降低第一章标题以放置一个漂亮的页眉,使所有后续页面看起来正常

降低第一章标题以放置一个漂亮的页眉,使所有后续页面看起来正常

我的书中有几章。我想在第一章上方添加一个漂亮的页眉,因此在这一页上,章节号和标题的排版应比平常略低(在页眉下方)。所有后续页面和章节标题都应按正常方式排版。

\documentclass[11pt]{book}

\usepackage{lipsum}
\usepackage{fancyhdr}
\fancypagestyle{firstpage}{
  \fancyhf{}
  \fancyhead{
    \begin{minipage}{\textwidth}
      {\sffamily Some information\\More information\\Another note\\This is a rather lengthy header\\foo\\bar\\buz\\blah\\beep}
    \end{minipage}
  }
}

\begin{document}

\chapter{A first chapter}
\thispagestyle{firstpage}

This is the first chapter. This page should include a fancy header
with some information, and as such the chapter number and title should
appear a little lower than for other chapters.

\lipsum[1-12]

\chapter{A second chapter}

This is the second chapter. It should be formatted normally, i.e., the
chapter number and title should appear at the top of the page, since
there is no special header here

\lipsum[13-19]

\end{document}

存在两个问题:

  1. 第一章排版不够低。它与页眉重叠。
  2. 后续页面的排版都低得多。底部边距几乎为零,而顶部边距很大。

LaTeX 也会输出警告:

Package Fancyhdr Warning: \headheight is too small (12.0pt): 
 Make it at least 133.13336pt.
 We now make it that large for the rest of the document.
 This may cause the page layout to be inconsistent, however.

这似乎是问题所在,但我不知道如何修复它。如果我把

\setlength{\headheight}{134pt}

\fancypagestyle{firstpage}{...}声明中,那么第一章标题的排版会较低,并且所有后续页面看起来都很好。这接近我想要的效果。但是,第一页的底部边距仍然几乎为 0,因此第一页末尾的文本一直延伸到底部。如何解决最后一个问题?

这似乎不是重复的。有两个相关问题:

但是,在这些情况下,设置\headheight似乎可以解决问题,并且他们似乎没有遇到我后面的问题。

答案1

诀窍是将小页面的高度设置为零,这样就不会影响后续页面的头部高度(以 为例fancyhdr)。这要求规则在小页面中排版,而不是打印通常会出现在错误位置的头部规则。

我还调整了章节标题上方的空间;最简单的方法是使用etoolbox:而不是 50pt(此处50\p@)我设置了 80pt,然后进行调整以适应。第一个补丁是为了避免在文档中\chapter需要。\thispagestyle{firstpage}

由于您使用 11pt 尺寸,因此需要将头部高度设置为 13.6pt。

\documentclass[11pt]{book}

\usepackage{etoolbox}
\usepackage{fancyhdr}

\usepackage{lipsum} % just for the example

\setlength{\headheight}{13.6pt}
\fancypagestyle{firstpage}{%
  \renewcommand{\headrulewidth}{0pt}%
  \fancyhf{}%
  \fancyhead{%
    \begin{minipage}[t][0pt]{\textwidth}
    \sffamily
    Some information\\
    More information\\
    Another note\\
    This is a rather lengthy header\\
    foo\\
    bar\\
    buz\\
    blah\\
    beep\strut
    \hrule
    \end{minipage}% <--- don't forget
  }%
}

\patchcmd{\chapter}{plain}{firstpage}{}{} % avoid the need of \thispagestyle after \chapter
\makeatletter
\patchcmd{\@makechapterhead}{50\p@}{80\p@}{}{}  % chapter head is lower
\patchcmd{\@makeschapterhead}{50\p@}{80\p@}{}{} % starred chapter head is lower
\makeatother

\begin{document}

\chapter{A first chapter}

This is the first chapter. This page should include a fancy header
with some information, and as such the chapter number and title should
appear a little lower than for other chapters.

\lipsum[1-12]

\chapter{A second chapter}

This is the second chapter. It should be formatted normally, i.e., the
chapter number and title should appear at the top of the page, since
there is no special header here

\lipsum[13-19]

\end{document}

在此处输入图片描述

相关内容