6

I'm having some issues when using tabularx within a table environment. The most annoying of these issues is that the table counter seems to be increasing by 2 for every table. So instead of having Table 1, 2 and 3, I have Table 1, 3, and 5. I've included a MWE to illustrate this behaviour.

    % ************ Preamble ****************
\documentclass[a4paper,12pt]{report}
\usepackage[top=2cm, bottom=2cm, left=3.5cm, right=2cm]{geometry} % sets margins
\usepackage{natbib} % for harvard style referencing
\usepackage[margin=10pt, labelfont=bf, format=hang, textfont={small,it}]{caption} % for more interesting captions
\captionsetup[subfigure]{style=default, margin=0pt, labelfont=bf, textfont={small,it}, singlelinecheck=true} % makes subfigure captions a bit more interesting.
\usepackage{multirow} % allows merging of rows in tables
\usepackage{ltablex} % Combines tabularx and longtable functionality
\usepackage{booktabs} % For professional looking tables

% *********** BEGIN! ******************
\begin{document}

Tables~\ref{tab:1}, \ref{tab:2} and \ref{tab:3} are not numbered correctly.

\noindent
\begin{minipage}[htb]{\textwidth}
   \captionof{table}{A table.}
   \begin{tabularx}{\textwidth}{X X X X X X X}
         \toprule
         \textbf{Number} & \multicolumn{6}{l}{\textbf{Number}} \\
         \textbf{(samples)} & \textbf{0} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} \\ \hline
         1 & \textit{1} & -- & -- & -- & -- & --\\
         2 & \textit{2} & -- & -- & -- & -- & --\\
         3--5 & \textit{3} & -- & -- & -- & -- & --\\
         6--10 & \textit{4} & \textit{5} & -- & -- & -- & --\\
         11--18 & \textit{6} & \textit{7} & \textit{8} & -- & -- & --\\
         \bottomrule
         \label{tab:1}
   \end{tabularx}
\end{minipage}

\noindent
\begin{minipage}[htb]{\textwidth}
\captionof{table}{Another table.}
\begin{tabularx}{\textwidth}{X X X X X X X}
      \toprule
      \textbf{Number} & \multicolumn{6}{l}{\textbf{Number}} \\
      \textbf{(samples)} & \textbf{0} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} \\ \hline
      1 & \textit{1} & -- & -- & -- & -- & --\\
      2 & \textit{2} & -- & -- & -- & -- & --\\
      3--5 & \textit{3} & -- & -- & -- & -- & --\\
      6--10 & \textit{4} & \textit{5} & -- & -- & -- & --\\
      11--18 & \textit{6} & \textit{7} & \textit{8} & -- & -- & --\\
      \bottomrule
      \label{tab:2}
\end{tabularx}
\end{minipage}

\noindent
\begin{minipage}[htb]{\textwidth}
\captionof{table}{And another table.}
\begin{tabularx}{\textwidth}{X X X X X X X}
      \toprule
      \textbf{Number} & \multicolumn{6}{l}{\textbf{Number}} \\
      \textbf{(samples)} & \textbf{0} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} \\ \hline
      1 & \textit{1} & -- & -- & -- & -- & --\\
      2 & \textit{2} & -- & -- & -- & -- & --\\
      3--5 & \textit{3} & -- & -- & -- & -- & --\\
      6--10 & \textit{4} & \textit{5} & -- & -- & -- & --\\
      11--18 & \textit{6} & \textit{7} & \textit{8} & -- & -- & --\\
      \bottomrule
      \label{tab:3}
\end{tabularx}
\end{minipage}


\end{document}

If anyone can shed any light on this bizarre behaviour it would be most welcome.

1 Answer 1

6

use it this way:

\documentclass[a4paper,12pt]{report}
\usepackage[margin=10pt, labelfont=bf, format=hang, textfont={small,it}]{caption} % for more interesting captions
\captionsetup[subfigure]{style=default, margin=0pt, labelfont=bf, textfont={small,it}, singlelinecheck=true} % makes subfigure captions a bit more interesting.
\usepackage{ltablex} % Combines tabularx and longtable functionality
\usepackage{booktabs} % For professional looking tables

\begin{document}

Tables~\ref{tab:1}, %\ref{tab:2} and \ref{tab:3} are not numbered correctly.

\noindent
\begin{tabularx}{\textwidth}{X X X X X X X}
\caption{A table.}\label{tab:1}\\\toprule
\textbf{Number} & \multicolumn{6}{l}{\textbf{Number}} \\
\textbf{(samples)} & \textbf{0} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} \\ \hline
   1 & \textit{1} & -- & -- & -- & -- & --\\
   2 & \textit{2} & -- & -- & -- & -- & --\\
3--5 & \textit{3} & -- & -- & -- & -- & --\\
6--10 & \textit{4} & \textit{5} & -- & -- & -- & --\\
11--18 & \textit{6} & \textit{7} & \textit{8} & -- & -- & --\\\bottomrule
\end{tabularx}

\end{document}

package ltablex loads the longtable package which increases the table counter. However, you can use the \caption inside the tabular, then there is no need for a minipage and for \captionof

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .