如何防止段落之間分頁

如何防止段落之間分頁

我想排版類似「引用加歸屬」的內容,例如在書籍章節的開頭。它應該看起來像這樣:

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}

相關內容