页边距中的 fancyhdr

页边距中的 fancyhdr

book我想使用类和包打印文本,就像在页面上打印页眉一样,但按照典型的书籍格式(在奇数页上向右打印,在偶数页上向左打印)在页面的左/右边距旋转fancyhdr。这包括页码。

先前的答案是一个很好的开始(在这里找到:旋转的、在右边距运行的文本?) 并按发布的方式工作。但是,它似乎在我的 MWE 中不起作用。

我的 MWE 产生:

  • 第 1 页的边距中没有文本(文本应位于右边距)
  • 第 1 页居中显示页码(页码应朝东)
  • 页边空白处的文字出现在第 2 页(这是正确的)
  • 第 2 页的页码是东(应该是西)

第 3 页和第 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}

第 1 页 第2页

答案1

您的代码中有两个问题:

  1. \fancyfoot[R]{\thepage}在页面右侧输入页码(偶数页码或奇数页码)。将此行更改为

    \fancyfoot[LE,RO]{\thepage} % <=======================================
    
  2. 您还需要定义样式plain,它用于课堂上的章节页面book。因此,复制完整的代码\fancypagestyle{sideheading}{%并将其与更改后的行一起添加\fancypagestyle{plain}{%

请参阅以下完整 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}

以及生成的pdf:

结果页面 1

第二页:

结果第二页

答案2

章节页面plain默认使用页面样式。如果plain要使用与之前设置的花式页面样式相同的设置,可以plain使用

\fancypagestyle{plain}{}

如果你使用\pagestyle{sidemargin} 首页\thispagestyle{plain}\pagestyle{plain}普通页面将获得相同的页眉和页脚。

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

在此处输入图片描述

相关内容