2

I am creating a table with 2 panels. The caption is for the entire table. And I am using the packages threeparttable, caption and subcaption. The question I have is, where do I place the latex \caption command for the entire table? What is the best position given this table? I illustrate two ways below. I think each of them have different issues.

If I use the first method -- I see the text corresponding to the string "Table" counter appear with the parenthesis. I see as "Table (4)" while I was hoping for "Table 4". The MWE is below. Is there a way to change the properties of caption when used along with threeparttable and subtable, so that it is consistent with the caption format when used with out them?

If I use the second method, the counter for the Table seems to be breaking. So I see Table 1 and then Table 3.

\documentclass[12pt]{article}
\usepackage{rotating}
\usepackage{longtable}
\usepackage{float}
\usepackage{pdflscape}
\usepackage[flushleft]{threeparttable}

\usepackage[font=footnotesize,format=plain,
    labelfont=sc,up,textfont=up,
    tableposition=top,figureposition=top]{caption}
\usepackage{subcaption}
\captionsetup{
    format = plain,
    labelfont = sc
}
\usepackage{tabularx} % for better tables
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{dcolumn}

\begin{document}

%%%%%TABLE 1: \caption after \begin{threeparttable}
      \begin{table}
      \centering
   \begin{threeparttable}
   \caption{This table shows the details}

  \begin{subtable}[t]{\linewidth}
    \centering
    \vspace{0pt}
    \begin{tabular}{@{\extracolsep{5pt}} lccc}
      \toprule
      Panel A & & & \\
      Year & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
    \end{tabular}
  \end{subtable}


  \begin{subtable}[t]{\linewidth}
    \centering
    \begin{tabular}{@{\extracolsep{5pt}} lccc}
      \toprule
      Panel B & & & \\
      Year & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
      \bottomrule
    \end{tabular}
  \end{subtable}
\end{threeparttable}
\end{table}

%%%%% TABLE 2: \caption between begin{table} and begin{threeparttable}
\begin{table}

  \caption{This table shows the details}    \centering
   \begin{threeparttable}
  \begin{subtable}[t]{\linewidth}
    \centering
    \vspace{0pt}
    \begin{tabular}{@{\extracolsep{5pt}} lccc}
      \toprule
      Panel A & & & \\
      Year & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
    \end{tabular}
  \end{subtable}


  \begin{subtable}[t]{\linewidth}
    \centering
    \begin{tabular}{@{\extracolsep{5pt}} lccc}
      \toprule
      Panel B & & & \\
      Year & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
      \bottomrule
     \end{tabular}
     \end{subtable}
    \end{threeparttable}
    \end{table}
   \end{document}
2
  • Aside: You use subtable environments, but you don't appear to make use of a key feature of these environments, viz., the ability to assign captions that can be cross-referenced via LaTeX's \label-\ref system. Is this deliberate?
    – Mico
    Commented Oct 18, 2016 at 2:22
  • @Mico Yes - the caption is for the entire table. The reason I use subtable is for the two panels -- although I realize I can use labels for cross reference. So the table consists two panels - and the caption is for the entire table, and the subtable I don't have any any caption.
    – rajvijay
    Commented Oct 18, 2016 at 2:38

1 Answer 1

3

Some comments, in no particular order:

  • The reason for putting \caption after \begin{threeparttable} is to assure that the width of the caption is the same as that of the associated tabular material. Your sample captions aren't as wide as the associated tabulars, obscuring this aspect. At any rate, if you want the width of the caption to be no wider than the tabular material, you should place it after \begin{threeparttable}. Mainly, it's a stylistic choice that's up to you to make.

  • You use two subtable environments but don't appear to make use of the subtable machinery. E.g., no separate captions generated via \caption statements. I would simplify the tabular material.

  • Instead of providing the directive @{\extracolsep{5pt}} to each and every tabular environment, I would provide a single \addtolength\tabcolsep{2.5pt} directive in the preamble. (Inter-column spaces are 2\tabcolsep wide.)

With these adjustments in place, the numbering of both tables is as one would expect it to be. Observe the widths of the captions in the following screenshot: the first is constrained to the width of the associated tabular, whereas the second is not.

enter image description here

\documentclass[12pt]{article}
\usepackage[flushleft]{threeparttable}
\usepackage[size=footnotesize,  % are you sure you want this?
    format=plain,labelfont=sc,
    skip=0.5\baselineskip,
    tableposition=top,figureposition=top]{caption}
\usepackage{tabularx}
\usepackage{booktabs}
\addtolength{\tabcolsep}{2.5pt} % centralize this instruction
\begin{document}

%%%%%TABLE 1: \caption after \begin{threeparttable}
\begin{table}[t]
\centering
\begin{threeparttable}
   \caption{This caption is very very very very long}

   \begin{tabular}{@{} lccc@{}}
      \toprule
      Panel A & & & \\
      Year & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
      \bottomrule
      \addlinespace
      Panel B & & & \\
      Year & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
      \bottomrule
   \end{tabular}
\end{threeparttable}
\end{table}

%%%%% TABLE 2: \caption before begin{threeparttable}
\begin{table}[h]
  \caption{This caption is also so very very very very long}    
  \centering

  \begin{threeparttable}
  \begin{tabular}{@{} lccc@{}}
      \toprule
      Panel A & & & \\
      Year   & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
      \bottomrule
      \addlinespace
      Panel B & & & \\
      Year   & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
      \bottomrule
  \end{tabular}
  \end{threeparttable}
\end{table}
\end{document}

Addendum: If you want to use both threeparttable and subtable environments, note that each threeparttable environment needs to be placed inside a subtable. The following code illustrates how this may be done.

\documentclass[12pt]{article}
\usepackage[flushleft]{threeparttable}
\usepackage{subcaption}
\captionsetup{size=footnotesize, 
    format=plain,labelfont=sc, skip=0.5\baselineskip,
    tableposition=top,figureposition=top}
\usepackage{booktabs}
\addtolength{\tabcolsep}{2.5pt} % global-scope instruction
\begin{document}

\begin{table}[t]
\centering
   % first, the overall table caption
   \caption{This caption is very very very very long} 
   \label{tab:longcap}


   \begin{subtable}{\textwidth}
   \centering
   \begin{threeparttable}
   % a caption for the first subtable
   \caption{Panel A, with a very very very long trailer} \label{tab:subA}
   \begin{tabular}{@{} lccc@{}}
      \toprule
      Year & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
      \bottomrule
   \end{tabular}
   \end{threeparttable}
   \end{subtable}

   \bigskip
   \begin{subtable}{\textwidth}
   \centering
   % a caption for the second subtable
   \begin{threeparttable}
   \caption{Panel B, also with a very very very long trailer} \label{tab:subB}
   \begin{tabular}{@{} lccc@{}}
      \toprule
      Year & $2002$ & $2003$ & $2004$ \\
      \midrule
      model1 & $1.703$ & $1.339$ & $1.238$  \\
      model2 & $2.104$ & $1.920$ & $1.774$  \\
      \bottomrule
   \end{tabular}
   \end{threeparttable}
   \end{subtable}
\end{table}

Cross-references to table \ref{tab:longcap}, table \ref{tab:subA}, and table \ref{tab:subB}.
\end{document} 
2
  • That works great!!! I have the table in my required format. So if no cross referencing, subtable is not needed as in my case. But let us say if I have to include \ref and cross refer. In that case, how could subtable be incorporated in the above, but then it preserves the numbering? Or is it a bug?
    – rajvijay
    Commented Oct 18, 2016 at 13:03
  • @rajvijay -If you want to use the threeparttable package along with subtable environments, you should set up threeparttable environments inside the subtables. I'll post an addendum to show how this should be done.
    – Mico
    Commented Oct 18, 2016 at 13:58

You must log in to answer this question.

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