当我使用时:
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}cccc}
它将所有内容移到左侧,并在右侧表格中留出一些空间(示例 1)
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}Xccc}
它不会给出中心。(示例 2)
我的完整 MWE:
\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage[svgnames, table]{xcolor}
\usepackage{hhline, boldline}
\usepackage{seqsplit, caption} %for table spacing to second row
\usepackage{booktabs, ragged2e} % Use booktabs rules and get rid of vertical rules, ragged2e to ragged text
\usepackage{siunitx} %for table spacing to second row
\usepackage{threeparttable} %to add footnote below table
\usepackage{tabulary}
\usepackage{graphicx}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}cccc}
\toprule
& \thead{\small {\textbf{Mean}}\\ \textbf{(\%)}} & \small {\textbf{N}}
& \thead{\small {\textbf{Std. Deviation}}\\ \textbf{(\%)}}& \thead{\small {\textbf{Std. Error}} \\ \textbf{Mean (\%)}} \\
\midrule
\multicolumn{1}{l}{\textit{Aaaaaa example dataset} (AA)} & 94.51 & 60 & 5.55 & 1.33 \\
\multicolumn{1}{l}{\textit{Aaaaaa example dataset} (BB)} & 40.32 & 60 & 12.13 & 3.43 \\
\bottomrule
\end{tabularx}
\caption{Example 1}
\end{table}
\begin{table}[h!]
\centering
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}Xccc}
\toprule
& \thead{\small {\textbf{Mean}}\\ \textbf{(\%)}} & \small {\textbf{N}}
& \thead{\small {\textbf{Std. Deviation}}\\ \textbf{(\%)}}& \thead{\small {\textbf{Std. Error}} \\ \textbf{Mean (\%)}} \\
\midrule
\multicolumn{1}{l}{\textit{Aaaaaa example dataset} (AA)} & 94.51 & 60 & 5.55 & 1.33 \\
\multicolumn{1}{l}{\textit{Aaaaaa example dataset} (BB)} & 40.32 & 60 & 12.13 & 3.43 \\
\end{tabularx}
\caption{Example 2}
\end{table}
\end{document}
答案1
你错误地声明了列:你可能想要
>{\raggedright}Xcccc
并去掉\multicolumn{1}{l}{...}
第一列的。
我认为使用siunitx
和tabular*
更好。
\documentclass[12pt,oneside]{book}
\usepackage[pass,showframe]{geometry}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{siunitx}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\begin{document}
\begin{table}[htp!]
\centering
\begin{tabular*}{\textwidth}{
@{\extracolsep{\fill}}
l
S[table-format=2.2]
S[table-format=2.0]
S[table-format=2.2]
S[table-format=1.2]
@{}
}
\toprule
& {\thead{Mean \\ (\%)}}
& {\theadfont N}
& {\thead{Std. Dev. \\ (\%)}}
& {\thead{Std. Error \\ Mean (\%)}} \\
\midrule
\textit{Aaaaaa example dataset} (AA) & 94.51 & 60 & 5.55 & 1.33 \\
\textit{Aaaaaa example dataset} (BB) & 40.32 & 60 & 12.13 & 3.43 \\
\bottomrule
\end{tabular*}
\caption{Example}
\end{table}
\end{document}
我只留下了必要的包。请注意输入较少:由于您设置了,\theadfont
因此重复\small
和是没有意义的\textbf
。