minted、colortbl 和 multicolumn 之间的冲突(在数组单元格中插入代码)

minted、colortbl 和 multicolumn 之间的冲突(在数组单元格中插入代码)

我正在制作一个表格,其中有些单元格包含代码。我还想给一些单元格上色。在表格单元格内使用 minted 内联代码是完全允许的。但是,我不能在多列命令中使用 minted 代码。这是一个最小的例子:

\documentclass{article}

\usepackage{minted}
\usepackage{colortbl}

\begin{document}

\begin{tabular}{|l|l|}
  \multicolumn{2}{l|}{\mintinline{rust}|let r = &mut a[1];|} \\
\end{tabular}

\end{document}


我收到以下错误信息:

This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdflatex)
 \write18 enabled.
entering extended mode
(./minted-tabular.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-01-21>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2021/10/04 v1.4n Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/minted/minted.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/kvoptions/kvoptions.sty
(/usr/share/texlive/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)
(/usr/share/texlive/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty))
(/usr/share/texlive/texmf-dist/tex/latex/fvextra/fvextra.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/share/texlive/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty)
(/usr/share/texlive/texmf-dist/tex/latex/upquote/upquote.sty)
(/usr/share/texlive/texmf-dist/tex/latex/lineno/lineno.sty))
(/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/tools/shellesc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/ifplatform/ifplatform.sty
(/usr/share/texlive/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty
(/usr/share/texlive/texmf-dist/tex/generic/infwarerr/infwarerr.sty)
(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty))
(/usr/share/texlive/texmf-dist/tex/generic/catchfile/catchfile.sty
(/usr/share/texlive/texmf-dist/tex/generic/etexcmds/etexcmds.sty))
(/usr/share/texlive/texmf-dist/tex/generic/iftex/ifluatex.sty)
(./minted-tabular.w18))
(/usr/share/texlive/texmf-dist/tex/generic/xstring/xstring.sty
(/usr/share/texlive/texmf-dist/tex/generic/xstring/xstring.tex))
(/usr/share/texlive/texmf-dist/tex/latex/framed/framed.sty)
(/usr/share/texlive/texmf-dist/tex/latex/float/float.sty))
(/usr/share/texlive/texmf-dist/tex/latex/colortbl/colortbl.sty
(/usr/share/texlive/texmf-dist/tex/latex/tools/array.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def)))/usr/bin/pygmentize

(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./minted-tabular.aux)
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)
Runaway argument?
let r = 
! Forbidden control sequence found while scanning use of \minted@inline@ii.
<inserted text> 
                \par 
l.9 ...{l|}{\mintinline{rust}|let r = &mut a[1];|}
                                                   \\
?

请注意,这是库。如果我不包含colortbl此文件,则编译。此外,我仍然可以在数组单元中使用 minted inline。

发生了什么事?我该怎么办?

答案1

加上另一副大括号。

\documentclass{article}

\usepackage{minted}
\usepackage{colortbl}

\begin{document}

\begin{tabular}{|l|l|}
  \multicolumn{2}{|l|}{{\mintinline{rust}|let r = &mut a[1];|}} \\
\end{tabular}

\end{document}

在此处输入图片描述

您收到的错误是由于\mintinline进行进一步的前向扫描,这在某种程度上与colortbl表格单元格模板的重构相冲突。

相关内容