其次,我面临的问题是将第一行加粗。我以前使用表格格式。一旦我添加了\textbf{}
,内容就会被勾勒出来。
\textbf{Example} & \textbf{Fruit Example Example} & \textbf{Mean} & {\thead{Std. Deviation}}& {\thead{Std. Error}} \\
\documentclass[12pt,oneside]{book}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\usepackage{makecell,siunitx}
\usepackage{booktabs, array}
\usepackage{tabulary,siunitx}
\usepackage{makecell, multirow, tabularx} %for table multirow
%for table multirow
\begin{document}
\setlength\extrarowheight{1pt}
\renewcommand{\arraystretch}{1.2}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\newcolumntype{V}{>{\centering\arraybackslash}p{1cm}} % Centred fix width column
\begin{table}[h!]
\centering
\sisetup{table-number-alignment=center}
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}XcS[table-format=-1.5]S[table-format=1.5]}
\toprule
\textbf{Example} & \textbf{Fruit Example Example} & \textbf{Mean} & {\thead{Std. Deviation}}& {\thead{Std. Error}} \\
\midrule
\multicolumn{1}{l}{\thead{Fruit Fruit Example Example}} & AA & 42.00\% & 31.0000 & 5.80230 \\
\cmidrule{2-5}
& BB & 42.00\% & 17.8743 & 5.20 \\
\cmidrule{2-5}
& Total & 73.2 & 44.1257 & 5.22 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案1
像这样?
\documentclass[12pt,oneside]{book}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\usepackage{siunitx}
\usepackage{booktabs, makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\newcolumntype{V}{>{\centering\arraybackslash}p{1cm}} % Centred fix width column
\begin{document}
\begin{table}[ht]
\centering
\begin{tabularx}{\textwidth}{Y c
S[table-format=2.2,
table-space-text-post=\%]
S[table-format=2.4]
S[table-format=1.5]}
\toprule
\thead[bl]{Example}
& \thead[b]{Fruit\\ Example\\ Example}
& {\thead[b]{Mean}}
& {\thead[b]{Std.\\ Deviation}}
& {\thead[b]{Std.\\ Error}} \\
\midrule
\multirow{3.6}{=}{Fruit Fruit Example Example}
& AA & 42.00\% & 31.0000 & 5.80230 \\
\cmidrule{2-5}
& BB & 42.00\% & 17.8743 & 5.20 \\
\cmidrule{2-5}
& Total & 73.2 & 44.1257 & 5.22 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
笔记:
- 每个包只需加载一次就足够了
- 有些包会加载其他包,例如
tabularx
loadsarray
,所以你不需要再次加载它 - 如果您定义了一些新类型的列,请在表格代码中使用它们
- 我有一种强烈的感觉,您之前已经问过类似的问题......
附录 受到下面@Bernard 评论的启发,我建议您考虑对表格设计进行以下更改:
- 在数字结束百分号之间插入小距离
- 将具有相似含义的数字四舍五入为具有相同数量的小数。这可以通过使用选项
siunitx
和round-mode = places
(round-precision=...
参见下面的 MWE)简单地完成。
\documentclass[12pt,oneside]{book}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{siunitx}
\usepackage{booktabs, makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\newcolumntype{V}{>{\centering\arraybackslash}p{1cm}} % Centred fix width column
\begin{document}
\begin{table}[ht]
\centering
\sisetup{round-mode = places,
round-precision=3,
}
\begin{tabularx}{\textwidth}{Y c
S[table-format=2.2,
round-precision=2,
table-space-text-post=\%]
*{2}{S[table-format=2.3]}
}
\toprule
\thead[bl]{Example}
& \thead[b]{Fruit\\ Example\\ Example}
& {\thead[b]{Mean}}
& {\thead[b]{Std.\\ Deviation}}
& {\thead[b]{Std.\\ Error}} \\
\midrule
\multirow{3.6}{=}{Fruit Fruit Example Example}
& AA & 42.00\,\% & 31.0000 & 5.80230 \\
\cmidrule{2-5}
& BB & 42.00\,\% & 17.8743 & 5.2 \\
\cmidrule{2-5}
& Total & 73.2\,\% & 44.1257 & 5.22 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
这使:
(红线表示页面布局)