1

Please see the MWE. I would like the page numbers aligned with the entire block of text (text + margin note) like in page 3. I know it is possible because it is used in the documentation of Notes Tex (https://ctan.math.washington.edu/tex-archive/macros/latex/contrib/notestex/doc/NotesTeX.pdf) but cannot find a way!

\documentclass[10pt]{book}
\usepackage{lipsum}
\usepackage{marginnote}
 \renewcommand*{\marginfont}{\scriptsize \sffamily}
   \renewcommand\raggedrightmarginnote{}
\renewcommand\raggedleftmarginnote{}

\usepackage[ paperwidth=160mm, paperheight=240mm, textheight=18cm, textwidth=8cm, inner=2cm, marginparwidth=2.5cm, marginparsep=0.5cm] {geometry} \usepackage{wrapfig} \usepackage{fontspec} \begin{document} %\sloppy

\newpage

\paragraph{First} \begin{wrapfigure}{i}{0.64\textwidth}% \vspace{5pt} \noindent {\fontsize{46pt}{46pt}\selectfont \hspace{-5pt} Big} \end{wrapfigure} This\marginnote{I want this to be aligned. \lipsum[1]} is a paragraph. \lipsum[1]

\newpage

\paragraph{First} \begin{wrapfigure}{i}{0.64\textwidth}% \vspace{5pt} \noindent {\fontsize{46pt}{46pt}\selectfont \hspace{-5pt} Big} \end{wrapfigure} This\marginnote{I want this to be aligned. \lipsum[1]} is a paragraph. \lipsum[1]

\newgeometry{ textwidth=11cm} \lipsum[1] \restoregeometry

\end{document}

Haim
  • 487

1 Answers1

1

This uses \AddToHook to implement the page number.

\documentclass[10pt]{book}
\usepackage{lipsum}
\usepackage{marginnote}
 \renewcommand*{\marginfont}{\scriptsize \sffamily}
   \renewcommand\raggedrightmarginnote{}
\renewcommand\raggedleftmarginnote{}

\usepackage[ paperwidth=160mm, paperheight=240mm, textheight=18cm, textwidth=8cm, inner=2cm, marginparwidth=2.5cm, marginparsep=0.5cm, showframe] {geometry}

\pagestyle{empty} \AddToHook{shipout/background}{\ifodd\value{page} \put (\dimexpr 1in+\oddsidemargin+\textwidth+\marginparsep+\marginparwidth\relax, \dimexpr -1in-\topmargin-\headheight\relax) {\llap{\thepage}}% right justified \else \put (\dimexpr 1in+\evensidemargin-\marginparsep-\marginparwidth\relax, \dimexpr -1in-\topmargin-\headheight\relax) {\thepage} \fi}

\usepackage{wrapfig} \usepackage{fontspec} \begin{document} \newpage

\paragraph{First} \begin{wrapfigure}{i}{0.64\textwidth}% \vspace{5pt} \noindent {\fontsize{46pt}{46pt}\selectfont \hspace{-5pt} Big} \end{wrapfigure} This\marginnote{I want this to be aligned. \lipsum[1]} is a paragraph. \lipsum[1]

\newpage

\paragraph{First} \begin{wrapfigure}{i}{0.64\textwidth}% \vspace{5pt} \noindent {\fontsize{46pt}{46pt}\selectfont \hspace{-5pt} Big} \end{wrapfigure} This\marginnote{I want this to be aligned. \lipsum[1]} is a paragraph. \lipsum[1]

\newgeometry{marginparsep=0pt, marginparwidth=0pt, textwidth=11cm} \lipsum[1] \restoregeometry

\end{document}


This modifies \pagestyle{headings}, which should be the default style for book class.

\documentclass[10pt]{book}
\usepackage{lipsum}
\usepackage{marginnote}
 \renewcommand*{\marginfont}{\scriptsize \sffamily}
   \renewcommand\raggedrightmarginnote{}
\renewcommand\raggedleftmarginnote{}

\usepackage[ paperwidth=160mm, paperheight=240mm, textheight=18cm, textwidth=8cm, inner=2cm, marginparwidth=2.5cm, marginparsep=0.5cm, showframe] {geometry}

\makeatletter \def\ps@headings{% \let@oddfoot@empty\let@evenfoot@empty \def@evenhead{\hskip\dimexpr -\marginparsep-\marginparwidth\relax \thepage\hfil\slshape\leftmark}% \def@oddhead{{\slshape\rightmark}\hfil\thepage\hskip\dimexpr -\marginparsep-\marginparwidth\relax}% \let@mkboth\markboth \def\chaptermark##1{% \markboth {\MakeUppercase{% \ifnum \c@secnumdepth >\m@ne \if@mainmatter @chapapp\ \thechapter. \ % \fi \fi ##1}}{}}% \def\sectionmark##1{% \markright {\MakeUppercase{% \ifnum \c@secnumdepth >\z@ \thesection. \ % \fi ##1}}}} \makeatother \pagestyle{headings}

\usepackage{wrapfig} \usepackage{fontspec} \begin{document} \newpage

\paragraph{First} \begin{wrapfigure}{i}{0.64\textwidth}% \vspace{5pt} \noindent {\fontsize{46pt}{46pt}\selectfont \hspace{-5pt} Big} \end{wrapfigure} This\marginnote{I want this to be aligned. \lipsum[1]} is a paragraph. \lipsum[1]

\newpage

\paragraph{First} \begin{wrapfigure}{i}{0.64\textwidth}% \vspace{5pt} \noindent {\fontsize{46pt}{46pt}\selectfont \hspace{-5pt} Big} \end{wrapfigure} This\marginnote{I want this to be aligned. \lipsum[1]} is a paragraph. \lipsum[1]

\newgeometry{marginparsep=0pt, marginparwidth=0pt,textwidth=11cm} \lipsum[1] \restoregeometry

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Thanks. Both solution works. But is there a way to just tell latex to use the text + Margin as width? So that I can use the fancyhdr package? – Haim Aug 24 '23 at 02:20
  • Also, how do I change your code so to have the page number on the bottom? Thanks! – Haim Aug 24 '23 at 02:21
  • While it is possible to use fancyhdr, you could only use LO and RE and put the entire header or footer in a `\makebox[\dimexpr \textwidth+\marginparsep+\marginparwidth]...'. Except tfor \chaptermark and \sectionmark, ordinary page styles are pretty simple. – John Kormylo Aug 24 '23 at 05:06
  • For \AddToHook, the footer is locates at y=\dimexpr -1in-\topmargin-\headheight-\headsep-\textheioght-\footskip\relax. For \ps@headings, simply use \@oddfoot and \@evenfoot. – John Kormylo Aug 24 '23 at 05:11
  • Thanks so much John! This works – Haim Aug 25 '23 at 10:11