如何检测摘要是否到达第二页,以便添加页眉

如何检测摘要是否到达第二页,以便添加页眉

我正在写一篇论文,论文的第一页(如果足够长的话,是第二页)是摘要。当摘要延伸到第二页时,我有两个格式要求无法理解:

  1. 如何防止页码显示在第 2 页?我可以用 隐藏第 1 页上的页码\thispagestyle{empty},但我不知道如何隐藏第 2 页上的页码,因为我不知道第 2 页从哪里开始
  2. 我该如何添加仅适用于第 2 页的页眉?同样,我不知道该把这个页眉声明放在哪里,因为我不知道第 2 页从哪里开始

以下是实际说明:

如果摘要延伸到第二页,则该页的标题应如下:

Jane Mary Doe – [University], [year of graduation] 

摘要未分页。

如果摘要适合一页,那么就不应该有第二页摘要。有人能帮我理解这个问题吗?

答案1

由于这里没有示例可供参考,因此这个答案需要一些猜测,并且要感谢@cfr 在评论中的建议。我在代码中添加了一些注释来解释一下。@cfr 给出的关键(而且相当聪明)想法是为摘要打开一种特殊的页面样式,但仅在第一页上抑制它。

\documentclass{article}
\usepackage{lipsum}
% define a new page style
\makeatletter
\newcommand{\ps@abstract}{%
    \renewcommand{\@oddhead}{\hss Jane Mary Doe -- University of Oxford, 1264\hss}%
    \renewcommand{\@evenhead}{\@oddhead}% left same as right
    \renewcommand{\@oddfoot}{}% blank footers
    \renewcommand{\@evenfoot}{}}
\makeatother
\begin{document}
\pagestyle{abstract} % turn on the new page style
\thispagestyle{empty} % but turn it off for the first page
\begin{abstract}
    Here goeth a pithy summary of the wonderful text herein.
    \lipsum % add some dummy text to push us over 1 page
    % the new heading will appear on p2 of the abstract
\end{abstract}
\clearpage  % or \cleardoublepage if you are in two sided mode
\pagenumbering{arabic} % reset page numbers to 1 (only if you want to)
\pagestyle{plain} % or whatever style you want for the rest of the doc
\section{Introduction}

Here goeth the rest of the booke.

\end{document}

解释

LaTeX 中的页面样式定义和启用分为两个阶段:要定义样式abc,您需要定义一个新命令\ps@abc,该命令重新定义上面显示的四个页眉和页脚命令。然后使用 切换到该样式\pagestyle{abc}。如果您希望页面样式仅适用于当前页面,则可以使用\thispagestyle{abc};上一个页面样式将在后续页面上恢复。

标准样式为empty、 (类plain中的默认样式) 、 和。articleheadingsmyheadings页面布局部分Wikibooks 上有一些有用的参考资料。有几种软件包可以简化和扩展这些基本的 LaTeX 机制。您可能想尝试fancyhdr例如。

当 TeX 到达页面末尾时,页面样式就会应用,因此如果您在页面中途切换标题,新样式将应用于当前页面,而不是下一个页面。因此,在切换标题样式之前,通常最好确保您已经开始了新页面。该\clearpage命令会为您完成此操作(并且还会确保在新页面开始之前放置任何待处理的浮动,例如figuretable环境)。

相关内容