tabularx 环境中的 Lstlisting/Verbatim?

tabularx 环境中的 Lstlisting/Verbatim?

我注意到\lstlistingtabularx 内部不起作用:

\documentclass{article}
\usepackage{listings}
\usepackage{tabularx}
\let\code\lstinline

\begin{document}

% It does work
\begin{tabular}{|*3{>{}l|}} \hline
\code!\begin{center}! & \code!\centering! & \code!\begin{raggedleft}! \\ \hline
\end{tabular}

% It doesn't work
\begin{tabularx}{\columnwidth}{|*3{>{}X|}} \hline
\code!\begin{center}! & \code!\centering! & \code!\begin{raggedleft}! \\ \hline
\end{tabularx}

\end{document}

我收到此错误:

! Improper alphabetic constant.
<to be read again> 
                   \begin 
l.16 \end{tabularx}

出了什么问题?我该如何修复?

相关内容