2

I want to print text as you would a header on a page but rotated in the left/right margins of the page following a typical book format (print right on odd pages and print left on even pages) using class book and package fancyhdr. This includes page numbers.

A previous answer was a good start (found here: Rotated, running text in right margin?) and works as posted. However, it does not seem to work in my MWE.

My MWE produces:

  • No text in margin on page 1 (text should be in right margin)
  • A centered page number on page 1 (page number should be east)
  • Text in margin appears on page 2 (this is correct)
  • Page number on page 2 is east (should be west)

Similar issues with pages 3 and 4.

\documentclass[11pt,letterpaper]{book}
\usepackage[margin=1.00in,showframe]{geometry}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{varwidth}
\usepackage{tikz}
\usetikzlibrary{shapes.misc,calc}

\begin{document}
% PAGE MARGINS HEADER/FOOTER
\fancypagestyle{sideheading}{%
  %% Clear all headers and footers
  \fancyhf{}
    %% Right headers on odd pages
  \fancyhead[RO]{%
      \begin{tikzpicture}[overlay,remember picture]
      \node[text=black,
      inner ysep=12pt, inner xsep=20pt,
      rounded rectangle,
      execute at begin node={\begin{varwidth}{\textheight}},%<====
      execute at end node={\end{varwidth}},
      rotate=-90]
      at ([xshift=-13mm,yshift=0mm]current page.east)
      {\Gid};
    \end{tikzpicture}
        }
        %% Left headers on even pages
\fancyhead[LE]{%
\begin{tikzpicture}[overlay,remember picture]
      \node[text=black,
      inner ysep=12pt, inner xsep=20pt,
      rounded rectangle,
      execute at begin node={\begin{varwidth}{\textheight}},%<====
      execute at end node={\end{varwidth}},
      rotate=90]
      at ([xshift=13mm,yshift=0mm]current page.west)
      {\Gid};
    \end{tikzpicture}
        }
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
  \fancyfoot[R]{\thepage}
}

\newcommand{\Gid}{}

\fancyhf{}
\chead{\Gid} 
\pagestyle{sideheading}
\linespread{0.0}

\renewcommand{\Gid}{{\bf \Large MARGIN TEXT 1}} 

\chapter{Insert Coin(s) To Begin}
\begin{multicols*}{2}
\lipsum
\end{multicols*}

\renewcommand{\Gid}{{\bf \Large MARGIN TEXT 2}} 
\chapter{How To Handle Loss}
\begin{multicols*}{2}
\lipsum
\end{multicols*}

\end{document}

Page 1 Page 2

2 Answers 2

1

There are two issues in your code:

  1. \fancyfoot[R]{\thepage} types the page number on the right side of the page for even or odd page numbers. Change this line to

    \fancyfoot[LE,RO]{\thepage} % <=======================================
    
  2. You need to define style plain too, it is used in chapter pages in class book. So copy the complete code of \fancypagestyle{sideheading}{% and add it with the changed line \fancypagestyle{plain}{%.

Please see the following complete mwe:

\documentclass[11pt,letterpaper]{book}

\usepackage[margin=1.00in,showframe]{geometry}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{varwidth}
\usepackage{tikz}
\usetikzlibrary{shapes.misc,calc}


\begin{document}
% PAGE MARGINS HEADER/FOOTER
\fancypagestyle{sideheading}{%
  %% Clear all headers and footers
  \fancyhf{}
    %% Right headers on odd pages
  \fancyhead[RO]{%
      \begin{tikzpicture}[overlay,remember picture]
      \node[text=black,
      inner ysep=12pt, inner xsep=20pt,
      rounded rectangle,
      execute at begin node={\begin{varwidth}{\textheight}},%<====
      execute at end node={\end{varwidth}},
      rotate=-90]
      at ([xshift=-13mm,yshift=0mm]current page.east)
      {\Gid};
    \end{tikzpicture}
        }
        %% Left headers on even pages
\fancyhead[LE]{%
\begin{tikzpicture}[overlay,remember picture]
      \node[text=black,
      inner ysep=12pt, inner xsep=20pt,
      rounded rectangle,
      execute at begin node={\begin{varwidth}{\textheight}},%<====
      execute at end node={\end{varwidth}},
      rotate=90]
      at ([xshift=13mm,yshift=0mm]current page.west)
      {\Gid};
    \end{tikzpicture}
        }
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
  \fancyfoot[LE,RO]{\thepage} % <=======================================
}

\fancypagestyle{plain}{% <==============================================
  %% Clear all headers and footers
  \fancyhf{}
    %% Right headers on odd pages
  \fancyhead[RO]{%
      \begin{tikzpicture}[overlay,remember picture]
      \node[text=black,
      inner ysep=12pt, inner xsep=20pt,
      rounded rectangle,
      execute at begin node={\begin{varwidth}{\textheight}},%<====
      execute at end node={\end{varwidth}},
      rotate=-90]
      at ([xshift=-13mm,yshift=0mm]current page.east)
      {\Gid};
    \end{tikzpicture}
        }
        %% Left headers on even pages
\fancyhead[LE]{%
\begin{tikzpicture}[overlay,remember picture]
      \node[text=black,
      inner ysep=12pt, inner xsep=20pt,
      rounded rectangle,
      execute at begin node={\begin{varwidth}{\textheight}},%<====
      execute at end node={\end{varwidth}},
      rotate=90]
      at ([xshift=13mm,yshift=0mm]current page.west)
      {\Gid};
    \end{tikzpicture}
        }
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
  \fancyfoot[LE,RO]{\thepage} % <=======================================
}

\newcommand{\Gid}{}

\fancyhf{}
\chead{\Gid} 
\pagestyle{sideheading}
\linespread{0.0}

\renewcommand{\Gid}{{\bf \Large MARGIN TEXT 1}} 

\chapter{Insert Coin(s) To Begin}
\begin{multicols*}{2}
\lipsum
\end{multicols*}

\renewcommand{\Gid}{{\bf \Large MARGIN TEXT 2}} 
\chapter{How To Handle Loss}
\begin{multicols*}{2}
\lipsum
\end{multicols*}

\end{document}

and the resulting pdf:

resulting page 1

and page two:

resulting page two

2

Chapter pages use pagestyle plain by default. If plain should use the same settings as a previous set fancy page style, you can redefine plain using

\fancypagestyle{plain}{}

If you use \pagestyle{sidemargin} before the first \thispagestyle{plain} or \pagestyle{plain} plain pages will get the same headers and footers.

\documentclass[11pt,letterpaper]{book}
\usepackage[margin=1.00in,showframe,
  headheight=13.6pt% as suggested by fancyhdr
]{geometry}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{varwidth}
\usepackage{tikz}
\usetikzlibrary{shapes.misc,calc}

\fancypagestyle{plain}{}% <- added
\fancypagestyle{sideheading}{%
  \fancyhf{}
  \fancyhead[RO]{%
      \begin{tikzpicture}[overlay,remember picture]
      \node[text=black,
      inner ysep=12pt, inner xsep=20pt,
      rounded rectangle,
      execute at begin node={\begin{varwidth}{\textheight}},
      execute at end node={\end{varwidth}},
      rotate=-90]
      at ([xshift=-13mm,yshift=0mm]current page.east)
      {\Gid};
    \end{tikzpicture}
        }
\fancyhead[LE]{%
\begin{tikzpicture}[overlay,remember picture]
      \node[text=black,
      inner ysep=12pt, inner xsep=20pt,
      rounded rectangle,
      execute at begin node={\begin{varwidth}{\textheight}},
      execute at end node={\end{varwidth}},
      rotate=90]
      at ([xshift=13mm,yshift=0mm]current page.west)
      {\Gid};
    \end{tikzpicture}
        }
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
  \fancyfoot[RO,LE]{\thepage}% <- changed
}

\newcommand{\Gid}{}
%\fancyhf{}% not needed
%\chead{\Gid}% not needed
\pagestyle{sideheading}
\begin{document}
\linespread{0.0}

\renewcommand{\Gid}{{\bfseries \Large MARGIN TEXT 1}} 
\chapter{Insert Coin(s) To Begin}
\begin{multicols*}{2}
\lipsum
\end{multicols*}

\renewcommand{\Gid}{{\bfseries \Large MARGIN TEXT 2}} 
\chapter{How To Handle Loss}
\begin{multicols*}{2}
\lipsum
\end{multicols*}
\end{document}

enter image description here

You must log in to answer this question.

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