1

I'm using ltablex and threeparttablex for my long tables across 2 or 3 pages. However, into the text body I use tabularx without the intention of numbering, but the tabularx environment is increasing the numeration of the tables. Any help?

\documentclass{article}

\usepackage{booktabs,ltablex,threeparttablex,blindtext}


\begin{document}

\blindtext

\begin{tabularx}{\linewidth}{cc}
Row 1, Col 1 & Row 1, Col 2\\
Row 2, Col 1 & Row 2, Col 2
\end{tabularx}

\begin{table}[h]
  \begin{ThreePartTable}
    \begin{tabularx}{\textwidth}{cc}
\caption{Example}
\label{tab:dummy}\\
\toprule
ex1 & ex2\\
ex3 & ex4\\
\bottomrule
\end{tabularx}%
\begin{tablenotes}\footnotesize
\item[a] note1.
\item[b] note2.
\end{tablenotes}
\end{ThreePartTable}
\end{table}

\end{document} 
  • tabularx tries to determine the column widths etc. (you're not using X columns at all, so why using tabularx here?) and as such is evaluating the code at least twice, i.e. the \caption is called twice at least and increases the table counter. By the way, \caption inside the tabularx environment is weird – user31729 Jan 18 at 17:28
  • @ChristianHupfer I'm using the ´tabularx´ for the X columns. In this MWE I want to focus in the numbering problem. The caption inside the tabularx is recommended for the type os tables that I'm using – Daniel Valencia C. Jan 18 at 17:45
  • @ChristianHupfer: caption inside tabularx is not so weird with package ltablex: for tabularxs that break across pages, one has to use the longtable syntax. – Bernard Jan 18 at 19:33
  • @Bernard: I missed the ltablex stuff issue, in this \caption is alright there – user31729 Jan 18 at 19:37
  • by the way also longtable increases table counter even when the longtable has no caption – user4686 Jan 18 at 20:24
2

A fix with a new environment that reduces the counter (increased by tabularx environment through "ltablex" package)

\documentclass{article}

\usepackage{ltablex,booktabs,threeparttablex,blindtext,environ}

\NewEnviron{mytabularx}[2]{\begin{tabularx}{#1}{#2}\BODY\end{tabularx}\addtocounter{table}{-1}}

\begin{document}

\blindtext

\begin{mytabularx}{\linewidth}{cc}
Row 1, Col 1 & Row 1, Col 2\\
Row 2, Col 1 & Row 2, Col 2
\end{mytabularx}

\begin{table}
 \caption{Example}\label{tab:dummy}
  \begin{ThreePartTable}
    \begin{mytabularx}{\linewidth}{cc}
\toprule
ex1 & ex2\\
ex3 & ex4\\
\bottomrule
\end{mytabularx}%
\begin{tablenotes}\footnotesize
\item[a] note1.
\item[b] note2.
\end{tablenotes}
\end{ThreePartTable}
\end{table}

\begin{mytabularx}{\linewidth}{cc}
Row 1, Col 1 & Row 1, Col 2\\
Row 2, Col 1 & Row 2, Col 2
\end{mytabularx}

\begin{table}
 \caption{Example}\label{tab:dummy2}
  \begin{ThreePartTable}
    \begin{mytabularx}{\linewidth}{cc}
\toprule
ex1 & ex2\\
ex3 & ex4\\
\bottomrule
\end{mytabularx}%
\begin{tablenotes}\footnotesize
\item[a] note1.
\item[b] note2.
\end{tablenotes}
\end{ThreePartTable}
\end{table}
\end{document} 

Output:

enter image description here

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.