tabularray 和 listings 可组合性

tabularray 和 listings 可组合性

以下 MWE(借自@Celdor 回答},其中使用tabular表格,工作正常:

\documentclass{article}
\usepackage{array}
\usepackage{xcolor}
\usepackage{listings}
\lstset{language=sql,
        keywordstyle=\color{black!30!blue}\bfseries,
        columns=flexible,
        }

\begin{document}
\noindent\begin{tabular}{w{l}{11cm}|c}
\begin{lstlisting}
SELECT SUM(lo_extendedprice*lo_discount) AS revenue
    FROM lineorder, dwdate
WHERE d_yearmonthnum = 199401
    AND lo_orderdate = d_datekey
    AND lo_discount BETWEEN 4
    AND 6 AND lo_quantity
    BETWEEN 26 AND 35;
\end{lstlisting} & 1 \\
    \end{tabular}
\end{document}

在此处输入图片描述

与此同时,使用该tblr包的转换,即使使用选项verb,也不会:

\documentclass{article}
\usepackage{tabularray}
\usepackage{xcolor}
\usepackage{listings}
\lstset{language=sql,
        keywordstyle=\color{black!30!blue}\bfseries,
        columns=flexible,
        }

\begin{document}
\noindent\begin{tblr}{colspec = {X[j,m] | c},
                      rowsep=3pt,
                      verb}
\begin{lstlisting}
SELECT SUM(lo_extendedprice*lo_discount) AS revenue
    FROM lineorder, dwdate
WHERE d_yearmonthnum = 199401
    AND lo_orderdate = d_datekey
    AND lo_discount BETWEEN 4
    AND 6 AND lo_quantity
    BETWEEN 26 AND 35;
\end{lstlisting} & 1 \\
    \end{tblr}
\end{document}

在 MWE 之上进行编译会引发以下警告:

Package Listings Warning: Text dropped after begin of listing on input line 1.

! Missing } inserted.
<inserted text>
                }
l.25     \end
             {tblr}
? 

lstlisting并且什么都没产生。我是否过于简化了代码的插入,或者tabularray还不支持这一点?

关于这个问题,你可以将其视为后续问题`listings` 和 `tabularray` 同时使用时出错

答案1

这是一个解决方法filecontents*

\documentclass{article}
\usepackage{tabularray}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
  language=sql,
  keywordstyle=\color{black!30!blue}\bfseries,
  columns=flexible,
}

\begin{document}

\begin{filecontents*}[force]{\jobname-sql.tex}
SELECT SUM(lo_extendedprice*lo_discount) AS revenue
    FROM lineorder, dwdate
WHERE d_yearmonthnum = 199401
    AND lo_orderdate = d_datekey
    AND lo_discount BETWEEN 4
    AND 6 AND lo_quantity
    BETWEEN 26 AND 35;
\end{filecontents*}

\noindent\begin{tblr}{colspec = {X[j,m] | c},
    rowsep=3pt,
    verb}
  \lstinputlisting{\jobname-sql.tex} & 1 \\
\end{tblr}
\end{document}

相关内容