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}
    

2 Answers 2

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

0

Here is a solution with {NiceArray} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$\begin{NiceArray}{ccccw{c}{1cm}w{c}{1cm}ccw{c}{1cm}w{c}{1cm}}
    &   & \Block{1-*}{T_2} \\
    &   & \Block{1-4}{1} &&&& \Block{1-4}{2} \\
\Block{8-1}{T_1}
    &   &     &   & \Block{1-2}{T_4} && && \Block{1-2}{T_4} \\
    &   &     &   & 1 & 2 &     &   & 1 & 2 \\
    & 1 & T_3 & 1 & 0 & 0 & T_3 & 1 & 0 & 0 \\
    &   &     & 2 & 0 & 0 &     & 2 & 0 & 0 \\
    &   &     &   & \Block{1-2}{T_4} && && \Block{1-2}{T_4} \\
    &   &     &   & 1 & 2 &     &   & 1 & 2 \\
    & 2 & T_3 & 1 & 0 & 0 & T_3 & 1 & 0 & 0 \\
    &   &     & 2 & 0 & 0 &     & 2 & 0 & 111111 \\
\CodeAfter
  \SubMatrix[{5-5}{6-6}]
  \SubMatrix[{5-9}{6-10}]
  \SubMatrix[{9-5}{10-6}]
  \SubMatrix[{9-9}{10-10}]
  \SubMatrix[{3-3}{10-10}][extra-height=6pt,xshift=2pt]
\end{NiceArray}$

\end{document}

You need several compilations.

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .