1

Im trying to have automatic rownumbers on a multi-page table reset on a page-break. So far I got this, but I dont know, why the counter does not reset:

\documentclass{article}
\usepackage{lipsum,ltablex}
\newcounter{rownumber}
\begin{document}
\begin{tabularx}{\textwidth}{|>{\stepcounter{rownumber}\arabic{rownumber}}c|X|}
    \hline
    \multicolumn{1}{|c|}{Rownumber\setcounter{rownumber}{0}}&Data\\\hline
    \endhead
    &Ok\newline\lipsum[1]\\\hline
    &Ok\newline\lipsum[2]\\\hline
    &Ok\newline\lipsum[3]\\\hline
    &Ok\\\hline
    &Ok\\\hline
    &Should be 1\\\hline
    &Should be 2\\\hline
    &\ldots\\\hline
\end{tabularx}
\end{document}
Virsacer
  • 111
  • longtable uses tex's asynchronous page breaking routines, so typically many rows, or with tabularx as you have there, the entire table, has been set before any page breaking happens. – David Carlisle Dec 09 '14 at 22:27
  • Thanks for your answer @DavidCarlisle So the headlines are beeing added afterwards and there is no way to reset the counter (at the right time) and other table-packages work the same way? – Virsacer Dec 10 '14 at 09:24
  • @Visacer no in fact other table packages do not work the same way superatb/xtab page break by counting rows witin the macros and making a new tabular on each page, so thety are probably a better starting point – David Carlisle Dec 10 '14 at 13:28
  • You can use the aux file and two runs. See http://tex.stackexchange.com/questions/196033/how-do-i-test-for-a-new-page – John Kormylo Dec 10 '14 at 22:50
  • @DavidCarlisle Thanks I got it working with xtab, but apparently I connot use the X columntype, which is more important to me. – Virsacer Dec 11 '14 at 09:11
  • @JohnKormylo Thanks, I will have a look at that – Virsacer Dec 11 '14 at 09:12

0 Answers0