6

I make an FAQ document, for this I redefined environments like

\newenvironment{question} % no indenting, bold and new paragraph
{\setlength\parindent{0pt}\bfseries}
{\par}

\newenvironment{answer} % v spacing at the end
{}
{\vspace*{10pt}}

(This is likely to change in the near future.)

In the document, I have brief questions and answers:

\begin{question}
    Why?
\end{question}
\begin{answer}
    I don't know!
\end{answer}

How can I "group" question and answer in order to not have a pagebreak between question and answer?

pfnuesel
  • 642
  • you might try \par\nobreak as the closing part of the question environment. this won't prevent breaks within either the question or answer though, so to encourage a break before a question, start that environment with \par\penalty-1000. (\goodbreak is defined as \par\penalty-500, so you probably want something stronger than that.) you'll probably still need to use \newpage sometimes. – barbara beeton Dec 12 '13 at 17:42

1 Answers1

9

The simplest solution is to define a wrapper environment such as

\newenvironment{qn}{\par\noindent\begin{minipage}{\linewidth}}{\end{minipage}\par}

then use

\begin{qn}
\begin{question}
    Why?
\end{question}
\begin{answer}
    I don't know!
\end{answer}
\end{qn}
Werner
  • 603,163
David Carlisle
  • 757,742
  • Any explanation whatsoever, would be just fantastic and greatly appreciated! Is it the minipage command that prevents pagebreaks? The official documentation does not mention it at all (http://joshua.smcvt.edu/latex2e/minipage.html) :/ – Domi Nov 07 '20 at 20:18
  • 1
    @Domi yes that is essentially minipage's only function: it makes an unbreakable box. – David Carlisle Nov 07 '20 at 20:20