# Placing a rectangular node in tikz by specifying two opposing corners

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.
• Apologies for a previous comment. The best way to do this is by defining a use- defined to path. – user10274 Jun 14 '15 at 11:40
• Related: Q87989 – Qrrbrbirlbel Jun 14 '15 at 13:18
• What should happen, if you apply a rotation to the scope, say \begin{tikzpicture}[rotate=30]. Should this transformation also apply to the rectangular node? – Qrrbrbirlbel Jun 14 '15 at 13:19

## 2 Answers

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:

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}[
mynode/.style 2 args = {
draw, rounded corners, fill=black,
inner sep=0pt, outer sep=0pt,
fit=(#1) (#2)}
]
\coordinate (bottom left) at (10,10);
\coordinate (top right) at (20,20);
\node[mynode={bottom left}{top right}] {};
\end{tikzpicture}
\end{document} Of course, you can define rectangle size on different way, for example width minimum width, minimum height, text width and text height etc.

For fiting node on given coordinates I use tikzlibrary{fit} and set inner node separation to 0pt. 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.

You can also define a node placed at the middle of the coordinates, and big half the distance of the two coordinates.

\node[rounded corners, draw=red, minimum size=10cm] at (15,15) {};


Here are the corners to show it fits:  ## Ouput ## Code

\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);
\node[rounded corners, draw=red, minimum size=10cm] at (15,15) {};
\end{tikzpicture}
\end{document}