2

I am trying to use a custom theorem-like environment inside a list (using the enumitem package), but I get the error message

``LaTeX Error: Something's wrong--perhaps a missing \item.''

Outside the list, the custom environment works correctly. How can I correct this? Is there an incompatibility between the enumitem package and custom environments?

Here is the MWE:

\documentclass{article}
\usepackage{amsthm} % theorem-like environments
\usepackage{framed} % vertical bar to the left of text of custom environment
\usepackage{enumitem} % enumerations
\usepackage{lipsum} % dummy text

% custom environment, with vertical bar to the left of text
\newtheorem{theoremzz}{Theorem}
\newenvironment{theorem}[1][]{\begin{theoremzz}[#1]\begin{leftbar}}{\end{leftbar}\end{theoremzz}}

% default environment
\newtheorem{proposition}[theoremzz]{Proposition}

\begin{document}

\begin{enumerate}

\item I want my custom \texttt{theorem} environment inside this item of the list.

\begin{theorem}
\lipsum[1][1-4]
\end{theorem}

As you can see, it did not work correctly.

\item Now an attempt with a default \texttt{proposition} environment:

\begin{proposition}
\lipsum[2][1-4]
\end{proposition}

It works!

\end{enumerate}

\noindent Outside the list, the custom environment works:

\begin{theorem}
\lipsum[3][1-4]
\end{theorem}

\end{document}

enter image description here

1 Answer 1

1

Consider placing the nested theorem inside a minipage of appropriate width (\linewidth). This boxing circumvents the error. Some additional spacing is added to match the surrounding layout.

enter image description here

\documentclass{article}

\usepackage{amsthm,framed}
\usepackage{lipsum}

% Custom environment, with vertical bar to the left of text
\newtheorem{theoremzz}{Theorem}
\newenvironment{theorem}[1][]{\begin{theoremzz}[#1]\begin{leftbar}}{\end{leftbar}\end{theoremzz}}

% default environment
\newtheorem{proposition}[theoremzz]{Proposition}

\begin{document}

\begin{enumerate}

  \item I want my custom \texttt{theorem} environment inside this item of the list.

    \vspace{\topsep}

    \begin{minipage}{\linewidth}
      \begin{theorem}
        \lipsum[1][1-4]
      \end{theorem}
    \end{minipage}

    \vspace{\topsep}

    As you can see, it worked as expected.

  \item Now an attempt with a default \texttt{proposition} environment:

    \begin{proposition}
      \lipsum[2][1-4]
    \end{proposition}

    It works!

\end{enumerate}

\noindent Outside the list, the custom environment works:

\begin{theorem}
  \lipsum[3][1-4]
\end{theorem}

\end{document}
1
  • Note that the minipage construction will make the theorem unbreakable across the page boundary.
    – Werner
    Dec 30, 2020 at 6:34

You must log in to answer this question.

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