1

It's kinda hard to explain what I want so here's the code and the result:

\begin{gather*}
    \begin{matrix}
    {} & \begin{pmatrix} 0 & 1 & \cdots & n-1 \end{pmatrix} \\
    \begin{pmatrix} 0 \\  1 \\ \vdots \\ n-1 \end{pmatrix} &
        \begin{pmatrix}
        f(0,0)&f(0,1)&\cdots&f(0,n-1)\\
        f(1,0)&f(1,1)&\cdots&f(1,n-1)\\
        \vdots&\vdots&\ddots&\vdots\\
        f(n-1,0)&f(n-1,1)&\cdots&f(n-1,n-1)
        \end{pmatrix}
   \end{matrix}
\end{gather*}

enter image description here

What I wanted is for the upper matris to be equally formatted as the big one below. So "0" shoud be aligned with "f(0,0)", "1" with "f(0,1)" and so on. I don't think I can use arrays since that wouldn't be able to use brackets. A solution would be appreciated, thanks.

2

A quick fix; use \makebox[\widthof{<last row cell>}]{<first row cell>}. This requires the calc package to compute \widthof.

 \begin{gather*}
    \begin{matrix}
    {} & \begin{pmatrix}\makebox[\widthof{$f(n-1,0)$}]{0} & \makebox[\widthof{$f(n-1,1)$}]{1} & \cdots & \makebox[\widthof{$f(n-1,n-1)$}]{$n-1$}\end{pmatrix} \\[.2em]
    \begin{pmatrix} 0 \\  1 \\ \vdots \\ n-1 \end{pmatrix} &
        \begin{pmatrix}
        f(0,0)&f(0,1)&\cdots&f(0,n-1)\\
        f(1,0)&f(1,1)&\cdots&f(1,n-1)\\
        \vdots&\vdots&\ddots&\vdots\\
        f(n-1,0)&f(n-1,1)&\cdots&f(n-1,n-1)
        \end{pmatrix}
   \end{matrix}
\end{gather*}

enter image description here

  • 1
    You might want to use \mathmakebox from mathtools (\widthof is included). This is the approach used by \vdotswithin. – John Kormylo Jun 11 '17 at 19:25

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.