0

The following MWE (borrowed from @Celdor answer}, where is used tabular table, works fine:

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

enter image description here

Meanwhile its transformation to use the tblr package, even with option verb, doesn't:

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

Compiling above MWE throw the following warnings:

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

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

and not produce anything. Did I oversimplified the inserting of lstlisting code, or tabularray doesn't support this yet?

On this question you can look as following-up question to Error with `listings` and `tabularray` used together

3
  • tblr env absorbs its content using ltcmd/xparse arg-type +b (check how \NewTblrEnviron and tblr are defined in package source), thus all the newlines in a verbatim env are irreversibly converted to spaces. I don't see any easy workaround/fix. See discussion github.com/lvjr/tabularray/issues/13. Commented Mar 14, 2023 at 8:47
  • @muzimuzhiZ, thanks for info. I will check this at my next spare time (late evening in my time zone).
    – Zarko
    Commented Mar 14, 2023 at 9:06
  • 1
    @muzimuzhiZ, i check discussion on github. It seems that tabularray will not handle verbatim/listings soon :-). So, the suggestion of Paul Gaborit in his answer below seems to be the only way to go!
    – Zarko
    Commented Mar 14, 2023 at 21:03

1 Answer 1

1

Here is a workaround using 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}
3
  • This works, but ... my real table have 13 rows each with different listings. This means I need to define 13 filecontents* . Huh, a bit annoying! Anyway, thank you very much (ab for few days only +1)
    – Zarko
    Commented Mar 14, 2023 at 8:13
  • @Zarko You can use a counter to differentiate each external file. Commented Mar 14, 2023 at 8:26
  • 1
    I already use your solution in my answer tex.stackexchange.com/questions/679251/…. I differentiate files similarly as you suggest in comment. It works fine and code is not so cumbersome as I afraid in the first. Thank you again!
    – Zarko
    Commented Mar 14, 2023 at 9:12

You must log in to answer this question.

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