风格别致,文本高度随章节变化

风格别致,文本高度随章节变化

我使用包创建了自己的页眉和页脚样式fancyhdr,并且希望它也出现在章节页面上。我使用了此主题。另外,由于我的样式需要更改标题和文本之间的间距,因此我根据以下情况重新定义了headsep和大小textheight软件包文档(第 6 页)。

对于“正常”部分,一切都很好,所有尺寸都像我定义的一样。对于章节页面,textheight不考虑 I 的设置。对于第一个,文本以合适的形状填充页面。但对于第二章,文本高度似乎是 中定义的高度MyStyle,它将文本拆分到新页面上。

\documentclass{report}

\usepackage[top=2cm, bottom=2cm, left=1.5cm, right=1.5cm]{geometry}

\usepackage{titletoc}

% Header and footer
\usepackage{lastpage}
\usepackage{fancyhdr}

\fancypagestyle{MyStyle}{
  \fancyhf{}
  \rhead{Foo}
  \lfoot{\thepage/\pageref{LastPage}}
  \renewcommand{\headrulewidth}{0.0pt}
  \renewcommand{\headsep}{5cm}
  \renewcommand{\textheight}{19cm}
}
\fancypagestyle{plain}{
  \fancyhf{}
  \rhead{Foo}
  \lfoot{\thepage/\pageref{LastPage}}
  \renewcommand{\headrulewidth}{0.0pt}
  \renewcommand{\headsep}{0cm}
  \renewcommand{\textheight}{99cm} % It seems it has no effect
}

%generates filler text
\usepackage{blindtext}

\renewcommand\thesubsubsection{\Alph{subsubsection}}

\begin{document}

  \pagestyle{MyStyle}

  \chapter{My chapter 1}
    \Blindtext[3][2]

  \section{Section 1}

    \subsection{SubSec 1.1}

      \subsubsection{SubSubSec 1.1.A}
        \label{sss1A}
        \blindtext

      \subsubsection{SubSubSec 1.1.B}
        \label{sss1B}
        \blindtext

    \subsection{SubSec 1.2}

  \section{Section 2}

    \subsection{SubSec 2.1}

    \subsection{SubSec 2.2}

      \subsubsection{SubSubSec 2.2.A}
        \label{sss2A}
        \blindtext

      \subsubsection{SubSubSec 2.2.B}
        \label{sss2B}
        \blindtext

  \section{Section 3}

    \ref{sss1A} and \ref{sss2B} refer to sections 1.1.A and 2.2.B. But as it
    is, we could think they refer to two successive sections.

  \chapter{My chapter 2}
  \Blindtext[3][2]

\end{document}

我真的不明白这个问题。我错过了什么吗?这是一个错误吗?...

答案1

此解决方案使用etoolbox包进行修改\@makechapterhead以重叠\headsep区域。它还消除了通常会添加的额外 50pt 间隙。

顺便说一句,虽然\headrulewidth是一个宏,\headsep并且\textheight是 dimen 寄存器,应该使用来设置\setlength

\documentclass{report}

\usepackage[top=7cm, headsep=5cm,  bottom=2cm, left=1.5cm, right=1.5cm]{geometry}% top includes headsep

\usepackage{titletoc}

% Header and footer
\usepackage{lastpage}
\usepackage{fancyhdr}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@makechapterhead}{\vspace*{50\p@}}{\vspace*{-5cm}}{}{Error}
\makeatother

\fancypagestyle{MyStyle}{
  \fancyhf{}
  \rhead{Foo}
  \lfoot{\thepage/\pageref{LastPage}}
  \renewcommand{\headrulewidth}{0.0pt}
}
\fancypagestyle{plain}{
  \fancyhf{}
  \rhead{Foo}
  \lfoot{\thepage/\pageref{LastPage}}
  \renewcommand{\headrulewidth}{0.0pt}
}

%generates filler text
\usepackage{blindtext}

\renewcommand\thesubsubsection{\Alph{subsubsection}}

\pagestyle{MyStyle}

\begin{document}

  \chapter{My chapter 1}

    \the\headsep

    \the\textheight

    \Blindtext[3][2]

  \section{Section 1}

    \subsection{SubSec 1.1}

      \subsubsection{SubSubSec 1.1.A}
        \label{sss1A}
        \blindtext

      \subsubsection{SubSubSec 1.1.B}
        \label{sss1B}
        \blindtext

    \subsection{SubSec 1.2}

  \section{Section 2}

    \subsection{SubSec 2.1}

    \subsection{SubSec 2.2}

      \subsubsection{SubSubSec 2.2.A}
        \label{sss2A}
        \blindtext

      \subsubsection{SubSubSec 2.2.B}
        \label{sss2B}
        \blindtext

  \section{Section 3}

    \ref{sss1A} and \ref{sss2B} refer to sections 1.1.A and 2.2.B. But as it
    is, we could think they refer to two successive sections.

    \the\headsep

    \the\textheight

  \chapter{My chapter 2}

    \the\headsep

    \the\textheight

  \Blindtext[3][2]

\end{document}

此版本将第一行文本(章节标题之后)放在文本区域内。

\documentclass{report}

\usepackage[top=7cm, headsep=5cm,  bottom=2cm, left=1.5cm, right=1.5cm, showframe]{geometry}% top includes headsep

\usepackage{titletoc}

% Header and footer
\usepackage{lastpage}
\usepackage{fancyhdr}

\makeatletter
\def\@makechapterhead#1{\vspace*{-2\baselineskip}% not sure where the extra ilne comes from
  \noindent\raisebox{0pt}[0pt]{\parbox[b]{\textwidth}{\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}}
\makeatother

\fancypagestyle{MyStyle}{
  \fancyhf{}
  \rhead{Foo}
  \lfoot{\thepage/\pageref{LastPage}}
  \renewcommand{\headrulewidth}{0.0pt}
}
\fancypagestyle{plain}{
  \fancyhf{}
  \rhead{Foo}
  \lfoot{\thepage/\pageref{LastPage}}
  \renewcommand{\headrulewidth}{0.0pt}
}

%generates filler text
\usepackage{blindtext}

\renewcommand\thesubsubsection{\Alph{subsubsection}}

\pagestyle{MyStyle}

\begin{document}

  \chapter{My chapter 1}

    \Blindtext[3][2]

  \section{Section 1}

    \subsection{SubSec 1.1}

      \subsubsection{SubSubSec 1.1.A}
        \label{sss1A}
        \blindtext

      \subsubsection{SubSubSec 1.1.B}
        \label{sss1B}
        \blindtext

    \subsection{SubSec 1.2}

  \section{Section 2}

    \subsection{SubSec 2.1}

    \subsection{SubSec 2.2}

      \subsubsection{SubSubSec 2.2.A}
        \label{sss2A}
        \blindtext

      \subsubsection{SubSubSec 2.2.B}
        \label{sss2B}
        \blindtext

  \section{Section 3}

    \ref{sss1A} and \ref{sss2B} refer to sections 1.1.A and 2.2.B. But as it
    is, we could think they refer to two successive sections.

  \chapter{My chapter 2}

  \Blindtext[3][2]

\end{document}

相关内容