2
\documentclass[varwidth]{standalone}
\usepackage {listings}
\usepackage {tabularx}

\begin{document}
Expectation:
\begin{table}[l]
    abc \lstinline[]${def}$ ghi \\
    \lstinline[]$abc {def} ghi$ \\
\end{table}

Found:
\begin{table}
    \begin{tabularx}{\textwidth}{X}
        abc \lstinline[]${def}$ ghi \\
        \lstinline[]$abc {def} ghi$ \\
    \end{tabularx}
\end{table}
\end{document}

I am trying to use lstinline with curly braces inside a tabularx table, but it leads to weird problems.

enter image description here

1 Answer 1

3

You can not use verb-like commands in the argument of another command, and for technical reasons, that includes the body of tabularx, so:

\documentclass[varwidth]{standalone}
\usepackage {listings}
\usepackage {tabularx}
\newsavebox\zzz
\newsavebox\zzzb
\begin{document}
Expectation:
\begin{table}%??[l]
    abc \lstinline[]${def}$ ghi \\
    \lstinline[]$abc {def} ghi$ \\
\end{table}

Found:
\begin{table}
\begin{lrbox}{\zzz}\lstinline[]${def}$\end{lrbox}
\begin{lrbox}{\zzzb}\lstinline[]$abc {def} ghi$\end{lrbox}
    \begin{tabularx}{\textwidth}{X}
        abc \usebox\zzz\ ghi \\
         \usebox\zzzb
    \end{tabularx}
\end{table}
\end{document}

You must log in to answer this question.

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