分页符处省略的文本块之间的水平线

分页符处省略的文本块之间的水平线

我正在尝试定义一个在文本块后添加水平线的命令,但我很难找到一种方法来省略分页符处的行 - 文本块应该由水平线分隔或者分页符,绝不会同时出现。

下面是一个展示我的方法的 MWE:

\documentclass[paper=a5]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}

\newcommand{\mycommand}[1]{%
  #1%
  \vspace{.1ex}\begin{center}\rule{.25\textwidth}{0.4pt}\end{center}\vspace{.1ex}%
}

\begin{document}

\mycommand{\blindtext[2]}
\mycommand{some text some text some text some text some text some text some text}

\end{document}

输出

输出

我想删除第二页顶部的一条水平线。我该怎么做?

我读对 LaTeX 中的分页符做出反应但我没有找到一种方法来使其解决方案适应我的问题。

答案1

领导的老把戏就该这么做。

\documentclass[paper=a5]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}

\newcommand{\mybreak}{%
  \par
  \nointerlineskip
  \cleaders\vbox to 5ex{%
    \vss
    \hbox to \textwidth{\hss\vrule width 0.25\textwidth height 0.2pt depth 0.2pt\hss}
    \vss
  }\vskip5ex
}

\begin{document}

\blindtext[2]

\mybreak

some text some text some text some text some text some text some text

\mybreak

some text some text some text some text some text some text some text

\end{document}

在此处输入图片描述

答案2

来自我的一个旧解决方案,也可以在这里使用(https://tex.stackexchange.com/a/396216/120578)(我将您的命令与我的命令结合使用):

\documentclass[paper=a5]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}

\newsavebox{\mybottombox} % Box to save the text of the command 
\newlength{\mybottomlength} % The length of our text inside the command
\newlength{\availafter} % The available length left on the page after placing our text

% Optional argument is the minimum length after the nobottom text for not pagebreak. Change it to your needs
\newcommand{\nobottom}[2][40pt]{\savebox{\mybottombox}{\vbox{#2}}\setlength{\mybottomlength}{\ht\mybottombox}%
\setlength{\availafter}{\dimexpr\textheight-\mybottomlength-\pagetotal\relax}\ifdim\availafter<#1%
\pagebreak%\noindent\usebox{\mybottombox}%
\else%
\noindent\usebox{\mybottombox}%
\fi%
}%

\newcommand{\mycommand}[1]{%
  #1\vspace{.1ex}\par%
  \nobottom{\noindent\begin{center}\rule{.25\textwidth}{0.4pt}\end{center}\vspace{.1ex}}%
}

\begin{document}

\mycommand{\blindtext[2]}
\mycommand{some text some text some text some text some text some text some text}
\mycommand{some text some text some text some text some text some text some text}
\end{document}

输出:

在此处输入图片描述

如果该行位于页面底部,我就不会添加它。底部在我的命令的可选参数中定义\nobottom,例如,我使用了 40pt。

如果特定段落需要,我们还可以将我的可选参数作为命令的可选项。

相关内容