我想为自己生成一个标准的、简单的报告模板。在所附的示例中,我想在第一页上设置不同的标题。我在尝试删除标题行从第一页开始。
代码
% vim:ft=tex:
%
\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont{Arial}
% Use if Arial font unavailable
% \usepackage{helvet}
% \renewcommand{\familydefault}{\sfdefault}
% Geometry has to be loaded before the footer
\usepackage{geometry}
\geometry{
a4paper,
left=20mm,
top=20mm,
bottom=20mm,
top=20mm
}
\usepackage{lastpage} % for the last page number
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
% Add a line above footer
\renewcommand{\footrulewidth}{0.4pt}% default is 0pt
% Add line above footer
\renewcommand{\headrulewidth}{0.4pt}
\fancyfoot[OR]{\footnotesize \thepage\ /\ \pageref{LastPage}}
% Define style to be used for the first page
\fancypagestyle{firststyle}
{
\fancyhf{}
\renewcommand{\headrulewidth}{0.0pt} % I would hope for this to delete header rule on the first page
\fancyfoot[OR]{\footnotesize \thepage\ /\ \pageref{LastPage}}
}
% Title page configuration
\title{\vspace{-2cm}Title of the Document\vspace{-5mm}}
\author{Author\vspace{-5mm}}
\date{\today}
\begin{document}
% Use special first page style on the first page
\thispagestyle{firststyle}
\maketitle\thispagestyle{fancy}
\section{Section}
\subsection{Section two}
Sample document
\end{document}
答案1
您\thispagestyle
在同一页面上调用了两次,第二次又使用了默认样式。由于\thispagestyle
只会影响当前页面上的样式,因此您无需像这样重新设置样式。
但是,您应该\thispagestyle
在之后调用\maketitle
,因为\maketitle
内部调用\thispagestyle{plain}
。
% vim:ft=tex:
%
\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont{Arial}
% Use if Arial font unavailable
% \usepackage{helvet}
% \renewcommand{\familydefault}{\sfdefault}
% Geometry has to be loaded before the footer
\usepackage{geometry}
\geometry{
a4paper,
left=20mm,
top=20mm,
bottom=20mm,
top=20mm
}
\usepackage{lastpage} % for the last page number
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
% Add a line above footer
\renewcommand{\footrulewidth}{0.4pt} % default is 0pt
% Add a line below header
\renewcommand{\headrulewidth}{0.4pt}
\fancyfoot[OR]{\footnotesize \thepage\ /\ \pageref{LastPage}}
% Define style to be used for the first page
\fancypagestyle{firststyle}{
\fancyhf{}
\renewcommand{\headrulewidth}{0.0pt}
\fancyfoot[OR]{\footnotesize \thepage\ /\ \pageref{LastPage}}
}
% Title page configuration
\title{\vspace{-2cm}Title of the Document\vspace{-5mm}}
\author{Author\vspace{-5mm}}
\date{\today}
\begin{document}
% Use special first page style on the first page
\maketitle
\thispagestyle{firststyle}
\section{Section}
\subsection{Section two}
Sample document
\newpage
More text
\end{document}