1
\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

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}

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.