我正在尝试将表格下方的子标题文本的宽度与表格宽度对齐。我使用 \scalebox 和 \input 来调整表格的大小。但是,表格下方的文本比表格本身更宽,我不知道如何将文本与表格宽度对齐。您知道如何做到这一点吗?我总是收到警告消息“包标题警告:\subcaption 在框或环境之外”。
非常感谢您付出的时间和帮助!
\documentclass{article}
\usepackage{siunitx}
\usepackage{adjustbox,lipsum}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabulary}
\usepackage{multirow}
\usepackage{dcolumn}
\usepackage{tabularht}
\usepackage[font=footnotesize, labelfont=footnotesize, labelformat=empty, position=top]{subcaption}
\usepackage[font=small,skip=0pt]{caption}
\begin{document}
\begin{table}[h]
\centering{
\caption{Descriptive Statistics}
\vspace{0.1cm}
\label{tab:DesriptiveStatistics}
}
\begin{tabular}{lcccc}
\toprule
\textbf{Variables} & \textbf{N} & \textbf{Mean} & \textbf{Median} & \textbf{Std. Dev.} \\
\midrule
\textbf{Whole Sample} & & & & \\
\midrule
Profit & XXX & XXX & XXX & XXX \\
Sales & XXX & XXX & XXX & XXX \\
\textbf{A} & & & & \\
Profit & XXX & XXX & XXX & XXX \\
Sales & XXX & XXX & XXX & XXX \\
\bottomrule
\end{tabular}%
\vspace{0.1cm}
\subcaption{This table shows the descriptive statistics for the whole sample as well as for the different sub-samples.}
\end{table}
\end{document}
答案1
这是一个类似的答案唯一的那个@Bernard 发布了这篇文章,其中采用了三部分表包裹。
一个threeparttable
环境具有(最多)三个正式组件:一个\caption
、一个tabular
环境(一个tabularx
、tabulary
或tabular*
环境也可以)及其任意关联的自由浮动文本(如果有)以及一个tablenotes
环境(提供与\tnote
放置在环境内的任何指令相关联的脚注文本tabular
)。
该环境的特殊之处threeparttable
在于,它会自动将标题、材料tablenotes
和任何“自由浮动”文本的宽度限制为环境的宽度tabular
。
哦,不要过度大胆的标题单元格的内容。设计良好的表格通常根本不需要这样的视觉刺激。
\documentclass{article}
%% I've stripped down the preamble to the bare minimum
%\usepackage[utf8]{inputenc} %% that's the default nowadays
\usepackage[T1]{fontenc} % optional
\usepackage{booktabs}
\usepackage[skip=0.333\baselineskip]{caption}
\usepackage[flushleft]{threeparttable} % <-- new
\begin{document}
\begin{table}[h]
\centering
\begin{threeparttable}
\caption{Descriptive Statistics}
\label{tab:DesriptiveStatistics}
\begin{tabular}{@{} l cccc @{}}
\toprule
Variables & $N$ & Mean & Median & St.\ Dev. \\
\midrule
\multicolumn{5}{@{}l}{Whole Sample} \\
Profit & XXX & XXX & XXX & XXX \\
Sales & XXX & XXX & XXX & XXX \\
\addlinespace
\multicolumn{5}{@{}l}{Subsample A} \\
Profit & XXX & XXX & XXX & XXX \\
Sales & XXX & XXX & XXX & XXX \\
\bottomrule
\end{tabular}
\smallskip\small % or "\footnotesize"
This table shows the descriptive statistics for the whole sample as well as for various subsamples.
\end{threeparttable}
\end{table}
\end{document}
答案2
标准方式使用threeparttable
环境,测量表格注释的表格宽度:
\documentclass{article}
\usepackage{siunitx}
\usepackage{adjustbox,lipsum}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabulary}
\usepackage{multirow}
\usepackage{dcolumn}
\usepackage{tabularht}
\usepackage[font=footnotesize, labelfont=footnotesize, labelformat=empty, position=top]{subcaption}
\usepackage[font=small,skip=0pt]{caption}
\usepackage[flushleft]{threeparttable}
\begin{document}
\begin{table}[h]
\begin{threeparttable}
\centering\captionsetup{skip=1ex}%{
\caption{Descriptive Statistics}
\label{tab:DesriptiveStatistics}
%
\begin{tabular}{lcccc}
\toprule
\textbf{Variables} & \textbf{N} & \textbf{Mean} & \textbf{Median} & \textbf{Std. Dev.} \\
\midrule
\textbf{Whole Sample} & & & & \\
\midrule
Profit & XXX & XXX & XXX & XXX \\
Sales & XXX & XXX & XXX & XXX \\
\textbf{A} & & & & \\
Profit & XXX & XXX & XXX & XXX \\
Sales & XXX & XXX & XXX & XXX \\
\bottomrule
\end{tabular}%
\vspace{0.1cm}
\begin{tablenotes}
\item[]\hskip -0.4em This table shows the descriptive statistics for the whole sample as well as for the different sub-samples.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案3
像这样吗?
由于您没有提供表格内容,我假设数字有三位数,如上图所示。实际数字需要您自己写。如果数字更多,则需要S
相应地更正列规范。
对于表格,使用talltblr
,tabularray
相当于threeparttable
。它允许将标题和表格注释或备注作为表格的一部分写入,其宽度等于表格宽度。在 MWE 中使用tabularray
包版本 2022C:
\documentclass{article}
\usepackage{lipsum}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\usepackage[skip=1ex, font=small]{caption}
\usepackage[font=footnotesize, labelformat=empty, position=top]{subcaption}
\begin{document}
\begin{table}[h]
\centering
\begin{talltblr}[
caption = {Descriptive Statistics},
label = {tab:DesriptiveStatistics},
note{} = {This table shows the descriptive statistics for the whole sample as well as for the different sub-samples.}
]{colspec={l
Q[c, si={table-format={3.0}}]
*{3}{Q[c, si={table-format={1.2}}]}},
row{1,2}={font=\bfseries, guard},
}
\toprule
Variables & N & Mean & Median& Std. Dev. \\
\midrule
\SetCell[c=5]{l, font=\bfseries} Whole Sample
& & & & \\
text & 123 & 1.23 & 1.23 & 1.23 \\
text & 123 & 1.23 & 1.23 & 1.23 \\
\SetCell[c=5]{l, font=\bfseries} A
& & & & \\
text & 123 & 1.23 & 1.23 & 1.23 \\
text & 123 & 1.23 & 1.23 & 1.23 \\
\bottomrule
\end{talltblr}
\end{table}
\end{document}