我的目标是排版一份程序手册。为了简单起见,我将使用与上一个问题相同的代码:
\documentclass[a4paper,14pt]{extreport}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage{framed, color}
\definecolor{shadecolor}{rgb}{0.64, 0.64, 0.82}
\begin{document}
\begin{flushright}
\textsl{\textcolor{red}{Procurement Protocol \textnumero 001}}\\
\today
\end{flushright}
\begin{center}
\textbf{{\Large Protocols for Safe Procurement of Specimens \\
Procurement Protocol \textnumero 001}}
\end{center}
\begin{multicols}{2}
\linespread{1.5}\selectfont
\setlength{\parindent}{0pt}
\textbf{Procurement \textnumero:} \dotfill
\textbf{Procurement date:} \dotfill
\textbf{Shipment type:} \dotfill
\textbf{Received by:} \dotfill
\textbf{Received on date:} \dotfill
\textbf{Country of origin:} \dotfill
\end{multicols}
\begin{shaded}
\centering\Large\bfseries Exemplary Specimen:
\end{shaded}
\lipsum[1]
\newpage
\begin{flushright}
\textsl{\textcolor{red}{Procurement Protocol \textnumero \textbf{002}}}\\
\today
\end{flushright}
\begin{center}
\textbf{{\Large Protocols for Safe Procurement of Specimens \\
Procurement Protocol \textnumero \textbf{002}}}
\end{center}
\begin{multicols}{2}
\linespread{1.5}\selectfont
\setlength{\parindent}{0pt}
\textbf{Procurement \textnumero:} \dotfill
\textbf{Procurement date:} \dotfill
\textbf{Shipment type:} \dotfill
\textbf{Received by:} \dotfill
\textbf{Received on date:} \dotfill
\textbf{Country of origin:} \dotfill
\end{multicols}
\begin{shaded}
\centering\Large\bfseries Exemplary Specimen:
\end{shaded}
\lipsum[2]
\end{document}
该文件应包含一组简短的(5-7 页)说明。根据要求,每条说明都应在页面的左上角或右上角带有“编号印章”,如下图所示。
当然,我可以使用\flushright
环境手动添加“数字标记”,如“示例”代码中所示,但有没有办法以半自动方式完成此操作?我知道一些软件包fancyhdr
,xwatermark
它们可能用于此目的。我的问题是:如何让“ fancyhdr
”通过不同的页面范围产生不同的标题?即第 1-5 页的右上角有“No 1”;第 6-11 页的右上角有“No 2”等等。感谢您的帮助!
答案1
我将定义一些宏来生成一致的布局以及随着每个新协议而步进的计数器。
\documentclass[a4paper,14pt]{extreport}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\usepackage{lipsum}
\usepackage{framed, color}
\definecolor{shadecolor}{rgb}{0.64, 0.64, 0.82}
\newcounter{procurement}
\usepackage{scrlayer-scrpage}
\ohead{\textcolor{red}{Procurement Protocol \textnumero~\theprocurement}\\\today}
\setlength{\headheight}{34.0pt}
\newcommand{\nextprotocol}{% automatic title on a new page
\clearpage
\refstepcounter{procurement}
\begin{center}
\textbf{\large Protocols for Safe Procurement of Specimens \\
Procurement Protocol \textnumero~\theprocurement}
\end{center}
}
\setlength{\parindent}{0pt}
\newcommand{\showEx}{%
\begin{shaded}
\centering\Large\bfseries Exemplary Specimen:
\end{shaded}
}
\begin{document}
\nextprotocol
\begin{tabular}{p{.47\linewidth}p{.47\linewidth}}
{Procurement \textnumero:} \dotfill &
{Procurement date:} \dotfill \\
{Shipment type:} \dotfill &
{Received by:} \dotfill \\
{Received on date:} \dotfill &
{Country of origin:} \dotfill \\
\end{tabular}
\showEx
\lipsum[1]
\nextprotocol
\begin{tabular}{p{.47\linewidth}p{.47\linewidth}}
{Procurement \textnumero:} \dotfill &
{Procurement date:} \dotfill \\
{Shipment type:} \dotfill &
{Received by:} \dotfill \\
{Received on date:} \dotfill &
{Country of origin:} \dotfill \\
\end{tabular}
\showEx
\lipsum[2]
\nextprotocol
\begin{tabular}{p{.47\linewidth}p{.47\linewidth}}
{Procurement \textnumero:} \dotfill &
{Procurement date:} \dotfill \\
{Shipment type:} \dotfill &
{Received by:} \dotfill \\
{Received on date:} \dotfill &
{Country of origin:} \dotfill \\
\end{tabular}
\showEx
\lipsum[2]
\end{document}
如果数字不是数值,而是任意字符串,您仍然可以使用简单的文本宏来填写标题。
%没有计数器,而是任意字符串
\documentclass[a4paper,14pt]{extreport}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage{framed, color}
\definecolor{shadecolor}{rgb}{0.64, 0.64, 0.82}
\usepackage{scrlayer-scrpage}
\newcommand{\thisprocurement}{}
\ohead{\textcolor{red}{Procurement Protocol \textnumero~\thisprocurement}\\\today}
\setlength{\headheight}{34.0pt}
\newcommand{\nextprotocol}[1][Not defined. Attention]{% automatic title on a new page
\clearpage
\renewcommand{\thisprocurement}{#1}
\begin{center}
\textbf{\large Protocols for Safe Procurement of Specimens \\
Procurement Protocol \textnumero~\thisprocurement}
\end{center}
}
\setlength{\parindent}{0pt}
\newcommand{\showEx}{%
\begin{shaded}
\centering\Large\bfseries Exemplary Specimen:
\end{shaded}
}
\begin{document}
\nextprotocol[Wombat12]
\begin{tabular}{p{.47\linewidth}p{.47\linewidth}}
{Procurement \textnumero:} \dotfill &
{Procurement date:} \dotfill \\
{Shipment type:} \dotfill &
{Received by:} \dotfill \\
{Received on date:} \dotfill &
{Country of origin:} \dotfill \\
\end{tabular}
\showEx
\lipsum[1]
\nextprotocol[Capybara.42]
\begin{tabular}{p{.47\linewidth}p{.47\linewidth}}
{Procurement \textnumero:} \dotfill &
{Procurement date:} \dotfill \\
{Shipment type:} \dotfill &
{Received by:} \dotfill \\
{Received on date:} \dotfill &
{Country of origin:} \dotfill \\
\end{tabular}
\showEx
\lipsum[2]
\nextprotocol
\begin{tabular}{p{.47\linewidth}p{.47\linewidth}}
{Procurement \textnumero:} \dotfill &
{Procurement date:} \dotfill \\
{Shipment type:} \dotfill &
{Received by:} \dotfill \\
{Received on date:} \dotfill &
{Country of origin:} \dotfill \\
\end{tabular}
\showEx
\lipsum[2]
\end{document}