4

I want to numerate every row, excluding the first one, in a tabularx environment. In my MWE the first line, headline, is also numerated. How can I turn this off?

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

Here is one option, using a conditional for printing the value in each row:

enter image description here

\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 is started from -1 at the beginning of every tabularx, making the header be at \value{rowcount}=0. So, we only print \therowcount. when not \value{rowcount}=0, or

\ifnum\value{rowcount}=0\else\therowcount.\hspace*{1pt}\fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.