TeX 能否知道它何时位于页面顶部?

TeX 能否知道它何时位于页面顶部?

我有一个回忆录项目,其中的章节彼此相连,章节之间有分隔线。如果章节位于页面顶部,则不应有分隔线或空格。有没有自动方法可以做到这一点,或者最好的方法是只使用 2 种章节样式,然后在它们之间手动切换以删除分隔线和多余的空格?

\documentclass[12pt,a4paper,article]{memoir} 
\usepackage{lipsum}

%----------depthead
\makeatletter
 \makechapterstyle{mychapter}{%
\renewcommand{\printchaptername}{}% suppress "Chapter" from heading
\renewcommand*{\printchapternum}{}% suppress numbering from heading
\renewcommand*{\chaptitlefont}{\centering}% title formatting
\renewcommand\afterchapternum{%
  \vskip3em\hrulefill\vskip1em}%  
\setlength\beforechapskip{-10pt}% 
\setlength\afterchapskip{30pt}% adjust vertical space after the title
}
\makeatother

\chapterstyle{mychapter}
\begin{document}

\chapter{Sample Chapter 1 should not have line and space}
\lipsum[1]

\chapter{Sample Chapter 2}
\lipsum[1]

\newpage

\chapter{Sample Chapter 3 should not have line and space}
\lipsum[1]


\end{document}

答案1

由于处理是异步的,因此您无法在页面为空时测试宏是否已处理。但是当页面为空时,TeX 处于特殊状态,它会忽略所有垂直空间(胶水)。这意味着您需要将规则设为“垂直空间”。这可以通过\leaders原始方式实现:它只是垂直或水平空间的一种特殊类型。因此,我用 替换了您\hrulefill\leaders

你的情况的第二个问题是\chapterheadstar包含项对于垂直列表不可见\hrule,因此此后页面不为空。我将此宏重新定义为空。

\documentclass[12pt,a4paper,article]{memoir}
\usepackage{lipsum}

%----------depthead
\makechapterstyle{mychapter}{%
  \renewcommand{\printchaptername}{}% suppress "Chapter" from heading
  \renewcommand*{\printchapternum}{}% suppress numbering from heading
  \renewcommand*{\chaptitlefont}{\centering}% title formatting
  \renewcommand\afterchapternum{%
    \vskip3em \leaders\hrule width\hsize\vskip.4pt\vskip1em}%  
  \setlength\beforechapskip{-10pt}% 
  \setlength\afterchapskip{30pt}% adjust vertical space after the title
  \def\chapterheadstart{}%
}

\chapterstyle{mychapter}
\begin{document}

\chapter{Sample Chapter 1 should not have line and space}
\lipsum[1]

\chapter{Sample Chapter 2}
\lipsum[1]

\newpage

\chapter{Sample Chapter 3 should not have line and space}
\lipsum[1]

\end{document}

编辑:以下代码是对下面 8 月 16 日评论的回应。定义:

\newdimen\ruleheight \ruleheight=.4pt
\def\doublerule#1{\vbox{\setbox0=\hbox{ #1 }%
   \baselineskip=3pt \lineskiplimit=-\maxdimen
   \hbox to\hsize{\ruleheight=1.2pt\doubleruleA\kern\wd0\doubleruleA}%
   \hbox to\hsize{\doubleruleA\box0 \doubleruleA}}}
\def\doubleruleA{{\advance\ruleheight by1pt\leaders\vrule height\ruleheight depth-1pt\hfil}}

并使用

\vskip1em \cleaders\doublerule{Hello world}\vskip\baselineskip \vskip3em

代替\vskip3em \leaders\hrule width\hsize\vskip.4pt\vskip1em

相关内容