我用花式高清创建自定义页眉和页脚。我还使用文本位置并使用 Tikz 来修饰这些页眉和页脚。
我想使用textpos
绝对定位而不是 tikz,current page
因为它不需要多次编译。
现在我声明了几种具有可变页眉/页脚高度的页面样式。我想为不与页眉/页脚重叠的页面添加自定义几何图形。
我在这里得到了一个 MWE
% -*- latex -*-
\documentclass[a4paper]{article}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{blindtext}
\usepackage[absolute,overlay]{textpos}
\usepackage{geometry}
\makeatletter
\newcommand{\header@first}{%
\begin{textblock*}{\paperwidth}[0,0](0pt, 0pt)
\begin{tikzpicture}
\node [rectangle, draw=red,
anchor=north,
minimum width=\paperwidth-\pgflinewidth,
minimum height=5cm] (box) at (0.5\paperwidth,0mm) {};
\end{tikzpicture}
\end{textblock*}
}%
\newcommand{\footer@first}{%
\begin{textblock*}{\paperwidth}[0,1](0pt, \paperheight)
\begin{tikzpicture}
\node [rectangle, draw=red,
anchor=south,
minimum width=\paperwidth-\pgflinewidth,
minimum height=8cm] (box) at (0.5\paperwidth,\paperheight) {};
\end{tikzpicture}
\end{textblock*}
}%
\fancypagestyle{firstpage}{%
\fancyhf{}
\lhead{} \chead{\header@first} \rhead{}
\lfoot{} \cfoot{\footer@first} \rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\newgeometry{top=5cm, bottom=8cm, hmargin={1cm, 1cm}, textwidth=19cm}
}
\fancypagestyle{otherpage}{%
\fancyhf{}
\lhead{} \chead{} \rhead{}
\lfoot{} \cfoot{} \rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\newgeometry{top=1cm, bottom=1cm, hmargin={5cm, 5cm}, textwidth=11cm }
}
\pagestyle{otherpage}
\makeatother
\begin{document}
\thispagestyle{firstpage}
\Blinddocument
\newpage
\pagestyle{fancy}
\blinddocument
\end{document}
可以看出,newgeometry
每页样式定义不明确。顺便说一句,我不确定是否应该在\fancypagestyle
命令中定义几何图形。
有没有办法正确地做到这一点?
短暂性脑缺血。
答案1
好吧,我没有找到更改页面样式的完整几何形状的方法,但我设法更改了特定样式的正确文本高度,就像我一开始想做的那样。我发布了答案,希望它能帮助其他人。
% -*- latex -*-
\documentclass[a4paper]{article}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{calc}
\usepackage{fancyhdr}
\usepackage{blindtext}
\usepackage[absolute,overlay]{textpos}
\usepackage[showframe,margin=3cm]{geometry}
\usepackage{layout}
\makeatletter
\def\@@top@height{5cm}
\def\@@bottom@height{10cm}
\newcommand{\header@first}{%
\begin{textblock*}{\paperwidth}[0,0](0pt, 0pt)%
\begin{tikzpicture}%
\node [rectangle, draw=red,%
anchor=north,%
minimum width=\paperwidth-\pgflinewidth,%
minimum height=\@@top@height] (box) at (0.5\paperwidth,0mm) {};%
\end{tikzpicture}%
\end{textblock*}%
}%
\newcommand{\footer@first}{%
\begin{textblock*}{\paperwidth}[0,1](0pt, \paperheight)%
\begin{tikzpicture}%
\node [rectangle, draw=red,%
anchor=south,%
minimum width=\paperwidth-\pgflinewidth,%
minimum height=\@@bottom@height] (box) at (0.5\paperwidth,\paperheight) {};%
\end{tikzpicture}%
\end{textblock*}%
}%
\fancypagestyle{firstpage}{%
\fancyhf{}%
\lhead{l} \chead{\header@first} \rhead{r}%
\lfoot{l} \cfoot{\footer@first} \rfoot{r}%
\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{0pt}%
}%
%% \def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1#1}
%% \def\disp#1{\convertto{cm}{#1}}
%% Grabbed using the layout package
\def\@@top@skip{\dimexpr(1in+\voffset+\topmargin+\headheight+\headsep)\relax}
\def\@@bottom@skip{\dimexpr(\paperheight-\@@top@skip-\textheight)\relax}
\newcommand{\setfirstpage}{%
\def\myskp{\dimexpr(\@@top@height-\@@top@skip)\relax}%
\def\myfskp{\dimexpr(\@@bottom@height-\@@bottom@skip)\relax}%
\null\vspace{\myskp}%
\thispagestyle{firstpage}%
\enlargethispage{-\myfskp}%
}%
\fancypagestyle{otherpage}{%
\fancyhf{}
\lhead{} \chead{} \rhead{}
\lfoot{} \cfoot{} \rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\pagestyle{otherpage}
\makeatother
\begin{document}
%% \layout%
\setfirstpage%
\Blinddocument
%% \newpage
\pagestyle{fancy}
\blinddocument
\end{document}