I googled but cannot find a solution. Is that possible to draw a node with TikZ which will be a square and NOT a rectangle of arbitrary proportions?
Minimum working example can be something like this:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node at (0,0) [circle,draw] (c100) {$c_{100}$};
\node at (3,0) [rectangle,draw] (v100) {$v_{100}$};
\draw (c100) -- (v100);
\end{tikzpicture}
\end{document}
While circle is perfectly round, rectangle is just a rectangle:
And I want it to be a square. I did not find any shape like square or so.
Best Answer
This is surprisingly difficult. In the following code, I've defined a custom node shape
square
that inherits from therectangle
shape, but forces its size to be square. Unfortunately, the inheritance mechanism doesn't allow redefinition of inherited saved anchors, so I had to copy some code from the TikZrectangle
definition.On the plus side, it should be correct in all cases (defining different values for
inner [xy]sep
,minimum {width,height}
andouter [xy]sep
) and has all the anchors of therectangle shape
.