如何让 LaTeX 优先在段落之间放置分页符?

如何让 LaTeX 优先在段落之间放置分页符?

我正在使用该memoir课程排版小说,故事中有几个“场景”发生在聊天室里。

我已经创建了一个环境,可以按照我想要的方式设置段落和字体,但仍然有些尴尬。

最小工作示例(使用 xelatex):

\documentclass[statementpaper,12pt]{memoir}
\usepackage[l2tabu,orthodox]{nag}
\usepackage{xparse}
\usepackage{lipsum}

\newlength{\defaultraggedyrightspace}
\setlength{\defaultraggedyrightspace}{1.85em}

\newlength{\prechatparindent}
\NewDocumentEnvironment{chatroom}{}{
    \raggedyright[2.5em]
    \setlength{\prechatparindent}{\parindent}
    \setlength{\parindent}{0em}
    \nonzeroparskip{}
    \ttfamily{}
}{
    \normalfont{}
    \raggedyright[\defaultraggedyrightspace]
    \setlength{\parindent}{\prechatparindent}
    \traditionalparskip{}
}

\begin{document}

\section*{It was a dark and stormy night}
\lipsum[2-6]

\begin{chatroom}

    \textbf{AOL Chat Room}\\
    \textbf{The Crash Pad – A Place to Start}
    
    \textbf{OnlineHost}\\
    ****GreenSky has entered the room.****
    
    \textbf{GreenSky}\\
    Hello everyone. I would like to discuss the ethics of war and conquest.
    Which chat room would be a good place to do that?
    
    \textbf{Blksnakexxxx}\\
    A/S/L?
    
    \textbf{SweetEzcape101}\\
    Whta a fukin nerd lol
    
    \textbf{PHaTMoNkEy}\\
    r u my social studies teacher? better get back 2 writing my essay 4 ur
    class roflmao
    
    \textbf{GreenSky}\\
    I am new to using the Internet. I just want some advice.
    
    \textbf{OOo\_KawaiiChica\_oOo}\\
    hiiiiii newbie! X3 *glomps you*
    
    \textbf{ILoveMyChevyTruck69}\\
    Type 9 if ur a woman with a pic
    
    \textbf{SailorNeptuneRox}\\
    Hey GreenSky, my friend hangs out on an IRC channel where they talk
    about stuff like that sometimes.
    
    \textbf{SailorNeptuneRox}\\
    Check out the \#philosophy channel on the Undernet server.
    
    \end{chatroom}

\section*{It was a bright and sunny day}

\lipsum[5-8]

\end{document}

输出的屏幕截图

有时分页符会恰好位于句柄和聊天语句的第一行之间。我特别想避免这种情况。我还希望 LaTeX 能够优先放置分页符之间段落,但是这比句柄后立即的分页符要好一些。

我还想为聊天的“段落”定义一个新命令,以便我可以在我的源代码中获得类似这样的内容:

\chatline[GreenSky]{
    Hello everyone. I would like to discuss the ethics of war and conquest.
    Which chat room would be a good place to do that?
}

\nopagebreak[4]我认为我可以使用and来改善分页符的位置,\nopagebreak[1]但我不确定具体该怎么做。我尝试了这个,但它并没有阻止位置错误的分页符:

\NewDocumentCommand{\chatline}{om}{\IfValueT{#1}{\nopagebreak[4]\textbf{#1}\\}\nopagebreak[1]#2}

相关内容