我正在使用的代码将所有单元格水平和垂直居中。
但是如果单元格文本分成多行(摘要列下的单元格),左侧单元格不再水平居中(见下图)。此外,如何将摘要下除顶部单元格(行)之外的所有单元格右对齐
\documentclass{article}
\usepackage{multirow}
\usepackage{tabulary}
\newcolumntype{K}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}
\begin{table} [!b]
\caption{Summary and comparisons of test methods}
\centering
\begin{tabular}{ K{5mm} | K{15mm} | K{15mm} || K{20mm} }
\hline
\multirow{2}{*}{\#} & \multicolumn{2}{c||}{Combination} & \multirow{2}{*}{Summary} \\ \cline{2-3}
& A & B & \\ \hline \hline
1 & \multirow{2}{=}{\centering 1} & A & \\ \cline{1-1} \cline{3-4}
2 & & B & \\ \cline{1-4}
3 & \multirow{4}{=}{\centering 2} & A & Note 1. Note 2. \\ \cline{1-1} \cline{3-4}
4 & & B & See \#3 \\ \cline{1-1} \cline{3-4}
5 & & C & Note 1. Note 2 \\ \cline{1-1} \cline{3-4}
6 & & D & Note 1. Note 2. Note 3. Note 4. \\ \cline{1-4}
7 & \multirow{4}{=}{\centering 2} & A & \\ \cline{1-1} \cline{3-4}
8 & & B & \\ \cline{1-1} \cline{3-4}
9 & & C & \\ \cline{1-1} \cline{3-4}
10 & & D & \\ \cline{1-4}
\end{tabular}
\label{tab:PWM4legComparison}
\end{table}
\end{document}
答案1
\documentclass{article}
\usepackage{multirow}
\usepackage{makecell} %<-----
\renewcommand{\theadfont}{\normalsize} %<-----
\newcolumntype{K}[1]{>{\centering\arraybackslash}m{#1}} %<-----
\begin{document}
\begin{table} [!b]
\caption{Summary and comparisons of test methods}
\centering
\begin{tabular}{ K{5mm} | K{15mm} | K{15mm} || m{20mm} } %<-----
\hline
\multirow{2}{*}{\#} & \multicolumn{2}{c||}{Combination} & \multirowthead{2}{Summary} \\ \cline{2-3}
& A & B & \\ \hline \hline
1 & \multirow{2}{=}{\centering 1} & A & \\ \cline{1-1} \cline{3-4}
2 & & B & \\ \cline{1-4}
3 & \multirow{8}{=}{\centering 2} & A & Note 1. Note 2. \\ \cline{1-1} \cline{3-4} %<-----
4 & & B & See \#3 \\ \cline{1-1} \cline{3-4}
5 & & C & Note 1. Note 2 \\ \cline{1-1} \cline{3-4}
6 & & D & Note 1. Note 2. Note 3. Note 4. \\ \cline{1-4}
7 & \multirow{4}{=}{\centering 2} & A & \\ \cline{1-1} \cline{3-4}
8 & & B & \\ \cline{1-1} \cline{3-4}
9 & & C & \\ \cline{1-1} \cline{3-4}
10 & & D & \\ \cline{1-4}
\end{tabular}
\label{tab:PWM4legComparison}
\end{table}
\end{document}