3

I have a 2 part table that I wish to label as "a" and "b", that also includes the section number and the table number within the section (e.g., "Table 4.1a" and Table "4.1b").

I use the basic approach to produce a caption which includes the section number (the \counterwithin{table}{section} command). However, when I try to integrate a subcaption, I can only produce "Table 1a" and "Table 1b", which does not include the section number.

\documentclass{article}
\setcounter{totalnumber}{4}

\begin{document}

\begin{table}
\renewcommand{\thetable}{\arabic{table}a}
\caption{First caption}\label{first}
\end{table}

\begin{table}
\addtocounter{table}{-1}
\renewcommand{\thetable}{\arabic{table}b}
\caption{Second caption}\label{second}
\end{table}

\end{document}

How can I integrate the \counterwithin{table}{section} command so that section numbers are also included?

Thanks

1 Answer 1

3
\documentclass{article}

\newcounter{mysubtable}
\newcommand\modcounter{%
  \refstepcounter{mysubtable}%
  \renewcommand{\thetable}{\thesection.\arabic{table}\alph{mysubtable}}%
}

\begin{document}

\section{Test}
Some cross-references to tables~\ref{first} and~\ref{second}.

\begin{table}
\modcounter
\caption{First caption}
\label{first}
\end{table}

\begin{table}
\addtocounter{table}{-1}
\modcounter
\caption{Second caption}
\label{second}
\end{table}

\end{document}

The result:

enter image description here

Remarks

  • A new counter mysubtable was defined.

  • A helping command \modcounter was also defined to (ref)step the mysubtable counter and to redefine \thetable to preppend the section counter.

  • To restart the counter, add

    \setcounter{mysubtable}{0}
    

    at the appropriate location.

4
  • Works great, but unfortunately does not "reset with a new table number; continues at the next letter. For example, Table 1.1a and Table 1.1b will be followed by Table1.2c and Table 1.2d
    – Dan
    Commented Jun 27, 2015 at 16:08
  • Update: By redefining the command before each table, you can get the letters to restart at a: e.g., \newcounter{mysubtable2} \renewcommand\modcounter{% \refstepcounter{mysubtable2}% \renewcommand{\thetable}{\thesection.\arabic{table}\alph{mysubtable2}}% }
    – Dan
    Commented Jun 27, 2015 at 16:27
  • @Dan This can be done in a simpler way. When I get home I'll update my answer. Commented Jun 27, 2015 at 17:48
  • Can this be modified to work for figures?
    – Dan
    Commented Dec 16, 2015 at 16:18

You must log in to answer this question.

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