Graphics, Figures & TablesIncorrect Table Numbering while using subtables

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
arbab cheema
Posts: 2
Joined: Wed May 22, 2019 4:08 am

Incorrect Table Numbering while using subtables

Post by arbab cheema »

I have some tables in my document which are composed of two subtables. The numbering becomes incorrect when these tables are added. For instance one table is numbered 4.24 but the next is numbered 4.26. The number 4.25 has been skipped. Is this error due to the fact that the table itself was composed of two subtables?

My code can be found below. Upon executing it, the first table is numbered 0.1 while the second table is numbered 0.3. Why the second table is not numbered 0.2?
\documentclass[12pt,a4paper,oneside,hidelinks]{scrbook}
\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage{fancyref}
\usepackage{hyperref}
\usepackage{lscape}
\usepackage{natbib}
\renewcommand*{\bibfont}{\raggedright}
\newcommand{\cchapter}[1]{\chapter[#1]{\centering #1}}
\usepackage{cite}
\setlength{\bibhang}{12pt}
\usepackage[nottoc]{tocbibind}
\setlength{\parskip}{0.5\baselineskip}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{subcaption}
\usepackage[font=small,skip=0pt]{caption}
\usepackage{array}
\usepackage{ragged2e}
\usepackage{xcolor}
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}
\captionsetup[table]{belowskip=0pt}
\captionsetup{font=normalsize,labelfont=bf,font=bf}
\usepackage{bm}
\usepackage{amsmath,amssymb}
\usepackage{chngcntr}
\counterwithout{equation}{chapter}
\usepackage{newtxtext,newtxmath}
\usepackage{setspace}

\begin{document}

\begin{table}[!htbp]
\centering
\caption{Announcements} \label{tab:distr}
\begin{subtable}[t]{\linewidth}
\rule[-2pt]{\textwidth}{0.5pt} \\
\justifying
\scriptsize
\noindent Description of variables is included here.

\noindent
\normalsize
\begin{tabularx}{1.0\linewidth}{>{\raggedright\arraybackslash}l >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}r}
\hline\hline
Weekday &          Count\\
\hline
Monday           &         136\\
Tuesday           &         480\\
Wednesday           &         290\\
Thursday           &         261\\
Friday           &         563\\
\hline
Total       &        1730\\
\hline\hline
\end{tabularx}
\subcaption{Panel A: Cumulative Distribution}
\end{subtable}
\begin{subtable}[t]{\linewidth}
\begin{tabularx}{1.0\linewidth}{>{\raggedright\arraybackslash}l >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}r}
 & & & & & & & & & & \\
\hline\hline
Weekday & A & B & C & D & E & F & G & H & I & Total\\
\hline
Monday & 92 & 0 & 71 & 1 & 0 & 0 & 0 & 1 & 0 & 164\\
Tuesday & 45 & 1 & 19 & 65 & 59 & 51 & 232 & 50 & 0 & 522\\
Wednesday & 35 & 0 & 17 & 94 & 38 & 77 & 2 & 51 & 14 & 328\\
Thursday & 33 & 7 & 37 & 6 & 59 & 47 & 5 & 73 & 21 & 288\\
Friday & 35 & 232 & 96 & 0 & 84 & 65 & 1 & 65 & 45 & 623\\
\hline
Total & 240 & 240 & 240 & 166 & 240 & 240 & 240 & 240 & 80 & 1926\\
\hline\hline
\end{tabularx}
\subcaption{Panel B: Individual Distribution}
\end{subtable}
\end{table}

\newpage
\begin{table}[!htbp]
\centering
\caption{Regressions} \label{tab:reg}
\begin{subtable}[t]{\linewidth}
\rule[-2pt]{\linewidth}{0.5pt} \\
\justifying
\scriptsize
\noindent Description of variables is included here.

\noindent
\normalsize
\begin{tabularx}{1.0\linewidth}{>{\raggedright\arraybackslash}l >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}r}
\hline\hline
            &   Mean&         Std. Dev&         Min&         Median&       Max& N\\
\hline
J &       0.13811&     0.14266&     0.00030&     0.08322&     0.92883&       11910\\
K &       0.12634&     0.13768&     0.00016&     0.07074&     0.92798&       11910\\
\hline
L &       0.12371&     0.14751&    -0.07714&     0.06475&     0.92866&       11910\\
M &       0.11913&     0.14021&    -0.03570&     0.06180&     0.92789&       11910\\
\hline
N &       0.49645&     0.69534&    -4.81374&     0.42740&     7.68042&       11910\\
O &       0.50296&     0.58914&    -4.06494&     0.43418&     4.58772&       11910\\
\hline
P &       0.05105&     0.54642&    -5.83177&     0.02309&     5.80889&       11910\\
Q &      0.06133&     0.40009&    -4.50850&     0.03513&     4.86864&       11910\\
\hline
R &       0.26164&     0.57158&    -5.12776&     0.21151&     5.79255&       11910\\
S &       0.27306&     0.49536&    -3.21627&     0.20411&     3.91303&       11910\\
\hline
U &       0.03693&     0.40521&    -4.39457&     0.02950&     5.82232&       11910\\
V &       0.05111&     0.28504&    -2.99187&     0.04154&     3.11172&       11910\\
\hline
X &       0.03782&     0.01885&     0.00309&     0.03383&     0.12898&       11910\\
Y &      0.03761&     0.01873&     0.00208&     0.03376&     0.12164&       11910\\
\hline\hline
\end{tabularx}
\subcaption{Panel A: Summary Statistics}
\end{subtable}
\begin{subtable}[t]{1.0\linewidth}
\centering
\begin{tabularx}{0.65\linewidth}{>{\raggedright\arraybackslash}l >{\raggedleft\arraybackslash}X >{\raggedleft\arraybackslash}r}
 & & \\
\hline\hline
v & t & p\\
\hline
a & 29.1060 &	0.0000\\
b & 11.1330 &	0.0000\\
c & -1.1215 &	0.2621\\
d &	-1.7339 &	0.0830\\
e &	-2.5628 &	0.0104\\
f & -3.2563 &	0.0011\\
g & 7.2860 &	0.0000\\
\hline\hline
\end{tabularx}
\subcaption{Panel B: t-tests}
\end{subtable}
\end{table}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Incorrect Table Numbering while using subtables

Post by Ijon Tichy »

If you are using \caption above the table, you should add class option captions=tableabove.

BTW: You should not use

Code: Select all

\setlength{\parskip}{0.5\baselineskip}
but class option parskip=half-. And you should not use package tocbibind but class options listof=totoc etc. And you should load hyperref after most other packages! And instead of you \cchapter I would recommend to redefine \raggedchapter to get centered chapters.

Here a more minimal example, that shows how it works:

Code: Select all

\documentclass[12pt,a4paper,oneside,hidelinks,
parskip=half-,% Do not use \setlength{\parskip}{0.5\baselineskip}
listof=totoc,% Do not use tocbibind
bibliography=totoc,% Do not use tocbibind
index=totoc,% Do not use tocbibind
captions=tableabove,% Needed if you use captions above tables or subtables would increase the table counter
]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage[font=bf,labelfont=bf]{caption}% If you load this after subcaption
                                % the options would be ignored.
\usepackage{subcaption}

\usepackage{hyperref}% Load hyperref as late as possible

\renewcommand*{\raggedchapter}{\centering}% Much better than \newcommand{\cchapter}[1]{\chapter[#1]{\centering #1}}
\captionsetup[subtable]{position=below,font=small}

\begin{document}
\chapter{Testchapter}
\begin{table}
  \centering
  \caption{Announcements} \label{tab:distr}
  \begin{subtable}[t]{\linewidth}
    \centering
    \begin{tabular}{lr}
      First & subtable
    \end{tabular}
    \caption{Panel A: Cumulative Distribution}
  \end{subtable}
  
  \bigskip
  \begin{subtable}[t]{\linewidth}
    \centering
    \begin{tabular}{lr}
      Second & subtable
    \end{tabular}
    \caption{Panel B: Individual Distribution}
  \end{subtable}
\end{table}

\begin{table}
  \centering
  \caption{Regressions} \label{tab:reg}
  \begin{subtable}[t]{\linewidth}
    \centering
    \begin{tabular}{lr}
      Third & subtable
    \end{tabular}
    \caption{Panel A: Summary Statistics}
  \end{subtable}

  \bigskip
  \begin{subtable}[t]{1.0\linewidth}
    \centering
    \begin{tabular}{lr}
      Forth & subtable
    \end{tabular}
    \caption{Panel B: t-tests}
  \end{subtable}
\end{table}

\end{document}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
arbab cheema
Posts: 2
Joined: Wed May 22, 2019 4:08 am

Incorrect Table Numbering while using subtables

Post by arbab cheema »

Hi Ijon Tichy

Thank you for such elaborate and valuable recommendations to rectify the code. I implemented all your suggestions and it worked flawlessly. Thanks again.
Post Reply