我希望在制表符上方放置一条水平线,在制表符下方放置另一条水平线,这样制表符内容和两行之间就没有分页符。以下是我迄今为止尝试过的方法:
\documentclass[a4paper]{article}
\newenvironment{ruletabbing}{%
\begingroup\setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}\raggedright\hrule\nopagebreak\tabbing\nopagebreak%
}{%
\nopagebreak\endtabbing\nopagebreak\vspace{-.05\baselineskip}\nopagebreak\hrule\par\vspace{.07\baselineskip}\endgroup%
}
\begin{document}
\strut
\vspace{46.8\baselineskip}\\
A page break after this text would be ok.\\[.1\baselineskip]
\begin{ruletabbing}
A page break after this text in tabbing, but not before it, would be ok.\\
A page break before this text in tabbing, but not after it, would be ok.
\end{ruletabbing}
\noindent A page break before this text would be ok.
\end{document}
但是,\nopagebreak
s 似乎没有效果;这个例子明显失败了:
上面,第一条规则后面紧接着一个分页符,这不是我们想要的。如果没问题,请稍微调整一下上面的 46.8。第二行也遇到了同样的问题,只需将 46.8 改为一个较小的值即可。
如何禁止在两条水平线和制表内容之间分页?制表内容必须允许分页。理想情况下,新的制表环境也应该在列表(itemize、enumerate、description)内工作,尽管这不是必须的。
答案1
几乎有五十万用户可能没有阅读,但防止在制表符环境中出现分页符是一个相当简单的事情,只需告诉制表符不是促进这些位置的中断,就像通常那样。这些设置将放置在与放置防止多余空白的设置相同的位置。
\makeatletter
\newenvironment{ruletabbing}{%
\setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}%
\raggedright
\@nobreaktrue % no favorable break at start
\@endparpenalty=10000 % no favorable break at end
\hrule\nopagebreak\tabbing
}{%
\endtabbing
\vspace{-.05\baselineskip}\hrule\vspace{.07\baselineskip}%
}
\makeatother
我已经复制了间距,但请注意,这\hrule
是有问题的,因为它与正常的行间间距规则不兼容。
答案2
您可以使用彩色盒子
\documentclass{book}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}[boxrule=0mm,toprule=1mm,bottomrule=1mm,colback=white,arc=0mm]
content
\end{tcolorbox}
\end{document}
或者
\documentclass{book}
\usepackage{tcolorbox}
\newenvironment{ruletabbing}{%
\begingroup\setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}\raggedright\hrule\nopagebreak\tabbing\nopagebreak%
}{%
\nopagebreak\endtabbing\nopagebreak\vspace{-.05\baselineskip}\nopagebreak\hrule\par\vspace{.07\baselineskip}\endgroup%
}
\begin{document}
\begin{tcolorbox}[boxrule=0mm,toprule=0mm,bottomrule=0mm,colback=white,arc=0mm]
\begin{ruletabbing}
A page break after this text in tabbing, but not before it, would be ok.\\
A page break before this text in tabbing, but not after it, would be ok.
\end{ruletabbing}
\end{tcolorbox}
\end{document}