如何防止段落之间出现分页符

如何防止段落之间出现分页符

我想排版类似“引用加署名”的内容,例如在书的章节开头。它应该看起来像这样:

CHAPTER TITLE

       This  is an  introductory quote.
       It's stylistically questionable,
       but it's a fun LaTeX exercise.

                         -- said by  me

Now starts the main body text, which is not rele-
vant to this question. It just goes on and on and
on and on.
    It just looks like ordinary text.  You do not
have to keep reading.

为此,我有一个环境和一个命令,用法如下:

\section{Chapter Title}

\begin{fooquote}
This is an introductory quote % etc. etc.
\quoteattribution{-- said by me}
\end{fooquote}

问题:我如何保证引用说明和正文之间没有分页符?我不介意有分页符之内引用,但引用和归因之间不应该有一个。

如果有必要,我很乐意更改我的整个设置。就我而言,它是这样的:

\newenvironment{fooquote}%
{ \bgroup
  \let\oldend=\end
  \def\end##1{\oldend{##1}\csname @afterindentfalse\endcsname
                          \csname @afterheading\endcsname}
  \begin{quote}%
  \itshape%
}{%
  \end{quote}
  \egroup
}
\newcommand{\quoteattrib}[1]{\normalfont\flushright#1}

答案1

如果有提供的示例文档,那么回答起来会容易得多,片段很难评论,但是

\newenvironment{fooquote}%
{ \bgroup
  \let\oldend=\end
  \def\end##1{\oldend{##1}\csname @afterindentfalse\endcsname
                          \csname @afterheading\endcsname}
  \begin{quote}%
  \itshape%
}{%
  \end{quote}
  \egroup
}
\newcommand{\quoteattrib}[1]{\normalfont\flushright#1}

\bgroup \egroup由于fooquote环境已经是一个组,因此不需要,还引入{ \bgroup了一个空格字符。

重新\end定义(实际上相当危险)似乎为时过早,它会影响\end任何嵌套环境,尤其是quote环境。您只想在之后激活它fooquote(我假设),因此它应该位于定义的结束代码的末尾。

flushright旨在成为一种环境形式,声明形式是,\raggedleft但如果它只有一行,我可能只会使用\hspace{\fill}\nopagebreak应该足以防止分页符,只要页面的其他地方具有灵活性。

在此处输入图片描述

\documentclass{book}

\makeatletter
\newenvironment{fooquote}{%
  \begin{quote}%
  \itshape
}{%
  \end{quote}%
\par
\aftergroup\@afterindentfalse
\aftergroup\@afterheading
\ignorespacesafterend
}
\newcommand{\quoteattrib}[1]{\par\nopagebreak\normalfont\hspace*{\fill}#1\par}

\makeatother

\begin{document}

\chapter{CCC}

\begin{fooquote}
red yellow blue
\quoteattrib{me}
\end{fooquote}

One two three. One two three. One two three. One two three.
One two three. One two three. One two three. One two three.
One two three. One two three. One two three. One two three.

One two three. One two three. One two three. One two three.
One two three. One two three. One two three. One two three.
One two three. One two three. One two three. One two three.

\end{document}

相关内容