使用 \filbreak 时避免在所有段落内分页,同时使用 \\

使用 \filbreak 时避免在所有段落内分页,同时使用 \\

我正在写一些歌词。如果可能的话,部分空白的页面应该比段落内的分页符更受欢迎。使用\widowpenalties 1 10000\raggedbottom不起作用。

到目前为止,我只能通过在\filbreak每个段落(= 节)后面添加来实现所需的行为。

\documentclass[12pt]{article}
\usepackage[paperwidth=16cm, paperheight=9cm]{geometry}
\usepackage{nopageno}
\setlength\parindent{0pt}
\setlength\parskip{1em}

% Manually adding \filbreak at the end of stanza. This works as expected:
\begin{document}
\raggedright
Roads go ever ever on,\\
Over rock and under tree,\\
By caves where never sun has shone,\\
By streams that never find the sea;\\
Over snow by winter sown,\\
And through the merry flowers of June,\\
Over grass and over stone,\\
And under mountains in the moon.\filbreak

Roads go ever ever on\\
Under cloud and under star,\\
Yet feet that wandering have gone\\
Turn at last to home afar.\\
Eyes that fire and sword have seen\\
And horror in the halls of stone\\
Look at last on meadows green\\
And trees and hills they long have known.\filbreak
\end{document}

使用手动 \filbreak 编译

但是,我不想在每个段落后手动输入这些内容。我尝试使用以下方法答案。问题是我还必须使用\\才能在诗句之间实现正确的换行。使用上述答案中的方法,我得到了\filbreak\\所以它不起作用。

\documentclass[12pt]{article}
\usepackage[paperwidth=16cm, paperheight=9cm]{geometry}
\usepackage{nopageno}
\setlength\parindent{0pt}
\setlength\parskip{1em}

% Trying to add \filbreak after each paragraph automatically. Not working:
\makeatletter
    \def\filbreak{!\@@par\vfil\penalty-200\vfilneg}
    % Exclamation mark is there just to show, that \\ is also treated like \par.
\makeatother

\begin{document}
\raggedright
\let\par\filbreak
Roads go ever ever on,\\
Over rock and under tree,\\
By caves where never sun has shone,\\
By streams that never find the sea;\\
Over snow by winter sown,\\
And through the merry flowers of June,\\
Over grass and over stone,\\
And under mountains in the moon.

Roads go ever ever on\\
Under cloud and under star,\\
Yet feet that wandering have gone\\
Turn at last to home afar.\\
Eyes that fire and sword have seen\\
And horror in the halls of stone\\
Look at last on meadows green\\
And trees and hills they long have known.
\end{document}

使用重新定义的 \par 进行编译

是否可以以某种方式\filbreak在每个段落后而不是每个段落后放置自定义命令() ?和实际上\\如何连接?我不喜欢使用其他诗歌包,因为我正在编写自己的诗歌包,其中包含一些与此问题无关的其他特定行为。\par\\

答案1

我建议切换\\到您设置的环境\newline中,因此分页符仅允许在段落之间。poem\interlinepenalty=10000

\documentclass[12pt]{article}
\usepackage[paperwidth=16cm, paperheight=9cm]{geometry}
\usepackage{nopageno}
\setlength\parindent{0pt}
\setlength\parskip{1em}

\newenvironment{poem}{%
  \begin{flushleft}\let\\\newline
  \interlinepenalty=10000
}{\end{flushleft}}

\begin{document}

\begin{poem}
Roads go ever ever on,\\
Over rock and under tree,\\
By caves where never sun has shone,\\
By streams that never find the sea;\\
Over snow by winter sown,\\
And through the merry flowers of June,\\
Over grass and over stone,\\
And under mountains in the moon.

Roads go ever ever on\\
Under cloud and under star,\\
Yet feet that wandering have gone\\
Turn at last to home afar.\\
Eyes that fire and sword have seen\\
And horror in the halls of stone\\
Look at last on meadows green\\
And trees and hills they long have known.
\end{poem}

\end{document}

在此处输入图片描述

答案2

您可以使用para钩子来添加\filbreak并通过设置高\interlinepenalty

\documentclass[12pt]{article}
\usepackage[paperwidth=16cm, paperheight=9cm]{geometry}
\usepackage{nopageno}
\setlength\parindent{0pt}
\setlength\parskip{1em}
\AddToHook{para/after}{\filbreak}
\showoutput
% Manually adding \filbreak at the end of stanza. This works as expected:

\begin{document}

\interlinepenalty=9000

Roads go ever ever on,\\
Over rock and under tree,\\
By caves where never sun has shone,\\
By streams that never find the sea;\\
Over snow by winter sown,\\
And through the merry flowers of June,\\
Over grass and over stone,\\
And under mountains in the moon.

Roads go ever ever on\\
Under cloud and under star,\\
Yet feet that wandering have gone\\
Turn at last to home afar.\\
Eyes that fire and sword have seen\\
And horror in the halls of stone\\
Look at last on meadows green\\
And trees and hills they long have known.
\end{document}

相关内容