In
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (bottom left) at (10,10);
\coordinate (top right) at (20,20);
\draw[rounded corners,fill=black] (bottom left) rectangle (top right);
\end{tikzpicture}
\end{document}
the line
\draw[rounded corners,fill=black] (bottom left) rectangle (top right);
draws a black rectangle with rounded corners between the coordinates (bottom left) and (top right).
What's the most concise way to define a node with exactly the same shape, position and size as a rectangle defined with '\draw' and 'rectangle' (as above)?
The solution should …
- use the provided coordinates with manual calculations,
- work with rounded corners,
- place the node's coordinates (n.north, n.west, …) were expected, and
- be as concise (and elegant) as possible.
Best Answer
If I understood you correctly, you like to determine rectangle with size determined with two coordinates (bottom left, top right). If this is a case, you can obtain this as follows:
Of course, you can define rectangle size on different way, for example width
minimum width
,minimum height
,text width
andtext height
etc.For fiting node on given coordinates I use
tikzlibrary{fit}
and set inner node separation to0pt
. The node aslo have all anchors as defined for rectangular shape.Comment: Declare rectangle nodes on such a way may lead to problem with placing of node's contents. They can be displaced from center of node.