我有一张小表格,我想将其放在文档的中央。我可以这样做,但标题会左对齐,而不是与居中表格对齐。我想将表格置于中央,并使标题与居中表格对齐。我该如何实现?
最小示例(我留下了一些包装信息以防有用):
\documentclass{scrartcl}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage{scrextend}
\usepackage[style=apa, backend=biber]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
\usepackage{amsmath}
\usepackage[sc]{mathpazo}
\usepackage{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\usepackage{url}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,
breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
{hyperref}
\hypersetup{pdfstartview={XYZ null null 1}}
\usepackage{enumerate}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[justification=justified,singlelinecheck=false]{caption}
\usepackage{hyperref}
\usepackage{here}
\newenvironment{my_enumerate}{
\begin{enumerate}
\setlength{\itemsep}{1pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}}{\end{enumerate}
}
\begin{document}
\begin{table}[ht]
\centering
\caption{Descriptive Statistics. \label{desc}}
\begin{tabular}{lccccc}
\toprule
& & \multicolumn{2}{c}{pre} & \multicolumn{2}{c}{post} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}
approach & n & mean & sd & mean & sd \\
\midrule
1 & $12$ & $24.2$ & $\phantom{0}8.3$ & $54.3$ & $11.0$ \\
2 & $12$ & $25.5$ & $\phantom{0}9.4$ & $65.2$ & $16.3$ \\
3 & $12$ & $26.3$ & $\phantom{0}9.1$ & $63.2$ & $12.5$ \\
All & $36$ & $25.3$ & $\phantom{0}8.8$ & $60.9$ & $13.9$ \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
注意!River Valey 网站上的 TABLE 包链接已失效。我在其他地方没有找到 TABLE 包。它不在 CTAN 上。
- 包含一个景观表作为浮动表。
- 将标题的格式精确设置为表格的宽度。
- 一些其他的钩子会在表格的水平规则周围添加一些额外的垂直空间。
\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{txfonts,array}
\usepackage[debug]{Table}
\begin{document}
\TABLE{\label{desc} Descriptive Statistics over a Mean Approach to sd and a, descriping both post and pre}
{\begin{tabular}{lccccc}
\toprule
& & \multicolumn{2}{c}{pre} & \multicolumn{2}{c}{post} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}
approach & n & mean & sd & mean & sd \\
\midrule
1 & $12$ & $24.2$ & $\phantom{0}8.3$ & $54.3$ & $11.0$ \\
2 & $12$ & $25.5$ & $\phantom{0}9.4$ & $65.2$ & $16.3$ \\
3 & $12$ & $26.3$ & $\phantom{0}9.1$ & $63.2$ & $12.5$ \\\midrule
All & $36$ & $25.3$ & $\phantom{0}8.8$ & $60.9$ & $13.9$ \\
\bottomrule
\end{tabular}
}
\end{document}
而且它似乎会自动将表格置于页面中央。
答案2
无论如何使用该caption
包时,都可以使用该包提供的命令\captionbox
(至少从 3.2 版开始):
\documentclass[captions=tableheading]{scrartcl}
\usepackage[american]{babel}
\usepackage{enumerate}
\usepackage{booktabs}
\usepackage[justification=justified,singlelinecheck=false]{caption}
\begin{document}
\begin{table}[ht]
\centering
\captionbox{Descriptive Statistics. \label{desc}}{%
\begin{tabular}{lccccc}
\toprule
& & \multicolumn{2}{c}{pre} & \multicolumn{2}{c}{post} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}
approach & n & mean & sd & mean & sd \\
\midrule
1 & $12$ & $24.2$ & $\phantom{0}8.3$ & $54.3$ & $11.0$ \\
2 & $12$ & $25.5$ & $\phantom{0}9.4$ & $65.2$ & $16.3$ \\
3 & $12$ & $26.3$ & $\phantom{0}9.1$ & $63.2$ & $12.5$ \\
All & $36$ & $25.3$ & $\phantom{0}8.8$ & $60.9$ & $13.9$ \\
\bottomrule
\end{tabular}}
\end{table}
\end{document}
答案3
如果你的目的是将标题排版为两端对齐,并调整其宽度以适应内容的宽度tabular
,你可以加载floatrow
包(无需添加\centering
)并将tabular
环境和标题放在里面\ttabbox
。
\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage[justification=justified,singlelinecheck=false]{caption}
\usepackage{floatrow}
\begin{document}
\begin{table}[ht]
\ttabbox{%
\caption{Descriptive Statistics. \label{desc}}%
}{%
\begin{tabular}{lccccc}
\toprule
& & \multicolumn{2}{c}{pre} & \multicolumn{2}{c}{post} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}
approach & n & mean & sd & mean & sd \\
\midrule
1 & $12$ & $24.2$ & $\phantom{0}8.3$ & $54.3$ & $11.0$ \\
2 & $12$ & $25.5$ & $\phantom{0}9.4$ & $65.2$ & $16.3$ \\
3 & $12$ & $26.3$ & $\phantom{0}9.1$ & $63.2$ & $12.5$ \\
All & $36$ & $25.3$ & $\phantom{0}8.8$ & $60.9$ & $13.9$ \\
\bottomrule
\end{tabular}
}
\end{table}
\end{document}