\documentclass{article}
\usepackage{booktabs}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\begin{document}
\begin{tabular}{@{}l*{2}{>{\textbackslash\ttfamily}l}l<{Example text}@{}}
\toprule[1.5pt]
& \multicolumn{2}{c}{\head{Input}} & \multicolumn{1}{c}{\head{Output}}\\
& \normal{\head{Command}} & \normal{\head{Declaration}} & \normal{} \\
\cmidrule(lr){2-3}\cmidrule(l){4-4}
Family & textrm & rmfamily & \rmfamily\\
& textsf & sffamily & \sffamily\\
& texttt & ttfamily & \ttfamily\\
\bottomrule[1.5pt]
\end{tabular}
\end{document}
上述代码片段会产生一个错误
\begin{tabular}{@{}l*{2}{>{\textbackslash\ttfamily}l}l<{Example text}@{}}
而且,我不明白错误原因。错误信息为“错误:LaTeX 错误:数组参数中的字符非法”。这是什么问题?
答案1
在列条目的开头或结尾插入内容由>{<start>}
或执行<{<end>}
。此功能由array
包裹,但您没有包括:
\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\begin{document}
\begin{tabular}{@{}l*{2}{>{\textbackslash\ttfamily}l}l<{Example text}@{}}
\toprule[1.5pt]
& \multicolumn{2}{c}{\head{Input}} & \multicolumn{1}{c}{\head{Output}}\\
& \normal{\head{Command}} & \normal{\head{Declaration}} & \normal{} \\
\cmidrule(lr){2-3}\cmidrule(l){4-4}
Family & textrm & rmfamily & \rmfamily\\
& textsf & sffamily & \sffamily\\
& texttt & ttfamily & \ttfamily\\
\bottomrule[1.5pt]
\end{tabular}
\end{document}