5

I would like to typeset something like a "quote plus attribution", e.g. at the beginning of a book chapter. It should look like this:

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.

For this purpose, I have an environment and a command, used like this:

\section{Chapter Title}

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

Question: How can I guarantee that there is no page break between the attribution and the body of the quote? I don't mind if there's a page break within the quote, but there shouldn't be one between the quote and the attribution.

I'm happy to change my entire setup if that's necessary. In my case, it's like this:

\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}
10
  • 1
    Please add a minimal working example (MWE). Answering your question is difficult without knowing how your foo environment is defined. Note also that \bar is the name of an existing macro. Be careful not to overwrite it if you need it in your document.
    – jub0bs
    Commented Apr 8, 2013 at 23:07
  • @Jubobs: OK, done. My fooquote is a bit lengthy because I want to suppress indentation after the quote.
    – Kerrek SB
    Commented Apr 8, 2013 at 23:09
  • 1
    Use the needspace package, and on the last line of the quote, issue a \needspace for the anticipated gap+attribution. space If it can't reserve it in advance, the page will break, with the end of the quote being bumped to the next page. Commented Apr 8, 2013 at 23:10
  • 1
    When using the package, I've sometimes found the actual number of \baselineskip's to be a non-precise measure. Try increasing the number above 3, and experiment with how it works. Commented Apr 8, 2013 at 23:19
  • 1
    Only way to guarantee is to wrap it in a minipage. What you showing is actually an "epigraph" is it really this long? Try using the epigraph package.
    – yannisl
    Commented Apr 8, 2013 at 23:36

1 Answer 1

9

Really it would be a lot easier to answer if there was a supplied example document, fragments are much harder to comment on but

\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}

the \bgroup \egroup are not needed as the fooquote environment is already a group, also { \bgroup introduces a space character.

The \end redefinition (which is rather dangerous really) appears to be too early it will affect the \end of any nested environment and in particular the quote environment. You just want to activate it after fooquote (I assume) so it should be right at the end of the end code of the definition.

flushright is intended to be an environment form, the declaration form being \raggedleft but if it's one line I'd probably just use \hspace{\fill}. \nopagebreak ought to be enough to prevent page breaks at that point as long as there is flexibility elsewhere in the page.

enter image description here

\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}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .