我尝试了几种方法,但仍然无法获得正确的对齐方式。我希望第一列位于左侧,然后其他列位于右侧。
\documentclass{article}
\usepackage{booktabs}
\usepackage[flushleft]{threeparttable}
\renewcommand{\TPTtagStyle}{\itshape} % optional
\usepackage{tabularx, ragged2e}
\usepackage{threeparttable}
\begin{document}
\begin{table}[!ht]
\centering
\begin{tablenotes}
\centering
\small
\item Dependent Variable: Testing1234
\end{tablenotes}
\begin{threeparttable}
%\newcolumntype{Y}{>{\RaggedRight\arraybackslash\hsize=2\hsize\linewidth=\hsize}X}
%\newcolumntype{W}{>{\RaggedLeft\arraybackslash\hsize=0.75\hsize\linewidth=\hsize}X}
%\begin{tabularx}{\textwidth}{@{}Y*{3}{W}@{}}
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}Xlllll}
\toprule
\small {\textbf{Source}}
& \small {\textbf{Type III Sum of Squares}}
& \small {\textbf{df}}
& \small {\textbf{Mean Square}}
& \small {\textbf{F}}
& \small {\textbf{Sig.}}\\
\midrule
Corrected Model & 14573.300\tnote{a} & 3 & 4857.767 & 40.297 & .000 \\
Testing1234 & 214036.900 & 1 & 214036.900 & 1775.503 & .000\\
Testing1234 & .100 & 1 & .100 & .001 & .977\\
Testing1234Testing1234 & 14137.600 & 1 & 14137.600 & 117.276 & .000\\
Testing1234Testing1234Testing1234 & 435.600 & 1 & 435.600 & 3.613 & .065 \\
\bottomrule
\end{tabularx}
\footnotesize
\begin{tablenotes}
\item[a]Testing1234Testing1234Testing1234 % the footnote itself
\end{tablenotes}
\end{threeparttable}
\caption{Testing1234
\label{tab:test123} }
\end{table}
\end{document}
我已经累了:
\newcolumntype{Y}{>{\RaggedRight\arraybackslash\hsize=2\hsize\linewidth=\hsize}X}
\newcolumntype{W}{>{\RaggedLeft\arraybackslash\hsize=0.75\hsize\linewidth=\hsize}X}
\begin{tabularx}{\textwidth}{@{}Y*{3}{W}@{}}
不工作
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}Xlllll}
不工作
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}Xrrrrr}
越来越困惑了。
答案1
使用\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xrrrrr}
您可以获得所需的结果。我还使用该\thead
命令替换重复的\small
和\textbf
命令,并在第二列和第四列的列标题中插入手动换行符:
\documentclass{article}
\usepackage{booktabs}
\usepackage[flushleft]{threeparttable}
\renewcommand{\TPTtagStyle}{\itshape} % optional
\usepackage{tabularx, ragged2e}
\usepackage{makecell}
\renewcommand\theadfont{\small\bfseries}
\begin{document}
\begin{table}[!ht]
\centering
\small
Dependent Variable: Testing1234
\begin{threeparttable}
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xrrrrr}
\toprule
\thead{Source}
& \thead{Type III\\ Sum of\\ Squares}
& \thead{df}
& \thead{Mean\\ Square}
& \thead{F}
& \thead{Sig.}\\
\midrule
Corrected Model & 14573.300\tnote{a} & 3 & 4857.767 & 40.297 & .000 \\
Testing1234 & 214036.900 & 1 & 214036.900 & 1775.503 & .000\\
Testing1234 & .100 & 1 & .100 & .001 & .977\\
Testing 1234Tes ting1234 & 14137.600 & 1 & 14137.600 & 117.276 & .000\\
Testing 1234Test ing12 34Te ting1234 & 435.600 & 1 & 435.600 & 3.613 & .065 \\
\bottomrule
\end{tabularx}
\footnotesize
\begin{tablenotes}
\item[a]Testing1234Testing1234Testing1234 % the footnote itself
\end{tablenotes}
\end{threeparttable}
\caption{Testing1234\label{tab:test123}}
\end{table}
\end{document}
答案2
您也可以使用tabulary
它来代替,tabularx
因为这个环境有 L、C、R 和 J 列。
但是为什么不使用 R 列来表示数字,而使用 S 列呢siunitx
?
\documentclass{article}
\usepackage{booktabs}
\usepackage{tabulary,siunitx,lipsum}
\begin{document}
\lipsum[1][1-4]
\begin{table}[h]
\begin{tabulary}{\textwidth}{@{}LS[table-format=6.3]
cS[table-format=6.3]S[table-format=4.3]c@{}}\toprule
& {Type III Sum} & & {Mean} & & \\
Source & {of Squares} & {df} & {Square} & {F} & {Sig.} \\\midrule
Corrected Model & 14573.300$^a$ & 3 & 4857.767 & 40.297 & .000 \\
Testing1234 & 214036.900 & 1 & 214036.900 & 1775.503 & .000\\
Testing1234 & .100 & 1 & .100 & .001 & .977\\
Testing1234Testing1234 & 14137.600 & 1 & 14137.600 & 117.276 & .000\\
Testing1234Testing1234\-Testing1234 & 435.600 & 1 & 435.600 & 3.613 & .065 \\
\bottomrule
\end{tabulary}
$^a$ \footnotesize Testing1234Testing1234Testing1234
\end{table}
\lipsum[2][1-4]
\end{document}
tabularx
是固定宽度的表格,至少有一个X列宽度相等(但,ta采取使不等的列与任何justito适应右对齐的文本(R列)左宽度适应单元格竞赛尝试使列不等的尝试采取最佳宽度