3

I have drawn this matrix with tikz but as you can see the boxes are not sqares. How could I fix this? I defined

\usepackage{tikz}
\usetikzlibrary{arrows,matrix,positioning}
\newcommand\bigzero{\makebox(0,0){\text{\huge0}}}

followed by my matrix

\begin{equation}\label{eqn:mat}
\begin{tikzpicture}[baseline=(current  bounding  box.center)]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m)
{
0&1\\
-1&0&&&&\bigzero\\
&&0&1\\
&&-1&0\\
&&&&\ddots\\
&\bigzero&&&&0&1\\
&&&&&-1&0\\          
};
\draw (m-1-1.north west) -- (m-1-2.north east) -- (m-2-2.south east) -- (m-2-1.south west) -- (m-1-1.north west);
\draw (m-3-3.north west) -- (m-3-4.north east) -- (m-4-4.south east) -- (m-4-3.south west) -- (m-3-3.north west);
\draw (m-6-6.north west) -- (m-6-7.north east) -- (m-7-7.south east) -- (m-7-6.south west) -- (m-6-6.north west);
\end{tikzpicture}
\end{equation}
  • You can use fit like in the answer to your previous question. If you really need squares, you may load shapes.geometric and use a regular polygon,regular polygon sides=4 for the fit. Note that the arrows library got superseded by arrows.meta. – user121799 Sep 9 '18 at 21:34
2
\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{matrix,positioning,fit}
\newcommand\bigzero{\makebox(0,0){\text{\huge0}}}
\begin{document}
\begin{equation}\label{eqn:mat}
\begin{tikzpicture}[baseline=(current  bounding  box.center)]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m)
{
0&1\\
-1&0&&&&\bigzero\\
&&0&1\\
&&-1&0\\
&&&&\ddots\\
&\bigzero&&&&0&1\\
&&&&&-1&0\\          
};
\node[draw,fit=(m-1-1) (m-2-2),inner sep=0pt]{};
\node[draw,fit=(m-3-3) (m-4-4),inner sep=0pt]{};
\node[draw,fit=(m-6-6) (m-7-7),inner sep=0pt]{};
\end{tikzpicture}
\end{equation}
\end{document}

enter image description here

Your Answer

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