How do I make a tikz rectangle node with given lower-left and upper-right corners, having a given border color and fill color? I know it seems like a basic question, but I cannot find an example in the manual! I tried this:

\node [shape=rectangle, thin, color=red, fill=red, fill opacity=0.4, minimum width=0.5599999999999998, minimum height=3.3999999999999995, above right] (A) at (1.4000000000000001, -3.0999999999999996) {};

marked as duplicate by Ignasi, Claudio Fiandrino, ChrisS, T. Verron, Peter Jansson Feb 18 '14 at 10:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Does it have to be a node? If not you can do something like \filldraw [draw=blue,fill=red] (0,0) rectangle (3,4);? – Torbjørn T. Feb 17 '14 at 22:00
  • @TorbjørnT.: That's fine, but then how do I place another node using the anchor "above" or "below"? – Neil G Feb 17 '14 at 22:01
  • Well, that would be a reason for having it as a node I guess. You would have to use explicit coordinates (or a coordinate calculated from the corners) instead of referring to the node name. – Torbjørn T. Feb 17 '14 at 22:04

You can use the fit library:



  inner sep=0pt,
\coordinate (A) at (2,3);
\coordinate (B) at (-3,4);
\coordinate (C) at (0,2);
\coordinate (D) at (-5,6);
\coordinate (E) at (5,-2);
\node[myrect={(A) (B)}] {}; 
\node[myrect={(C) (D)},draw=cyan,rounded corners] {}; 
\node[myrect={(A) (E)},draw=cyan,fill=orange,line width=2pt] {}; 
\foreach \Coord in {A,B,C,D,E}
  \node[circle,fill,inner sep=1.5pt,label=\Coord] at (\Coord) {};


enter image description here

  • One should note that the fit node will add a (potentially invisible) border, in addition to any inner sep. To use the node's anchors later on, instead of drawing it, one should use inner sep=0pt,line width=0pt. – Georges Dupéron Feb 9 '16 at 16:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.