标题与文本保持一致

标题与文本保持一致

您好,我正在用 Latex 写一个虚构的故事,在对话框方面遇到了麻烦。当一个角色说了些什么时,他们的名字和对话会放在一个无边框的框中。然而,我无法将名字和相应的对话放在一起。下图显示了第一页和第二页之间的过渡中出现的问题:

在此处输入图片描述

我希望第一页底部的名称与第二页顶部的对话框保持一致。我用来生成此代码的代码如下所示。我遇到的问题在于名为“dial”的新环境。

\documentclass[envcountsame,envcountchap]{article}

%used to make margins one left and right side of text
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist 


%Used to create the dialogue boxes
\newenvironment{dial}[1]
    {
        \begin{center}
            \vspace{0.3cm}
            \normalsize{\textbf{#1\\[1ex]}}
            \begin{small}
                \begin{changemargin}{2cm}{2cm}

    }
    {

                \end{changemargin}
            \end{small}
        \end{center}
    }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{dial}{Abbott}
hey
\end{dial}


\begin{dial}{Costello}
hey
\end{dial}


\begin{dial}{Abbott}
hey
\end{dial}


\begin{dial}{Costello}
hey
\end{dial}


\begin{dial}{Abbott}
hey
\end{dial}


\begin{dial}{Costello}
hey
\end{dial}


\begin{dial}{Abbott}
hey
\end{dial}


\begin{dial}{Costello}
hey
\end{dial}


\begin{dial}{Abbott}
hey
\end{dial}


\begin{dial}{Costello}
hey
\end{dial}


\begin{dial}{Abbott}
hey
\end{dial}


\begin{dial}{Costello}
This is the Problem right here. This is the Problem right here. This is the Problem right here. This is the Problem right here. This is the Problem right here. This is the Problem right here. This is the Problem right here. This is the Problem right here. This is the Problem right here. This is the Problem right here.
\end{dial}


\begin{dial}{Abbott}
hey
\end{dial}


\begin{dial}{Costello}
hey
\end{dial}


\end{document}



    \begin{dial}{Costello}
    hey
    \end{dial}


    \end{document}

我希望这些信息足以传达我的问题。再见,希望很快能收到你们的回复 :D

答案1

\nopagebreak只需在标题和内容之间添加一个到您的环境中:

\newenvironment{dial}[1]
    {
        \begin{center}
            \vspace{0.3cm}
            \normalsize{\textbf{#1\\[1ex]}}
            \nopagebreak
            \begin{small}
                \begin{changemargin}{2cm}{2cm}

    }
    {

                \end{changemargin}
            \end{small}
        \end{center}
    }

虽然这个解决方案应该可以完美地工作,但请注意,您这样做的方式可能不是最好的,在您的问题的评论中提到了出色的替代方案。

相关内容