0

I want to represent a four-dimensional tensor using a matrix of matrices. Additionally, I want to label the rows and columns of the inner matrices. My attempt to make this labeled matrix of matrices is given below, but there are a couple of things that I am not happy with.

  1. The row and column labels are not centered over the things that they are labeling. For example, the $$T_{2}$$ label should be between the $$1$$ and $$2$$ labels for the columns of the outer matrix. I tried using multicolumn and multirow, but they did not appear to work with the block matrix, and I could not figure out the necessary syntax from the documentation on CTAN.
  2. The results are not as good when some entries of the tensor are much longer than others. For example, the (2,2)-block below is much wider than the (1,2)-block, and the (1,2)-block does not adjust to match.

    \documentclass{article}
        \usepackage{blkarray}
    
        \newcommand{\tensorblock}[1]
        {
            \begin{blockarray}{c@{~}c@{~~}cc}
                && T_{4} \\
                && 1 & 2 \\
                \begin{block}{c@{~}c@{~~}[cc]}
                    T_{3} & 1 & 0 & 0 \\
                    & 2 & 0 & #1 \\
                \end{block}
            \end{blockarray}
        }
    \begin{document}
    \[
        \begin{blockarray}{c@{~}c@{~~}cc}
            && T_{2} \\
            && 1 & 2 \\
            \begin{block}{c@{~}c@{~~}[cc]}
                T_{1} & 1 & \tensorblock{0} & \tensorblock{0} \\
                & 2 & \tensorblock{0} & \tensorblock{111111} \\
            \end{block}
        \end{blockarray}
    \]
    \end{document}
    
1

If you want different columns to be the same width you need to know what that width is ahead of time.

\documentclass{article}
    \usepackage{blkarray}

    \newcommand{\tensorblock}[1]
    {
        \begin{blockarray}{c@{~}c@{~~}cc}
            && \BAmulticolumn{2}{c}{T_{4}} \\
            && \makebox[\widest]{1} & \makebox[\widest]{2} \\
            \begin{block}{c@{~}c@{~~}[cc]}
                T_{3} & 1 & 0 & 0 \\
                & 2 & 0 & #1 \\
            \end{block}
        \end{blockarray}
    }
  \newlength{\widest}
\begin{document}
\settowidth{\widest}{111111}%
\[
    \begin{blockarray}{c@{~}c@{~~}cc}
        && \BAmulticolumn{2}{c}{T_{2}} \\
        && 1 & 2 \\
        \begin{block}{c@{~}c@{~~}[cc]}
            T_{1} & 1 & \tensorblock{0} & \tensorblock{0} \\
            & 2 & \tensorblock{0} & \tensorblock{111111} \\
        \end{block}
    \end{blockarray}
\]
\end{document}

demo

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.