我正在尝试在乳胶上创建这个表
但是我不知道如何使用多行。这是我的代码
\begin{center}
\centering
\begin{tabular}{ | l | l | l | l | l | }
\hline
& & \multicolumn{3}{|c|}{ACTUAL} \\ \hline
& &Class A & Class B & Class C \\ \hline
& Class A & 42 & 4 & 3 \\ \hline
& Class B & 11 & 35 & 2 \\ \hline
& Class C & 3 & 6 & 38 \\ \hline
\end{tabular}
\captionof{table}{Risk Matrix}
\end{center}
这就是我通过代码得到的结果
注意:如何使值在表中居中
答案1
\documentclass[12pt]{article}
\usepackage{multirow,graphicx}
\usepackage{caption}
\begin{document}
\begin{center}
\centering
\renewcommand\arraystretch{1.1}
\begin{tabular}{ | l | l | l | l | l | }
\cline{3-5}
\multicolumn{2}{c|}{}& \multicolumn{3}{|c|}{ACTUAL} \\ \cline{3-5}
\multicolumn{2}{c|}{} &Class A & Class B & Class C \\ \hline
\multirow{3}{*}{\rotatebox{90}{\tiny ESTIMATED\,}} & Class A & 42 & 4 & 3\\ \cline{2-5}
& Class B & 11 & 35 & 2 \\ \cline{2-5}
& Class C & 3 & 6 & 38 \\ \hline
\end{tabular}
\captionof{table}{Risk Matrix}
\end{center}
\end{document}
答案2
\documentclass{scrartcl}
\usepackage{array,multirow,graphicx,booktabs}
\begin{document}
\begin{center}
\centering
\begin{tabular}{ l l c c c }
\toprule
& & \multicolumn{3}{c}{\textbf{Actual}} \\
& &Class A & Class B & Class C \\
\midrule
\parbox[t]{2mm}{\multirow{3}{*}{\rotatebox[origin=c]{90}{\textbf{Estim.}}}}& Class A & 42 & 4 & 3 \\
& Class B & 11 & 35 & 2 \\
& Class C & 3 & 6 & 38 \\
\bottomrule
\end{tabular}
\captionof{table}{Risk Matrix}
\end{center}
\end{document}
答案3
这里有 3 种变体,用于siunitx
居中右对齐数字,以及带有hhline, booktabs
and/or 的不同可能规则boldline
:
\documentclass[12pt]{article}
\usepackage{multirow,graphicx}
\usepackage{caption}
\usepackage{array, siunitx, boldline, hhline, booktabs}
\begin{document}
\begin{center}
\centering\sisetup{table-format=2.0}
\renewcommand\arraystretch{1.25}\setlength\arrayrulewidth{1pt}
\begin{tabular}{c|l *{3}{V{0.3}S}|}
\multicolumn{2}{c}{}& \multicolumn{3}{c}{ACTUAL} \\
\hhline{~~|---}
\multicolumn{2}{c|}{} & {Class A} & {Class B} & {Class C} \\
\hhline{~|----|}%\clineB{3-5}{0.3}
\multirow{3}{*}[-0.2ex]{\rotatebox{90}{\scriptsize ESTIMATED\,}} & Class A & 42 & 4 & 3\\ \clineB{2-5}{0.3}
& Class B & 11 & 35 & 2 \\ \clineB{2-5}{0.3}
& Class C & 3 & 6 & 38 \\
\hhline{~|----}
\end{tabular}
\captionof{table}{Risk Matrix}
\end{center}
\begin{center}
\centering\sisetup{table-format=2.0}
\renewcommand\arraystretch{1.25}\setlength\arrayrulewidth{1pt}
\begin{tabular}{cl| *{3}{S}}
\multicolumn{2}{c}{} & \multicolumn{3}{c}{ACTUAL} \\
& & {Class A} & {Class B} & {Class C} \\
\cline{2-5}
\multirow{3}{*}[-0.2ex]{\rotatebox{90}{\scriptsize ESTIMATED\,}} & Class A & 42 & 4 & 3\\ %
& Class B & 11 & 35 & 2 \\ %
& Class C & 3 & 6 & 38 \\
\end{tabular}
\captionof{table}{Risk Matrix}
\end{center}
\begin{center}
\centering\sisetup{table-format=2.0}
\begin{tabular}{cl *{3}{S}}
& & \multicolumn{3}{c}{ACTUAL} \\
\cmidrule(l{-1.5em}r{-1.5em}){4-4}
& & {Class A} & {Class B} & {Class C} \\%
\cmidrule[\heavyrulewidth]{2-5}
\multirow{3}{*}{\rotatebox{90}{\scriptsize ESTIMATED\,}} & Class A & 42 & 4 & 3\\ \addlinespace
& Class B & 11 & 35 & 2 \\ \addlinespace
& Class C & 3 & 6 & 38 \\
\cmidrule[\heavyrulewidth]{2-5}
\addlinespace[-\belowrulesep]
\end{tabular}
\captionof{table}{Risk Matrix}
\end{center}
\end{document}
答案4
您可以使用 轻松制作该表格{NiceTabular}
。nicematrix
键hvlines
绘制除“角落”之外的所有规则。 使用键corners
,我们告诉 nicematrix 考虑西北 (NW) 角落。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\renewcommand{\arraystretch}{1.2}
\begin{NiceTabular}{>{\tiny}ccccc}[corners=NW,hvlines]
& & \Block{1-3}{ACTUAL} \\
& & Class A & Class B & Class C \\
\Block{3-1}{\rotate ESTIMATED} & Class A & 42 & 4 & 3 \\
& Class B & 11 & 35 & 2 \\
& Class C & 3 & 6 & 38
\end{NiceTabular}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。