我想在 tabularx 环境中对除第一行之外的每一行进行编号。在我的 MWE 中,第一行(标题)也是编号的。我该如何关闭此功能?
\documentclass{article}
\usepackage{array,tabularx}
\newcounter{rowcount}
\setcounter{rowcount}{0}
\begin{document}
\begin{tabularx}{\textwidth}{@{\stepcounter{rowcount}\therowcount.\hspace*{1pt}}X|X}
head1 & head2\\
text text text text text text text text text text text text text text text text & txet\\
text text text text text text text text text text text text text text text & txet\\
text & txet\\
text & txet\\
text & txet\\
text & txet\\
\end{tabularx}
\end{document}
答案1
这是一个选项,使用条件来打印每行的值:
\documentclass{article}
\usepackage{array,tabularx}
\newcounter{rowcount}
\let\oldtabularx\tabularx
\renewcommand{\tabularx}{\setcounter{rowcount}{-1}\oldtabularx}
\begin{document}
\begin{tabularx}{\textwidth}{
@{\stepcounter{rowcount}\ifnum\value{rowcount}=0\else\therowcount.\hspace*{1pt}\fi}X|
X}
\bfseries head1 & \bfseries head2 \\
text text text text text text text text text text text text text text text text & textt \\
text text text text text text text text text text text text text text text & text \\
text & text \\
text & text \\
text & text \\
text & text
\end{tabularx}
\end{document}
rowcount
从-1
开始每一个 tabularx
,使标题位于\value{rowcount}=0
。因此,我们仅\therowcount.
在\value{rowcount}=0
或时打印
\ifnum\value{rowcount}=0\else\therowcount.\hspace*{1pt}\fi