使用 列说明符在表格内逐字插入

使用  列说明符在表格内逐字插入

我想绘制一个有两列的表格:第一列包含一些LaTeX命令,第二列包含预览。我不想在每一行中插入命令\verb++,而是想利用<>列说明符。但这会导致编译错误。请考虑以下 MWE:

\documentclass{article}
\usepackage{booktabs}

\begin{document}
 \begin{table}
  \centering
  \begin{tabular}{ll}
  %\begin{tabular}{>{\verb+}l<{+}l} <--- what I want to use
   \verb+\LaTeX+    & \LaTeX
  \end{tabular}
 \end{table}
\end{document}

答案1

https://tex.stackexchange.com/a/207977/197451

第一种方法是使用 collectcell 和 detokenise

在此处输入图片描述

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{array,collcell}
\newcommand{\myverb}[1]{\ttfamily\detokenize{#1}}

\begin{document}

\begin{tabular}{ >{\collectcell\myverb}l<{\endcollectcell} l }
  PI_all_data_BBB_M15X.pdf     & Results for \verb=BBB= model with profile plots \\
  PI_all_data_BetaBin_M15X.pdf & Results for \verb=BetaBin= model with profile plots \\
  PI_all_data_BinLNB_M15X.pdf  & Results for \verb=BinLNB= model with profile plots \\
  PI_all_data_Bin_M15X.pdf     & Results for \verb=Bin= model with profile plots \\
  PI_all_data_LogGamma_M15X.pdf& Results for \verb=LogGamma= model with profile plots \\
  PI_all_data_TwoBin_M15X.pdf  & Results for \verb=TwoBin= model with profile plots
\end{tabular}

\end{document}

第二种方法,使用 shortvrb 包

在此处输入图片描述

\documentclass{article}
\usepackage{shortvrb}

\MakeShortVerb{\|}

\begin{document}

\begin{tabular}{l l}
|some % text here| & some text here \\
|some $ text here| & some text here \\
|some { text here| & some text here \\
\end{tabular}

\end{document}

https://tex.stackexchange.com/a/297214/197451

相关内容