![使用 tikz 和 fancyhdr 模仿带有续页的信头](https://linux22.com/image/370324/%E4%BD%BF%E7%94%A8%20tikz%20%E5%92%8C%20fancyhdr%20%E6%A8%A1%E4%BB%BF%E5%B8%A6%E6%9C%89%E7%BB%AD%E9%A1%B5%E7%9A%84%E4%BF%A1%E5%A4%B4.png)
我正在尝试用续页来模仿信头。信头格式如下:第一页上有彩色横幅,右侧有徽标,左侧有部门名称。第一页底部附近还有部门地址。所有这些都必须绝对定位。续页有徽标,位置相同,但没有其他内容。
由于无知,我以为我会使用 tikz 进行绝对定位,使用页面坐标。这适用于第一页,但似乎不适用于任何后续页面。也就是说,后续页面应该包含徽标,并且只包含徽标,但它们不包含任何内容。到目前为止,我还没有找到任何能完全解决这个问题的答案,而且我很确定我在 fancyhdr 中犯了一些愚蠢的错误,而且可能一开始就做错了。
这是当前输出的示例。第二页和所有后续页面都应在与第一页完全相同的位置处有一个演示图像。
这是课程文件
% class file MWE
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mweletter}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{letter}}
\ProcessOptions
\RequirePackage[demo]{graphicx}
\LoadClass[a4paper]{letter}
\RequirePackage[left=2.5cm,showframe]{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{tikz}
%\RequirePackage{fontspec}
\usetikzlibrary{calc}
\newsavebox{\addressbox}
\savebox{\addressbox}{
\sffamily\fontsize{8}{10}\selectfont
\textcolor{blue}{\begin{minipage}{7cm}
Block A Level 4, Simpson Street, Springfield USA \\%
Tel: (+1) 617 123 4567 \\
\end{minipage}}
}
\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{0pt}%
\pagestyle{plain}
\AtBeginDocument{\thispagestyle{firstpage}}
\fancypagestyle{firstpage}{%
\fancyhf{}%
\begin{tikzpicture}[overlay, remember picture]
\fill [anchor=north west,inner sep=0pt,orange]
(current page.north west) rectangle ($(current page.north east) + (0,-3cm)$);
\node[anchor=north east,inner sep=0pt] at ($(current page.north east) + (-1cm,-0.5cm)$)
{\includegraphics[height = 1.6cm]{demo}};
\node[anchor=north west,inner sep=0pt] at
($(current page.north west) + (2.5cm,-0.5cm)$) {
\sffamily\fontsize{8}{12} Department
of Excellent Science };
\node[anchor=south west, inner sep=0pt] at
($(current page.south west) + (2.5cm,1.5cm)$) {\usebox{\addressbox}};
\end{tikzpicture}
}
\fancypagestyle{plain}{%
\fancyhf{}%
\begin{tikzpicture}[overlay, remember picture]
\node[anchor=north east,inner sep=0pt]
at ($(current page.north east) + (-1cm,-0.5cm)$)
{\includegraphics[height = 1.6cm]{demo}};
\end{tikzpicture}
}
还有一个乳胶文件可以运行它。
\documentclass[12pt]{mweletter}
\usepackage{blindtext}
\signature{%
Johnathan "John" I.Q. Neidelbaum Frink, Jr., B.Sc., Ph.D. M.R.S.C. \\
The Principal Professor \\
Springfield Heights Institute of Technology \\
Springfield, America
}
\date{\today}
\begin{document}
\begin{letter}{Prof Tan\\
Beijing Da Xue}
\opening{Dear Prof Tan,}
\Blindtext[5]
\closing{Yours sincerely,}
\encl{mweletter.cls}
\ps{Please see the enclosed file.}
\cc{Lisa Simpson}
\end{letter}
\end{document}
答案1
fancyhdr
marmot 的评论让我意识到一开始使用 是多么愚蠢。我完全不知道eso-pic
。这只是将元素放在页面上,并以不同的方式处理第一页。
% mweletter.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mweletter}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{letter}}
\ProcessOptions
\RequirePackage[demo]{graphicx}
\LoadClass[a4paper]{letter}
\RequirePackage[left=2.5cm,showframe]{geometry}
\RequirePackage{tikz}
\RequirePackage{eso-pic}
\usetikzlibrary{calc}
\AddToShipoutPicture{
\begin{tikzpicture}[overlay, remember picture]
\ifnum\value{page}=1
\fill [anchor=north west,inner sep=0pt,orange]
(current page.north west) rectangle ($(current page.north east) + (0,-3cm)$);
\node[anchor=north west,inner sep=0pt] at
($(current page.north west) + (2.5cm,-0.5cm)$) {
\sffamily\fontsize{8}{12} Department
of Excellent Science };
\node[anchor=south west, inner sep=0pt] at
($(current page.south west) + (2.5cm,1.5cm)$) {
\sffamily\fontsize{8}{10}\selectfont
\textcolor{blue}{
\begin{minipage}{7cm}
Block A Level 4, Simpson Street, Springfield USA \\%
Tel: (+1) 617 123 4567 \\
\end{minipage}}};
\fi
\node[anchor=north east,inner sep=0pt] at ($(current page.north east) + (-1cm,-0.5cm)$)
{\includegraphics[height = 1.6cm]{demo}};
\end{tikzpicture}
}
这是输入
\documentclass[12pt]{mweletter}
\usepackage{blindtext}
\signature{%
Johnathan "John" I.Q. Neidelbaum Frink, Jr., B.Sc., Ph.D. M.R.S.C. \\
The Principal Professor \\
Springfield Heights Institute of Technology \\
Springfield, America
}
\date{\today}
\begin{document}
\begin{letter}{Prof Tan\\
Beijing Da Xue}
\opening{Dear Prof Tan,}
\Blindtext[4]
\closing{Yours sincerely,}
\encl{mweletter.cls}
\ps{Please see the enclosed file.}
\cc{Lisa Simpson}
\end{letter}
\end{document}
给予