我尝试使用多列标签,但似乎行不通。当我运行以下命令时,失败:
\begin{equation*}
\mathbf{C} =
\begin{blockarray}{ccccccc}
& \multicolumn{5}{c}{\text{Predicted}} & \\
& 1 & 2 & 3 & \dots & n & \\
\begin{block}{c(ccccc)c}
1 & c_{11} & c_{12} & c_{13} & \dots & c_{1n} & \multirow{4}{*}{\rotatebox{-90}{\text{Actual}}} \\
2 & c_{21} & c_{22} & c_{23} & \dots & c_{2n} & \\
\vdots & \vdots & \ddots & & & \vdots & \\
n & c_{n1} & c_{n2} & c_{n3} & \dots & c_{nn} & \\
\end{block}
\end{blockarray}
\end{equation*}
这是我所得到的最接近无故障的版本,但无法使多列标签正常工作。
\begin{equation*}
\mathbf{C} =
\begin{blockarray}{ccccccc}
& \text{Predicted} & & & & \\
& 1 & 2 & 3 & \dots & n & \\
\begin{block}{c(ccccc)c}
1 & c_{11} & c_{12} & c_{13} & \dots & c_{1n} & \multirow{4}{*}{\rotatebox{-90}{\text{Actual}}} \\
2 & c_{21} & c_{22} & c_{23} & \dots & c_{2n} & \\
\vdots & \vdots & \ddots & & & \vdots & \\
n & c_{n1} & c_{n2} & c_{n3} & \dots & c_{nn} & \\
\end{block}
\end{blockarray}
\end{equation*}
如何让“预测”标签跨越剩余的列?
我很高兴从 blockarray 切换到另一个环境,但在查看了标记矩阵的多种替代方案后,这似乎是推荐的包。
完整文档:
\documentclass{beamer}
% PACKAGES
\usepackage{blkarray}
\usepackage{multirow}
\begin{document}
\begin{frame}
\begin{equation*}
\mathbf{C} =
\begin{blockarray}{ccccccc}
& \text{Predicted} & & & & & \\
& 1 & 2 & 3 & \dots & n & \\
\begin{block}{c(ccccc)c}
1 & c_{11} & c_{12} & c_{13} & \dots & c_{1n} & \multirow{4}{*}{\rotatebox{-90}{\text{Actual}}} \\
2 & c_{21} & c_{22} & c_{23} & \dots & c_{2n} & \\
\vdots & \vdots & \ddots & & & \vdots & \\
n & c_{n1} & c_{n2} & c_{n3} & \dots & c_{nn} & \\
\end{block}
\end{blockarray}
\end{equation*}
\end{frame}
\end{document}
答案1
感谢@Zarko指出,使用blockarray时执行多列的方法是使用\BAmulticolumn
而不是\multicolumn
。最终结果来自以下代码:
\documentclass{beamer}
\usepackage{blkarray}
\usepackage{multirow}
\begin{document}
\begin{frame}
\begin{blockarray}{ccccccc}
& \BAmulticolumn{5}{c}{\text{Predicted}} & \\
& 1 & 2 & 3 & \dots & n & \\
\begin{block}{c[ccccc]c}
1 & c_{11} & c_{12} & c_{13} & \dots & c_{1n} & \multirow{4}{*}{\rotatebox{-90}{\text{Actual}}} \\
2 & c_{21} & c_{22} & c_{23} & \dots & c_{2n} & \\
\vdots & \vdots & \ddots & & & \vdots & \\
n & c_{n1} & c_{n2} & c_{n3} & \dots & c_{nn} & \\
\end{block}
\end{blockarray}
\end{frame}
\end{document}
答案2
带有{NiceMatrix}
同名包nicematrix
。
\documentclass{beamer}
\usepackage{nicematrix}
\begin{document}
\begin{frame}
$\begin{NiceMatrix}
& \Block{1-5}{\text{Predicted}} \\
& 1 & 2 & 3 & \dots & n & \\
1 & c_{11} & c_{12} & c_{13} & \dots & c_{1n} & \Block{4-1}{\rotate\text{Actual}} \\
2 & c_{21} & c_{22} & c_{23} & \dots & c_{2n} & \\
\vdots & \vdots & \ddots & & & \vdots & \\
n & c_{n1} & c_{n2} & c_{n3} & \dots & c_{nn} & \\
\CodeAfter
\SubMatrix[{3-2}{6-6}]
\end{NiceMatrix}$
\end{frame}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。