答案1
以下是我的做法。需要进行一些调整,但希望这能为您指明正确的方向。我建议您查看一些我使用过的软件包。它们可能具有一些有用的功能,可以生成您似乎想要生成的某些类型的表格。
\documentclass{article}
\usepackage{booktabs} % Adds table formatting options
\usepackage{dcolumn} % Adds option to align data around the decimal point
\newcolumntype{d}{D{.}{.}{-1}} % Use 'd' to align column on decimal place
\usepackage[labelfont={bf},singlelinecheck={off}]{caption} % Formats captions on images, tables, etc.
\newcommand{\cc}[1]{\multicolumn{1}{c}{#1}} % centralise table cell
\begin{document}
\begin{table}[tp]
\centering
\caption{caption text goes here}
\label{tbl:crossref-label}
\begin{tabular}{l d d @{\extracolsep{6pt}} d d l}
\toprule
& \multicolumn{2}{c}{multicolumn title} & \multicolumn{3}{c}{multicolumn title} \\
\cmidrule{2-3} \cmidrule{4-6}
& \cc{Mean} & \cc{SD} & \cc{Mean} & \cc{SD} & \cc{$p$} \\
\midrule
text &&&&& \\
more text & 12.34 & 1.234 & 1.23 & 1.234 & ** \\
more text & 1.23 & 1.2345 & 12.3 & 1.23 & ** \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
以下是有关如何自定义问题中所示的表格的一些提示:
\captionsetup{justification=centering, labelfont=bf, labelsep=quad}
自定义标题,如上所示。- 均衡列宽的最佳方法是
\newcolumntype{C}{ >{ \arraybackslash \Centering } X }
在序言中使用新列类型定义新列C
类型。或者,您可以使用新列类型,\newcolumntype{R}{ >{ \arraybackslash \RaggedLeft } X }
其中R
条目向右对齐。许多出版物都使用这种格式作为第一列。 \cmidrule(lr){col}
允许从左到右进行修剪裁定\colorbox{LightBlue}{text}
以上面显示的颜色突出显示
整体代码为:
\documentclass{report}
% Text justification package
\usepackage{ragged2e}
% Table packages
\usepackage{booktabs}
\usepackage{tabularx}
% New column types
\newcolumntype{C}{ >{ \arraybackslash \Centering } X } % centered
\newcolumntype{L}{ >{ \arraybackslash \RaggedRight } X } % left justified
\newcolumntype{R}{ >{ \arraybackslash \RaggedLeft } X } % right justified
\newcolumntype{S}[1]{ >{ \arraybackslash \Centering } m{#1} } % centered with specified width
% Caption package
\usepackage{caption}
\captionsetup{justification=centering, labelfont=bf, labelsep=quad} % centers floats caption, makes float name in bold font, and adds space between float name and the caption
% Highlighting packages
\usepackage[svgnames]{xcolor}
% Shortcut command for highlighting in LightBlue
\newcommand{\LB}[1]{\colorbox{LightBlue}{#1}}
\begin{document}
\begin{table}[htp]
% Center the table
\centering
\caption{Scholarly works, time allocation, satisfaction, and income by US-versus foreign-born status}
\label{tbl:crossref-label}
\begin{tabularx}{1\textwidth}{C >{\hsize=0.2\hsize}C >{\hsize=0.2\hsize}C >{\hsize=0.2\hsize}C >{\hsize=0.2\hsize}C >{\hsize=0.2\hsize}C }
\toprule[0.8pt]
&
\multicolumn{2}{S{0.9in}}{Born in US N = $2900^{*}$} &
\multicolumn{3}{S{1.4in}}{Foreign Born N = $1190$}
\\
\cmidrule(lr){2-3} \cmidrule(lr){4-6}
& Mean & SD & Mean & SD & $p$
\\
\midrule
Recent Scholarly Works & & & & &
\\
\LB{Refereed Articles} & \LB{12.34} & \LB{1.234} & \LB{1.23} & \LB{1.234} & \LB{**}
\\
\bottomrule[0.8pt]
\end{tabularx}
\end{table}
\end{document}
答案3
使用@Ulysses 回答作为问题中缺少的 MWE ..,,包siunitx
和列threeparttable
类型S
以及限制表格标题到表格宽度并最终在表格下方添加表格注释例如**
在最后一列的描述(不清楚它们的含义)分别:
\documentclass{article}
\usepackage{booktabs, threeparttable}
\usepackage{siunitx} % Formats units, numbers, numbers in table
\usepackage[font=small, labelfont=bf, skip=1ex]{caption} % Formats captions of floats
\newcommand{\mcx}[2]{\multicolumn{#1}{c}{#2}} % shortcut for multicolumn
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable}
\caption{Scholarly works, time allocation, satisfaction, and income by US-versus foreign-born status}
\label{tbl:crossref-label}
\begin{tabular}{l *{2}{S[table-format=2.2] S[table-format=1.4]} c}
\toprule
& \mcx{2}{multicolumn title} & \mcx{3}{multicolumn title} \\
\cmidrule(lr) {2-3} \cmidrule(lr){4-6}
& {Mean} & {SD} & {Mean} & {SD} & $p$ \\
\midrule
text & & & & & \\
more text & 12.34 & 1.234 & 1.23 & 1.234 & ** \\
more text & 1.23 & 1.2345 & 12.3 & 1.23 & ** \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}