1

I'm trying to have a multicolumn label but that doesn't seem to work. When I run the following, it fails:

\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*}

This is the closest I've gotten to a non-failing version but am unable to get the multicolumn label to work.

\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*}

Single Column Labels Output

How can I get the "Predicted" label to span the remaining columns?

I'm happy to switch to another environment from blockarray but it seemed like this was the recommended package after looking at multiple alternatives for labeled matrixes.

Full document:

\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
    please always post a complete small document, not disconnected fragments, so people can run and debug the code. I'm surprised multirow works with blockarray at all, I'm certain that combination has never been tested by the authors of either package:-) – David Carlisle Aug 25 '18 at 15:04
  • 1
    Will update with full document. Apologies for that. I thought they'd work based on this question: tex.stackexchange.com/questions/10122/bordermatrix-with-blocks – sbeleidy Aug 25 '18 at 15:08
  • 1
    @sbeleidy, as you found yourself, in the first example replace \multicolumn{5}{c}{\text{Predicted}} with \BAmulticolumn{5}{c}{\text{Predicted}} and it will works. – Zarko Aug 25 '18 at 15:26
  • Well, that's embarassing. I completely missed that and saw it as multicolumn. Thank you @Zarko – sbeleidy Aug 25 '18 at 15:45
  • 1
    @DavidCarlisle, i know who is author :-). however after written 50+ packages (if i remember correctly) is difficult to remember all commands/macros names :-) – Zarko Aug 25 '18 at 19:45
2

Thanks to @Zarko pointing out that the way to do multicolumns when using blockarray is to use \BAmulticolumn instead of \multicolumn. The final result is from the following code:

\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}

enter image description here

  • 1
    nice answer (+1), however, please extend your code snippet to complete small document beginning with \documentclass... and end with \end{document} that members can simple copy and test it. – Zarko Aug 25 '18 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.