![将不同的页眉和边距应用于多页 LaTeX 文档的第一页(不是标题页)](https://linux22.com/image/472129/%E5%B0%86%E4%B8%8D%E5%90%8C%E7%9A%84%E9%A1%B5%E7%9C%89%E5%92%8C%E8%BE%B9%E8%B7%9D%E5%BA%94%E7%94%A8%E4%BA%8E%E5%A4%9A%E9%A1%B5%20LaTeX%20%E6%96%87%E6%A1%A3%E7%9A%84%E7%AC%AC%E4%B8%80%E9%A1%B5%EF%BC%88%E4%B8%8D%E6%98%AF%E6%A0%87%E9%A2%98%E9%A1%B5%EF%BC%89.png)
如何设置一个 LaTeX 文档,使第一页具有特定的页眉和独特的页边距(与第二页不同),而无需手动指定第二页的开始位置?
我正在写一封两页的求职信。第一页应该有页眉(因此页边距不同),而第二页应该有标准页边距而没有页眉。第一页上的内容长度是可变的,所以我需要自动过渡到第二页的布局。
以下是我当前的 LaTeX 代码。由于我是 LaTeX 新手,因此欢迎提出任何改进或建议。
\documentclass[12pt]{letter}
\usepackage[utf8]{inputenc}
\usepackage[empty]{fullpage}
\usepackage[hidelinks]{hyperref}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{fontawesome5}
\usepackage{eso-pic}
\usepackage{charter}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{comment}
% Define the initial geometry for the first page
\geometry{
top=2in, % Adjusted top margin for the first page
headheight=1.1in, % Height of the header
headsep=0.5in, % Separation between header and text
bottom=1.2in,
left=1.2in,
right=1.2in,
footskip=4.35004pt % Adjusted footskip to avoid a warning from fancyhdr
}
% Header settings for the first page
\fancypagestyle{firstpage}{
\fancyhf{} % clear all header and footer fields
%%% Some logo will be here
%% \fancyhead[L]{\includegraphics[height=1in]{some-logo.png}}
\fancyhead[R]{My department\\My university\\Address line 1\\Address line 2}
\renewcommand{\headrulewidth}{0pt} % removes the horizontal line in the header
}
% Define a plain page style for other pages
\fancypagestyle{plain}{
\fancyhf{} % clear all header and footer fields
\renewcommand{\headrulewidth}{0pt} % optional: removes the horizontal line in the header
}
% Patch the \end{letter} command to change page style and geometry
\AtEndEnvironment{letter}{
\pagestyle{plain}
\newgeometry{
top=1.2in, bottom=1.2in, left=1.2in, right=1.2in
}
}
\begin{document}
\thispagestyle{firstpage} % Apply the first page header style
\vspace{0.5in}
% Opening block
\today\\
\vspace{-0.1in}
Recipient's name,\\
Recipient's Institution,\\
Recipient's address line 1,\\
Recipient's address line 2\\
Dear\ Dr. Jon Doe,
% Body
\setlength\parindent{24pt}
\noindent{}Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc aliquam ultrices aliquet. Cras ac placerat ex, non rhoncus tortor. Phasellus accumsan sit amet felis vitae varius. Nullam efficitur lorem nec orci scelerisque, commodo rutrum arcu varius. Nullam orci metus, rutrum sit amet enim sit amet, luctus rutrum metus. Vivamus commodo, quam a euismod venenatis, felis lorem porta massa, ac cursus massa nibh eu lectus. Duis pretium in elit nec sodales. Vivamus consectetur tristique ante eget ultricies. Cras sed lectus luctus, commodo urna fringilla, placerat urna.
\noindent{}Aliquam ut ligula orci. Sed cursus interdum ante, et cursus erat aliquam vel. Maecenas sodales ligula mattis condimentum convallis. Donec aliquet ut libero eget dignissim. Etiam gravida bibendum venenatis. Maecenas accumsan magna lectus. Mauris leo urna, tincidunt at eros vel, consequat varius urna. Curabitur blandit, nunc sed ultricies vehicula, neque turpis blandit massa, pulvinar ultrices orci ligula et enim. Morbi at efficitur ipsum. Aliquam ullamcorper consequat nunc, quis pulvinar orci facilisis sit amet. Pellentesque volutpat quam vitae luctus euismod.
\noindent{}Fusce mauris enim, maximus in lorem mattis, volutpat euismod nibh. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse ac leo cursus, bibendum justo eget, laoreet risus. In sodales nisl vel viverra fringilla. Ut venenatis nisl id dapibus mollis. In elit tellus, venenatis sit amet lacinia in, cursus id erat. In hac habitasse platea dictumst. Pellentesque pharetra risus eu ex luctus bibendum. Proin dictum neque sit amet mauris viverra, et hendrerit lacus elementum.
\noindent{}Aliquam ut ligula orci. Sed cursus interdum ante, et cursus erat aliquam vel. Maecenas sodales ligula mattis condimentum convallis. Donec aliquet ut libero eget dignissim. Etiam gravida bibendum venenatis. Maecenas accumsan magna lectus. Mauris leo urna, tincidunt at eros vel, consequat varius urna. Curabitur blandit, nunc sed ultricies vehicula, neque turpis blandit massa, pulvinar ultrices orci ligula et enim. Morbi at efficitur ipsum. Aliquam ullamcorper consequat nunc, quis pulvinar orci facilisis sit amet. Pellentesque volutpat quam vitae luctus euismod.
%% My problem: Is there any way to make this at the start of the second page AUTOMATICALLY (i.e. after how many paragraphs)?
\pagestyle{plain}
\newgeometry{
top=1.2in, bottom=1.2in, left=1.2in, right=1.2in
}
\noindent{}Aliquam ut ligula orci. Sed cursus interdum ante, et cursus erat aliquam vel. Maecenas sodales ligula mattis condimentum convallis. Donec aliquet ut libero eget dignissim. Etiam gravida bibendum venenatis. Maecenas accumsan magna lectus. Mauris leo urna, tincidunt at eros vel, consequat varius urna. Curabitur blandit, nunc sed ultricies vehicula, neque turpis blandit massa, pulvinar ultrices orci ligula et enim. Morbi at efficitur ipsum. Aliquam ullamcorper consequat nunc, quis pulvinar orci facilisis sit amet. Pellentesque volutpat quam vitae luctus euismod.
% Closer
\vspace{0.2in}
\begin{flushleft}
Thank you for your consideration,
\vspace{0.2in}
Jack Doe\\
\vspace{0.2in}
\end{flushleft}
\end{document}
答案1
这用于\AddToHookNext{shipoout/background}
将页眉叠加在第一页上。\put
坐标相对于页面的左上角。我定位了页眉的右下角,用于\llap
将其向左移动,并使用表格 [b] 来处理多行并将其向上移动。
顺便说一句,在每个文档中都包含你曾经使用过的所有包并不是一个好主意。我努力不加载不需要的包。
\documentclass[12pt]{letter}
\usepackage[utf8]{inputenc}
\usepackage[empty]{fullpage}
\usepackage[hidelinks]{hyperref}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{fontawesome5}
\usepackage{eso-pic}
\usepackage{charter}
\usepackage{etoolbox}
\usepackage{comment}
% Define the initial geometry for the first page
\geometry{ top=1.2in, bottom=1.2in, left=1.2in, right=1.2in}% showframe
\pagestyle{empty}
\AddToHookNext{shipout/background}{\put ({\dimexpr\paperwidth-1.2in},-1.5in)% lower right corner
{\llap{\begin{tabular}[b]{@{}l@{}}% or r
My department\\My university\\Address line 1\\Address line 2
\end{tabular}}}}
\begin{document}
\vspace*{0.5in}
% Opening block
\today
\vspace{-0.1in}
Recipient's name,\\
Recipient's Institution,\\
Recipient's address line 1,\\
Recipient's address line 2\\
Dear\ Dr. Jon Doe,
% Body
\setlength\parindent{24pt}
\noindent{}Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc aliquam ultrices aliquet. Cras ac placerat ex, non rhoncus tortor. Phasellus accumsan sit amet felis vitae varius. Nullam efficitur lorem nec orci scelerisque, commodo rutrum arcu varius. Nullam orci metus, rutrum sit amet enim sit amet, luctus rutrum metus. Vivamus commodo, quam a euismod venenatis, felis lorem porta massa, ac cursus massa nibh eu lectus. Duis pretium in elit nec sodales. Vivamus consectetur tristique ante eget ultricies. Cras sed lectus luctus, commodo urna fringilla, placerat urna.
\noindent{}Aliquam ut ligula orci. Sed cursus interdum ante, et cursus erat aliquam vel. Maecenas sodales ligula mattis condimentum convallis. Donec aliquet ut libero eget dignissim. Etiam gravida bibendum venenatis. Maecenas accumsan magna lectus. Mauris leo urna, tincidunt at eros vel, consequat varius urna. Curabitur blandit, nunc sed ultricies vehicula, neque turpis blandit massa, pulvinar ultrices orci ligula et enim. Morbi at efficitur ipsum. Aliquam ullamcorper consequat nunc, quis pulvinar orci facilisis sit amet. Pellentesque volutpat quam vitae luctus euismod.
\noindent{}Fusce mauris enim, maximus in lorem mattis, volutpat euismod nibh. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse ac leo cursus, bibendum justo eget, laoreet risus. In sodales nisl vel viverra fringilla. Ut venenatis nisl id dapibus mollis. In elit tellus, venenatis sit amet lacinia in, cursus id erat. In hac habitasse platea dictumst. Pellentesque pharetra risus eu ex luctus bibendum. Proin dictum neque sit amet mauris viverra, et hendrerit lacus elementum.
\noindent{}Aliquam ut ligula orci. Sed cursus interdum ante, et cursus erat aliquam vel. Maecenas sodales ligula mattis condimentum convallis. Donec aliquet ut libero eget dignissim. Etiam gravida bibendum venenatis. Maecenas accumsan magna lectus. Mauris leo urna, tincidunt at eros vel, consequat varius urna. Curabitur blandit, nunc sed ultricies vehicula, neque turpis blandit massa, pulvinar ultrices orci ligula et enim. Morbi at efficitur ipsum. Aliquam ullamcorper consequat nunc, quis pulvinar orci facilisis sit amet. Pellentesque volutpat quam vitae luctus euismod.
\noindent{}Aliquam ut ligula orci. Sed cursus interdum ante, et cursus erat aliquam vel. Maecenas sodales ligula mattis condimentum convallis. Donec aliquet ut libero eget dignissim. Etiam gravida bibendum venenatis. Maecenas accumsan magna lectus. Mauris leo urna, tincidunt at eros vel, consequat varius urna. Curabitur blandit, nunc sed ultricies vehicula, neque turpis blandit massa, pulvinar ultrices orci ligula et enim. Morbi at efficitur ipsum. Aliquam ullamcorper consequat nunc, quis pulvinar orci facilisis sit amet. Pellentesque volutpat quam vitae luctus euismod.
% Closer
\vspace{0.2in}
\begin{flushleft}% as in \parskip=0pt ?
Thank you for your consideration,
\vspace{0.2in}
Jack Doe\\
\vspace{0.2in}
\end{flushleft}
\end{document}