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}
0

1 Answer 1

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}
5
  • 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
    Commented Aug 24, 2023 at 2:20
  • Also, how do I change your code so to have the page number on the bottom? Thanks!
    – Haim
    Commented Aug 24, 2023 at 2: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. Commented Aug 24, 2023 at 5: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. Commented Aug 24, 2023 at 5:11
  • Thanks so much John! This works
    – Haim
    Commented Aug 25, 2023 at 10:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .