tabularray 和清單的可組合性

tabularray 和清單的可組合性

以下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同時,即使使用 option ,其使用套件的轉換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}

相關內容