12

Hi I would like to have an item starting directly at level 2 in an item list.

The reason is I am using lstlistings inside the list and I would like those to be without margin so I am doing something like this:

\begin{itemize}
    \item Top level
    \begin{itemize}
        \item Second level
    \end{itemize}
\end{itemize}
\lstinputlisting{somefile}
\begin{itemize}
    \begin{itemize}
        \item Second level
    \end{itemize}
\end{itemize}
\lstinputlisting{someotherfile}

... but latex complains that there is no item in the second list at first level:

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

How can I fix that ? A possible option for me would also be to get rid of the margin for the listing if inside the list (but I didn't find a solution for that either).

So something like that without margin for the listings:

\begin{itemize}
    \item Top level
    \begin{itemize}
        \item Second level
        \lstinputlisting{somefile}
        \item Second level
        \lstinputlisting{someotherfile}
    \end{itemize}
\end{itemize}
2
  • 2
    You could do your first version but with \item[]\begin{itemize} instead of omitting the item.
    – TeXnician
    Commented Jul 5, 2017 at 8:16
  • @TeXnician I did not know I could do that :) Thanks! Could you make that an answer so I can pick it ? Commented Jul 5, 2017 at 12:54

1 Answer 1

22

Your error actually states how to solve it: You have to put an item into the itemize environment. As you do not want to see it, but want the indentation you can simply use a \item[]. Your itemize would then look like this:

\begin{itemize}
    \item Top level
    \begin{itemize}
        \item Second level
    \end{itemize}
\end{itemize}
\lstinputlisting{somefile}
\begin{itemize}
    \item[]\begin{itemize}
        \item Second level
    \end{itemize}
\end{itemize}

Just as remark: If you would want to switch to enumerate, you should have a look at enumitem and the resume option.

0

You must log in to answer this question.

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