![页边距中的 fancyhdr](https://linux22.com/image/396857/%E9%A1%B5%E8%BE%B9%E8%B7%9D%E4%B8%AD%E7%9A%84%20fancyhdr.png)
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
您的代码中有两个问题:
\fancyfoot[R]{\thepage}
在页面右侧输入页码(偶数页码或奇数页码)。将此行更改为\fancyfoot[LE,RO]{\thepage} % <=======================================
您还需要定义样式
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:
第二页:
答案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}