Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm wondering, are there any ways to get (and forward-reference at the beginning of the document) the total number of tables when using longtables? There are utility packages for standard table counter, but it's not used in longtable anymore starting from v3.02:

Counter for the tables, added in V3.02. Previous versions just used the LaTeX counter table, but this fails if table is reset during a document, eg report class resets it every chapter. This was changed from \newcount\LT@tables in V3.04. LaTeX counters are preserved correctly when \includeonly is used. In the rest of the file \LT@tables has been replaced by \c@LT@tables without further comment.

share|improve this question

1 Answer 1

up vote 7 down vote accepted
\documentclass{article}

\usepackage{longtable}

\makeatletter 
\gdef\LTno{??}
\AtEndDocument{\immediate\write\@auxout{\gdef\string\LTno{\theLT@tables}}}
\makeatother

\begin{document}

There are \LTno\ longtables here.

\begin{longtable}{c}a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\\end{longtable}

zzz

\begin{longtable}{c}a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\\end{longtable}

zzz

\begin{longtable}{c}a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\a\\\end{longtable}

zzz

\end{document}
share|improve this answer
    
It works, thanks. –  apsk Jan 10 at 16:00
3  
@apsk I still have a vague recollection of how longtable works:-) –  David Carlisle Jan 10 at 16:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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