Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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) {};
share|improve this question

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.

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

1 Answer 1

up vote 8 down vote accepted

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

share|improve this answer
Very clever! Thank you. – Neil G Feb 17 '14 at 22:07

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