3

I'm trying to typeset the matrix depicted in the diagram, I've considered many examples, and in particular easybmat. But nothing came closer than the approach I settled on given below. However it does not quite produce the accuracy I wanted. Is there a way to make the diagram closer to the required picture?

\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{easybmat}

\newcommand\bigzero{\makebox(0,0){\text{\Huge0}}}
\begin{document} 

\[
\sbox0{$\begin{array}{c c c |}0&1&0\\0&0&1\\0&0&0\\ \hline\end{array}$}
\sbox1{$\begin{array}{| r|}\hline \\ 2\\ \hline\end{array}$}
\sbox2{$\begin{matrix}2&1&0\\0&2&1\\0&0&2\end{matrix}$}
\sbox3{$\begin{array}{c c c |}2&1&0\\0&2&1\\0&0&2\\ \hline\end{array}$}
%
A=\left[
\begin{array}{c c c c}
\usebox{0}&  & \bigzero & \\
& \usebox{1} &  & \\
\bigzero & & \usebox{3} & \\
& &  & 0 \\
\end{array}
\right]
\]

\end{document} 

Required Picture Gotten so far

  • Rather than posting images it is better to show us what you have tried. Posting a minimal working example that indicates what you are trying to do makes it easier for people to understand what you want. It also makes it easier for people to help you, since they have some code to start from, and much more likely that some one will try to help you. – Andrew Apr 10 '17 at 4:25
4

For questions like this a matrix of math nodes is your friend. These are tikz matrix that allow you to draw lines connecting the matrix entries.

Here the output I get:

enter image description here

and here is the code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}

\[ A =
  \begin{tikzpicture}[baseline=(current bounding box.center),
                      large/.style={font=\large}]
    \matrix (M)[matrix of math nodes, nodes in empty cells,
                left delimiter={[}, right delimiter={]},
                column sep={1.2em,between origins},
                row sep={1.2em,between origins}
    ]{ 0 & 1 & 0 &   &              \\
       0 & 0 & 1 &   &   &   &   &  \\
       0 & 0 & 0 &   &   &          \\
         &   &   & 2 &   &          \\
         &   &   &   & 2 & 1 & 0 &  \\
         &   &   &   & 0 & 2 & 1 &  \\
         &   &   &   & 0 & 0 & 2 &  \\
         &   &   &   &   &   &   & 0\\
     };
    \draw(M-3-1.south west)--([xshift=2mm]M-3-4.south east);
    \draw(M-4-3.south)--(M-4-4.south east);
    \draw(M-7-5.south)--([xshift=2mm]M-7-7.south);
    \draw(M-1-3.north east)--(M-4-4.south west);
    \draw(M-4-4.north east)--(M-5-5.south west);
    \draw(M-5-7.north east)--(M-7-7.south east);
    \node[large] at (M-2-7){$0$};
    \node[large] at (M-7-2){$0$};
  \end{tikzpicture}
\]

\end{document}

Some words of explanation:

  • The (M) after \matrix means that the nodes have labels (M-1-1), (M-1-2) etc. You can change (M) to anything you like.
  • The node (M-3-1.south west) is the south west corner of the entry in row 3 and column 1. Simiarly, there are north, east, south, ...
  • I have used a matrix of math nodes but there is also a matrix of nodes. The difference, as you'd suspect, is that matrix of math nodes puts the matrix entries into math-mode.
  • the nodes in empty cells creates labels for empty cells.
  • I didn't put the large 0s into the matrix because this would have warped the row and column sizes
  • The lines column sep={1.2em,between origins} and row sep={1.2em,between origins} makes the distances between the center of the rows and columns the same, which you want if you are drawing vertical and horizontal lines between the matrix entries
  • you need to put braces around the delimiters in left delimiter={[} and right delimiter={]}
  • the baseline=(current bounding box.center) is there to center the matrix in the displayed equation
  • the large/.style={font=\large} sets the font size for the "large" zeros in the matrix (this is the meaning of the large in \node[large]).
  • Thx! I was going to use Tikz as a last resort ;) Now I know this is the way to go. – Athena Widget Apr 10 '17 at 15:39
0

100% based on Andrew's answer, I'm simply providing a possible solution to the 'large zero problem', based on the answer to Adjusting font size with TikZ picture

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}

\[ A =
  \begin{tikzpicture}[baseline=(current bounding box.center),
                  large/.style={font=\large}]
    \matrix (M)[matrix of math nodes, nodes in empty cells,
            left delimiter={[}, right delimiter={]},
            column sep={1.2em,between origins},
            row sep={1.2em,between origins}
    ]{ 0 & 1 & 0 &   &              \\
       0 & 0 & 1 &   &   &   &   &  \\
       0 & 0 & 0 &   &   &          \\
         &   &   & 2 &   &          \\
         &   &   &   & 2 & 1 & 0 &  \\
         &   &   &   & 0 & 2 & 1 &  \\
         &   &   &   & 0 & 0 & 2 &  \\
         &   &   &   &   &   &   & 0\\
     };
    \draw(M-3-1.south west)--([xshift=2mm]M-3-4.south east);
    \draw([xshift=1mm]M-4-3.south)--([xshift=1mm]M-4-4.south east);
    \draw(M-7-5.south)--([xshift=3mm]M-7-7.south);
    \draw(M-1-3.north east)--(M-4-4.south west);
    \draw(M-4-4.north east)--(M-5-5.south west);
    \draw(M-5-7.north east)--([yshift=-1mm]M-7-7.south east);
    \node[] at (M-2-7){\Huge 0};
    \node[] at (M-7-2){\Huge 0};
  \end{tikzpicture}
\]

\end{document}

LargeZeroSolution

  • 1
    In my answer I used \large. If you want a bigger 0 then all that you need to do is change the large/.style={font=\large} in my post to large/.style={font=\Huge}. (See my last dot-point:) – Andrew Apr 10 '17 at 23:17

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.