想调整表格以使其更好看,两种方法都试过了,但不起作用。
将第一列字母设为2行。将所有内容放在左侧,所有列的长度相同
\documentclass[12pt,oneside]{book}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\usepackage{makecell,siunitx}
\usepackage{booktabs}
\usepackage{tabulary,siunitx}
\usepackage{makecell, multirow, tabularx} %for table multirow
%for table multirow
\begin{document}
\renewcommand\theadfont{\small\bfseries}
\begin{table}[!ht]
\centering
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xcclc}
\toprule
\thead[l]{}
&
& \thead{Value Label}
& \thead{N}
\\
\midrule
\multirow{2}{*}{\textbf{Example}} & 1 & Example Example Example & 20\\
\cline{2-4}
& 2 & Example Example Example Example & 20 \\
\cline{1-4}
\multirow{2}{*}{\textbf{Example Example Example}} & 1 & AM & 20\\
\cline{2-4}
& 2 & FM & 20 \\
\bottomrule
\end{tabularx}
\end{table}
\setlength\extrarowheight{1pt}
\renewcommand{\arraystretch}{1.2}
\begin{table}[h!]
\centering
\begin{tabularx}{\textwidth}{@{}Y*{3}{W}@{}}
\toprule
&
& \small {\textbf{Value Label}} & \small {\textbf{N}}
\\
\midrule
\multirow{2}{*}{\textbf{Example}} & 1 & Example Example Example & 20\\
\cline{2-4}
& 2 & Example Example Example Example & 20 \\
\cline{1-4}
\multirow{2}{*}{\textbf{Example Example Example}} & 1 & AM & 20\\
\cline{2-4}
& 2 & FM & 20 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案1
当您将第一列和第三列更改为左对齐的 X 列时,将 {*} 更改为 {=} 可修复多行中的换行符。为了减少输入,我将此类列定义为新的列类型。此外,通过使用数组的新w
列,您可以修复宽度和对齐方式。我将宽度固定为 2 厘米,但如果您希望第二列和第四列更宽或更窄,请更改这些值。
示例 1
由于不能使用新版本的数组,我将第二列和第四列改为固定宽度的p
-column,内容居中。为了便于阅读,我定义了一个新的 columntype V
。此外,我将整个表格的宽度限制为0.7\linewidth
。我还选择了 fontsize \small
。
\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}
\small
\centering
\begin{tabularx}{0.7\textwidth}{@{}YVYV@{}} % Limit the width of the tabular
\toprule
&
& \small {\textbf{Value Label}} & \small {\textbf{N}}
\\
\midrule
\multirow{2}{*}{\textbf{Example}} & 1 & Example Example Example & 20\\
\cmidrule{2-4}
& 2 & Example Example Example Example & 20 \\
\cmidrule{1-4}
\multirow{2}{=}{\textbf{Example Example\newline Example}} & 1 & AM & 20\\
\cmidrule{2-4}
& 2 & FM & 20 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
示例 2
\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}
\begin{table}
\centering
\begin{tabularx}{\textwidth}{@{}Yw{c}{2cm}Yw{c}{2cm}@{}}
\toprule
&
& \small {\textbf{Value Label}} & \small {\textbf{N}}
\\
\midrule
\multirow{2}{*}{\textbf{Example}} & 1 & Example Example Example & 20\\
\cmidrule{2-4}
& 2 & Example Example Example Example & 20 \\
\cmidrule{1-4}
\multirow{2}{=}{\textbf{Example Example\newline Example}} & 1 & AM & 20\\
\cmidrule{2-4}
& 2 & FM & 20 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}