GeneralHelp on \subtable

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
chandangiri
Posts: 20
Joined: Thu Sep 06, 2007 7:31 pm

Help on \subtable

Post by chandangiri »

Hi.. I am using \subtable in document..and set the label appropriately. But When I am refering that subtable using \ref{label of subtable } and after compilation the table number is showing one less than the actual table number.. Can u be plz help regarding that?

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Help on \subtable

Post by localghost »

You have to post more information. It would be good to have the code that generates the (sub)table and the related references. The best way is to provide a minimal working example (MWE) to understand what's going wrong.
chandangiri
Posts: 20
Joined: Thu Sep 06, 2007 7:31 pm

Re: Help on \subtable

Post by chandangiri »

\documentclass[a4paper]{article}
\usepackage{subfigure}

\begin{document}
\section{Section title}

\begin{table}[h!]
\centering
\subtable[]{
\tiny
\centering
\begin{tabular}{|c|c|c|}\hline
a&b&c\\
d&e&f\\\hline
\end{tabular}
\label{tab:chapter4:1a}
}
\subtable[]{
\tiny
\centering
\begin{tabular}{|c|c|c|}\hline
g&h&i\\
j&k&l\\\hline
\end{tabular}
\label{tab:chapter4:1b}
}
\subtable[]{
\tiny
\centering
\begin{tabular}{|c|c|c|}\hline
m&n&o\\
p&q&r\\\hline
\end{tabular}
\label{tab:chapter4:1c}
}
\caption{Testing}
\label{tab:chapter4:1}
\end{table}

Here the tables are Table \ref{tab:chapter4:1}, \ref{tab:chapter4:1a}, \ref{tab:chapter4:1b} and \ref{tab:chapter4:1c}.
\end{document}

This is the example I have tried.. It is not giving correctly the subtable numbers. It is showing one less than the actual number.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Help on \subtable

Post by localghost »

At first, let me remark that the subfigure package is obsolete and should be replaced by the subfig package, which is also more consistent with the caption package. As far is I remember, the labels for the subtables have to be put into the optional arguments for their captions. There are two possible solutions.
  1. The simple one is to replace the \ref command for the subtables by the \subref command. For total reference you can use a combination of both.

    Code: Select all

    Here the tables is Table~\ref{tab:chapter4:1} with its subtables \subref{tab:chapter4:1a}, \subref{tab:chapter4:1b} and \subref{tab:chapter4:1c}. The Table~\ref{tab:chapter4:1}\subref{tab:chapter4:1a} is a subtable of Table~\ref{tab:chapter4:1}
  2. The better one is to change to the subfig package and modify the code. The changes are only marginal, so the code looks like the one you provided.

    Code: Select all

    \documentclass[12pt,BCOR13mm,DIV15]{scrartcl}  % KOMA Script article class
    \usepackage[T1]{fontenc}
    \usepackage[latin1]{inputenc}
    \usepackage[english]{babel}
    \usepackage[font=small,labelfont=bf]{caption}
    \usepackage[font=footnotesize]{subfig}
    
    \setlength{\parindent}{0pt}
    
    \begin{document}
    \section{Section title}
    
    \begin{table}[!ht]
      \centering
      \subfloat[First Subtable\label{tab:chapter4:1a}]{
        \tiny
        \centering
        \begin{tabular}{|c|c|c|}\hline
          a&b&c\\
          d&e&f\\\hline
        \end{tabular}
      }
      \subfloat[Second Subtable\label{tab:chapter4:1b}]{
        \tiny
        \centering
        \begin{tabular}{|c|c|c|}\hline
          g&h&i\\
          j&k&l\\\hline
        \end{tabular}
      }
      \subfloat[Third Subtable\label{tab:chapter4:1c}]{
        \tiny
        \centering
        \begin{tabular}{|c|c|c|}\hline
          m&n&o\\
          p&q&r\\\hline
        \end{tabular}
      }
      \caption{Testing}\label{tab:chapter4:1}
    \end{table}
    
    Here the tables are Table~\ref{tab:chapter4:1}, \ref{tab:chapter4:1a}, \ref{tab:chapter4:1b} and \ref{tab:chapter4:1c}. The Table~\ref{tab:chapter4:1}\subref{tab:chapter4:1a} is a subtable of Table~\ref{tab:chapter4:1}. Table~\ref{tab:chapter4:1} has also the two other subtables \ref{tab:chapter4:1}\subref*{tab:chapter4:1b} and \ref{tab:chapter4:1}\subref{tab:chapter4:1c}
    \end{document}
You can see how the subtables are referenced and test what's matching your ideas. For more information about labelling and referencing the subfloats please refer to the documentation of the subfig package.
chandangiri
Posts: 20
Joined: Thu Sep 06, 2007 7:31 pm

Re: Help on \subtable

Post by chandangiri »

It is working fine.. but will it also work for subfigures?
chandangiri
Posts: 20
Joined: Thu Sep 06, 2007 7:31 pm

Re: Help on \subtable

Post by chandangiri »

If the tables are large table (i.e not fit within the page width) then also tables are put side by side. So how the tables can be put one after another automatically in this case. If the Tables are small then again it sholud be fitted within one row.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Help on \subtable

Post by localghost »

chandangiri wrote: It is working fine.. but will it also work for subfigures?

Now let me think … hm … Of course it works with figures! What did you think? I already recommended to take look at the documentation. That's what these papers are made for. (Sorry if I hit the wrong note.)
chandangiri wrote: If the tables are large table (i.e not fit within the page width) then also tables are put side by side. So how the tables can be put one after another automatically in this case. If the Tables are small then again it should be fitted within one row.

I guess you are meaning that only one single table fits the linewidth. You can add a line break command to force the right placement.

Code: Select all

\begin{table}[!ht]
  \centering
  \subfloat[First Subfloat\label{subtab-1:table}{
    …
  }\\                                                %<<<< here is the line break
  \subfloat[Second Subfloat\label{subtab-2:table}{
    …
  }
  \caption{Table}\label{tab:table}
\end{table}
Post Reply