5

Consider this MWE:

\documentclass{article}
\usepackage{multicol}
\usepackage{listings}

\begin{document}

\def\extra{extra}

\begin{lstlisting}[
  multicols=2,
  caption={
    [short] aaaa \extra, \lstinline{asf_sdf}
  },
]
LDPT_NULL = 0,
LDPT_API_VERSION,
LDPT_GOLD_VERSION,
LDPT_LINKER_OUTPUT,
\end{lstlisting}

It crashes with:

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

It will not crash if multicols is commented - or if multicols is left, and \lstinline is commented. EDIT - and also, \protect\lstinline{asf_sdf} does not help.

How can I use all these commands together?

2

The listings documentation (see subsection 5.8) states that

the multicolumn option is known to fail with some keys.

If you can afford to do without \lstinline, use a custom macro instead:

enter image description here

\documentclass{article}

\usepackage{multicol}
\usepackage{listings}

\makeatletter
\newcommand\inlinecode[1]
  {\lst@basicstyle #1}
\makeatother

\begin{document}

\def\extra{extra}

\begin{lstlisting}[
  multicols=2,
  caption={
    [short] aaaa \extra, \inlinecode{asf\_sdf}
  },
]
LDPT_NULL = 0,
LDPT_API_VERSION,
LDPT_GOLD_VERSION,
LDPT_LINKER_OUTPUT,
\end{lstlisting}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.