与 subtable 和 threeparttable 一起使用时为表格放置标题

与 subtable 和 threeparttable 一起使用时为表格放置标题

threeparttable我正在创建一个有 2 个面板的表格。标题是针对整个表格的。我正在使用、caption和包subcaption。我的问题是,我应该将\caption整个表格的 latex 命令放在哪里?对于这个表格,最佳位置是什么?我在下面说明了两种方法。我认为每种方法都有不同的问题。

如果我使用第一种方法——我会看到与字符串“Table”计数器对应的文本与括号一起出现。我看到的是“Table (4)”,而我希望是“Table 4”。MWE 如下。有没有办法在与和一起使用时更改 caption 的属性threeparttablesubtable以便与不与它们一起使用时的 caption 格式一致?

如果我使用第二种方法,表格的计数器似乎会中断。所以我先查看表 1,然后查看表 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}

答案1

一些评论(无特定顺序):

  • 之所以放在\caption后面\begin{threeparttable},是为了确保标题的宽度与相关tabular材料的宽度相同。您的示例标题没有相关表格那么宽,掩盖了这一点。无论如何,如果您希望标题的宽度不比表格材料宽,则应将其放在 \begin{threeparttable}。主要来说,这是一个由您自行做出的风格选择。

  • 您使用了两个subtable环境,但似乎没有利用机器subtable。例如,没有通过\caption语句生成单独的标题。我会简化tabular材料。

  • @{\extracolsep{5pt}}我不会向每个环境都提供指令tabular,而是在序言中提供一个\addtolength\tabcolsep{2.5pt}指令。(列间空间很2\tabcolsep宽。)

经过这些调整后,两个表格的编号都符合预期。观察以下屏幕截图中的标题宽度:第一个表格的宽度限制为关联的宽度tabular,而第二个表格的宽度则不受限制。

在此处输入图片描述

\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}

附录:如果你想同时使用threeparttablesubtable环境,请注意每个threeparttable环境都需要放置里面a subtable. 以下代码说明了如何完成此操作。

\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} 

相关内容