我正在使用几何学用于设置文本宽度和边距等的包。花式高清使用初始文本几何设置。通过我的文档,我还多次使用更改文本布局的几何形状(即不是页面大小/方向)\newgeometry{}
(因为我的文本是相对于文档中的不同背景图像设置的)。
(如果我在文档中途更改几何图形,存在黑客行为所以花式高清选择并适应新的文本宽度)。
如何设置页脚和页眉宽度花式高清这样它就与文本几何形状无关,并且永远不会改变?因此,它会保持宽度,并且永远不会适应文本的几何形状。我的具体情况是,我希望页脚的宽度填满(几乎)整个页面宽度,并在应用此页面样式的每个页面上都保持这种宽度。
这里有一个小例子,显示页脚/页眉的宽度是根据原始几何形状设置的,并且永远不会改变(但是,在每一页上它都与文本开始的位置对齐):
\documentclass[8pt,oneside]{report}
\usepackage[a3paper,landscape,left=12.cm,right=12.cm]{geometry}
\usepackage{fancyhdr}
\usepackage{kantlipsum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% setup fancyhdr style "fancy"
\pagestyle{fancy}
% clear all
\fancyhf{}
% header content
\fancyhf[HL]{Left eye}
\fancyhf[HC]{Nose}
\fancyhf[HR]{Right eye}
% footer content
\fancyhf[FL]{Left foot}
\fancyhf[FC]{\thepage}
\fancyhf[FR]{Right foot}
% show header and footer lines
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
% TODO: here I would like some command/setting that sets up the header and
% footer width and keeps it through the whole document (unless changed),
% like \fancywidth{0.9\pagewidth} or \fancyfill{marginL}{marginR}.
%
% even better, this constant width setting should be possible to define
% for every \fancypagestyle (and if not defined, use the current behaviour).
% this way we could switch easily between different setups.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section*{geometry}
\kant[1-4]
\newpage
\newgeometry{left=1cm,right=1cm}
\section*{newgeometry\{left=1cm,right=1cm\}}
\kant[5-9]
\newpage
\newgeometry{left=20cm,right=11cm}
\section*{newgeometry\{left=20cm,right=11cm\}}
\kant[10-12]
\newpage
\restoregeometry
\section*{restoregeometry}
\kant[14-17]
\newpage
\end{document}
答案1
通常,页眉和页脚与 相连\textwidth
(这是标准印刷实践)。因此,您现在必须用fancyhdr
来补偿边距和 中的更改\textwidth
。
如果你看一下fancyhdr
文档中的图 1,你会看到从纸张左边缘到文本左边缘的距离是,1in+\hoffset+\oddsidemargin
因此,为了将页眉/页脚放置在距离纸张左边缘固定的空间上(例如1cm
),我们必须将页眉移动-1in-\hoffset-\oddsidemargin+1cm
为了保持页眉/页脚的固定宽度,我们不应使用\fancy..offset
,而应将其设置\headwidth
为我们所需的值。在下面的示例中,我将其设置为\paperwidth-2cm
,这样我们在页眉和页脚的两端都获得了边距1cm
,与文本的边距无关。至少这是我对您的愿望的理解。
\setlength{\headwidth}{\dimexpr\paperwidth-2cm}
\fancyhfinit{%
\hspace{\dimexpr-1in-\hoffset-\oddsidemargin+1cm}%
}
这是完整的文档。
\documentclass[8pt,oneside]{report}
\usepackage[a3paper,landscape,left=12.cm,right=12.cm]{geometry}
\usepackage{fancyhdr}
\usepackage{kantlipsum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% setup fancyhdr style "fancy"
\pagestyle{fancy}
\setlength{\headwidth}{\dimexpr\paperwidth-2cm}
\newlength{\fancyLM}
\fancyhfinit{%
\hspace{\dimexpr-1in-\hoffset-\oddsidemargin+1cm}%
}
% clear all
\fancyhf{}
% header content
\fancyhf[HL]{Left eye}
\fancyhf[HC]{Nose}
\fancyhf[HR]{Right eye}
% footer content
\fancyhf[FL]{Left foot}
\fancyhf[FC]{\thepage}
\fancyhf[FR]{Right foot}
% show header and footer lines
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
% TODO: here I would like some command/setting that sets up the header and
% footer width and keeps it through the whole document (unless changed),
% like \fancywidth{0.9\pagewidth} or \fancyfill{marginL}{marginR}.
%
% even better, this constant width setting should be possible to define
% for every \fancypagestyle (and if not defined, use the current behaviour).
% this way we could switch easily between different setups.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section*{geometry}
\kant[1-4]
\newpage
\newgeometry{left=1cm,right=1cm}
\section*{newgeometry\{left=1cm,right=1cm\}}
\kant[5-9]
\newpage
\newgeometry{left=20cm,right=11cm}
\section*{newgeometry\{left=20cm,right=11cm\}}
\kant[10-12]
\newpage
\restoregeometry
\section*{restoregeometry}
\kant[14-17]
\newpage
\end{document}
顺便说一句,还有其他方法可以将文本/图像放在页面上的固定位置,而无需使用fancyhdr
,例如eso-pic
包或 LateX 挂钩shipout
。