I have a problem compiling the following minimal example:
\documentclass{article}
\usepackage{listings}
\usepackage{tcolorbox}
\begin{document}
\begin{center}
\begin{tcolorbox}
\begin{lstlisting}
alert(123);
\end{lstlisting}
boom
\begin{enumerate}
\item one
\item two
\end{enumerate}
\end{tcolorbox}
\end{center}
\end{document}
I cannot reduce anything and don't know if the problem is dedicated to listings, tcolorbox, enumerate or center. (maybe all of them together)
The error is
! LaTeX Error: Something's wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.15 ^^I^^I^^I\item o
ne
which is (like most LaTeX errors) not very useful…
\begin{center}
and\end{center}
and instead use{\centering.... }%
the problem is resolved. Plus using thecenter
environment is adding additional vertical space -- which is usually not desired. See When should we use \begin{center} instead of \centering?.center
environment supposed to do? Thelstlisting
environment will use the whole text width anyway.\begin{center} ... \end{center}
environment or the\centering
command while we could simply use thetcolorbox
environment with thecenter
option?\begin{tcolorbox}[center] ... \end{tcolorbox}