[Tex/LaTex] Strange compilation problem using adjustwidth environment from changepage package

compilingerrorspackages

The following code gives a compilation error.

\documentclass{report}

\usepackage{changepage}

\begin{document}

\chapter{Text1}

\begin{adjustwidth}{1cm}{2cm}

\section{Text2}

Text3

\begin{quote}
Text4
\end{quote}

\end{adjustwidth}

\end{document}

The error says: "Something's wrong–perhaps a missing \item." in the line of \begin{quote}. The error disappears when I remove either of

  • the line \chapter{Text1}
  • the line \section{Text2}
  • the line Text3
  • the adjustwidth environment

How can this be?

Best Answer

The nesting fails. I don't know why but the following works:

The relevant part is:

\nointerlineskip\leavevmode

It's the classic 'a lot of stuff is implemented by LaTeX as a trivlist, even though this results in weird error messages' business. As a result, you need something to deal with the \par tokens correctly, which \leavevmode does. Here the complete MWE:

\documentclass{report}

\usepackage{changepage}

\begin{document}

\chapter{Text1}

\begin{adjustwidth}{1cm}{2cm}
\nointerlineskip\leavevmode
\section{Text2}

Text3

\begin{quote}
Text4
\end{quote}

\end{adjustwidth}

\end{document}