1

When using the above packages it seems that table counter is ignoring the subtables when labelling the subsequent table. Here is a MWE:

\documentclass[a4paper,oneside,12pt]{book}
\usepackage{standalone}
\usepackage{amsmath, subfig}
\usepackage{booktabs, makecell, multirow}
\usepackage[colorlinks=true, allcolors=black]{hyperref}
\usepackage{cleveref}
\usepackage[font = footnotesize]{caption}

\begin{document}
\section{First}
\begin{table}[!h]
    \label{4tbl:2}
    \centering\begingroup\fontsize{8}{10}\selectfont
    \subfloat[Stuff 2 \label{4tbl:1a}]{
        \begin{tabular}[t]{>{}l>{}l>{}l>{}l>{}l>{}ll}
            \toprule
            \multicolumn{1}{c}{\bgroup\fontsize{10}{12}\selectfont \egroup{}} & \multicolumn{6}{c}{\bgroup\fontsize{10}{12}\selectfont Stuff table 1\egroup{}} \\
            \cmidrule(l{3pt}r{3pt}){1-1} \cmidrule(l{3pt}r{3pt}){2-7}
            & v & w & f & h & $\mu_0$ & $w_0$\\
            \midrule
            2 & 1 & 1 & 0.75 & 1 & 0 & 1\\
            3 & 0.5 & 3 & 0.5 & 1 & 1 & 1\\
            \bottomrule
        \end{tabular}
    }
    \qquad
    \subfloat[Stuff 1\label{4tbl:1b}] {
        \begin{tabular}[t]{>{}l>{}l>{}l>{}l>{}l>{}ll}
            \toprule
            \multicolumn{1}{c}{\bgroup\fontsize{10}{12}\selectfont \egroup{}} & \multicolumn{6}{c}{\bgroup\fontsize{10}{12}\selectfont Stuff Table 2\egroup{}} \\
            \cmidrule(l{3pt}r{3pt}){1-1} \cmidrule(l{3pt}r{3pt}){2-7}
            & v & w & f & h & $\mu_0$ & $w_0$\\
            \midrule
            2 & 1 & 1 & 0.95 & 1 & 0 & 1\\
            3 & 0.5 & 1 & 0.75 & 1.5 & 1 & 1\\
            \bottomrule
        \end{tabular}
    }
    \endgroup{}
\end{table}

This is ref to \Cref{4tbl:1a} and this to \Cref{4tbl:1b}.

\begin{table}[!h]
    \centering\begingroup\fontsize{8}{10}\selectfont
    \begin{tabular}[t]{>{}l>{}l>{}l>{}l>{}l>{}ll}
        \toprule
        \multicolumn{1}{c}{\bgroup\fontsize{10}{12}\selectfont  \egroup{}} & \multicolumn{6}{c}{\bgroup\fontsize{10}{12}\selectfont 
        More Stuff \egroup{}} \\
        \cmidrule(l{3pt}r{3pt}){2-7}
        Exp & V & W & F & H & $\mu_0$ & $W_0$\\
        \midrule
        1 & 1 & 1 & 0.5 & 1 & 1 & 1\\
        2 & 1 & 1 & 0.95 & 1 & 0 & 1\\
        3 & 0.5 & 1 & 0.75 & 1.5 & 1 & 1\\
        4 & 1 & 3 & 0.5 & 1.5 & 1 & 1\\
        5 & 0.75 & 5 & 0.15 & 1 & 1 & 1\\
        \bottomrule
    \end{tabular}
    \caption{Parameter values for several Kalman filters.}
    \label{4tbl:3}
    \endgroup{}
\end{table}

This is ref to \Cref{4tbl:3}.

\end{document}

The second table should read Table 2.

3
  • 1
    It will work correctly as soon as you use \caption in the first table environment (before \label). Mar 22, 2023 at 13:24
  • Ok. I added a blank caption to the table environment before the table label which added "Table 1.1" to it (which I didn't want) but the numbering is correct.
    – Fatm
    Mar 22, 2023 at 16:21
  • You can use \refstepcounter{table} instead of an unwanted caption. See also \capstart from the hypcap package. Mar 22, 2023 at 17:26

1 Answer 1

0

See, if this works as you like to achieve:

\documentclass[a4paper,oneside,12pt]{book}
\usepackage{booktabs, makecell, multirow}
\usepackage[font = footnotesize]{caption}
\usepackage{subcaption}
\usepackage{siunitx}

\usepackage[colorlinks=true, 
            allcolors=black]{hyperref}
\usepackage{cleveref}   % had to be last in preamble

\begin{document}
\chapter{FIRST}

\section{First}
    \begin{table}[!h]
    \centering
    \small
\subfloat[Stuff 2   \label{4tbl:1a}]{%
    \begin{tabular}[t]{>{} c S[table-format=1.1] c
                             S[table-format=1.2] ccc @{}}
    \toprule
    &   \multicolumn{6}{c}{Stuff table 1}   \\
    \cmidrule(l{3pt}r{3pt}){1-1} 
    \cmidrule(l{3pt}r{3pt}){2-7}
    & {v}   & w & {f}   & h & $\mu_0$   & $w_0$\\
    \midrule
2   & 1     & 1 & 0.75  & 1 & 0         & 1 \\
3   & 0.5   & 3 & 0.5   & 1 & 1         & 1 \\
    \bottomrule
    \end{tabular}          }
\hfil
\subfloat[Stuff 1   \label{4tbl:1b}] {
    \begin{tabular}[t]{>{} c S[table-format=1.1] c
                             S[table-format=1.2]
                             S[table-format=1.1]    cc @{}}
    \toprule
    &   \multicolumn{6}{c}{Stuff Table 2}   \\
    \cmidrule(l{3pt}r{3pt}){1-1} 
    \cmidrule(l{3pt}r{3pt}){2-7}
    & {v}   & w & {f}   & {h}   & $\mu_0$   & $w_0$ \\
    \midrule
2   & 1     & 1 & 0.95 & 1      & 0         & 1     \\
3   & 0.5   & 1 & 0.75 & 1.5    & 1         & 1     \\
            \bottomrule
    \end{tabular}          }
%\caption[]{}    % <--- had to be used. Why you omit it?
\label{4tbl:2}
    \end{table}

This is ref to \Cref{4tbl:1a} and this to \Cref{4tbl:1b}.

    \begin{table}[!h]
    \centering%\begingroup
    \small
    \begin{tabular}[t]{>{} c S[table-format=1.1] c
                             S[table-format=1.2]
                             S[table-format=1.1]    cc @{}}
    \toprule
    & \multicolumn{6}{c}{More Stuff}    \\
    \cmidrule(l{3pt}r{3pt}){2-7}
Exp &{ V}   & W & {F}   & {H}   & $\mu_0$   & $W_0$\\
    \midrule
1   & 1     & 1 & 0.5   & 1     & 1         & 1\\
2   & 1     & 1 & 0.95  & 1     & 0         & 1\\
3   & 0.5   & 1 & 0.75  & 1.5   & 1         & 1\\
4   & 1     & 3 & 0.5   & 1.5   & 1         & 1\\
5   & 0.75  & 5 & 0.15  & 1     & 1         & 1\\
    \bottomrule
\end{tabular}
    \caption{Parameter values for several Kalman filters.}
    \label{4tbl:3}
\end{table}

This is ref to \Cref{4tbl:3}.

\end{document}

Main differences to your document example are:

  • instead of subfi is used subcaption package, which better works with \hyperref package
  • label at first table is moved to end of table (after subfloats
  • for columns with decimal numbers are used S column type defined in the siunitx package.
  • removed are all strange font settings for your table -however, i wonder, why you not use caption for the first table I should be inserted before label . As is MWE now, it works by accident since first table is immediately afters section and reference consider ˛section˛counter, not table

enter image description here

Is this what you after?

1
  • Ok Thanks. I didn't know that I MUST add caption. Adding this solved it as per the comment but thanks for the additional help with siunitx
    – Fatm
    Mar 22, 2023 at 16:25

You must log in to answer this question.

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