How can I draw only parts of a rectangle? I want to omit a small part of the rectangle to put some text in. As I'm using various complex rectangles, I do not want to construct own "open rectangles".

Is there a way to do this? Maybe similarly to using an arc?

Currently, I'm using

        \draw[rounded corners=3pt] (-5,-5) rectangle (5,5);
        \node at (0,5) {text with line in the middle from rectangle};

I have already tried

to clip the rectangle using an arc or leaving out some part of the rectangle using How can I invert a 'clip' selection within TikZ?, but both got too complex, fragile and did not work. There must be an easy way!?


Since there are other drawings beneath, using filling color beneath the text is no solution. The following example is a simple one, in other pictures there is even more "lively a background" behind the text... exemplary rectangles


Your question is not very clear.

Maybe the following code will help you:

  % first solution
  \node (label) at (0,5) {text with line in the middle from rectangle};
  \draw[rounded corners=3pt]
  (label) -| (-5,-5) -| (5,5) -- (label);

  % second solution (with filled rectangle and node)
  \node (label) at (0,4)
  {\phantom{text with line in the middle from rectangle}};
  \draw[rounded corners=3pt,fill=red!10]
  (label) -| (-4,-4) -| (4,4) -- (label);
  \node[draw,fill=lime!10,rounded corners=3pt] (label) at (0,4)
  {text with line in the middle from rectangle};

enter image description here

  • I think (label) -| (-5,-5) -| (5,5) -- (label); would suffice for input labor. But I think the idea is to have a nonclosed rectangle as arc to a circle though I think best is to make a node shape. – percusse Sep 4 '12 at 21:10
  • Using `||' and '-|' is a good suggestion. But I update my answer. I don't understand your second sentence... – Paul Gaborit Sep 4 '12 at 21:14
  • 1
    I meant when a circle is not completed as a closed path it's an arc and there is a command for that. As far as I understand OP is looking for that analogy for the rectangle. – percusse Sep 4 '12 at 21:18
  • @PaulGaborit with your solution, using fill for the rectangle. the text will be partially covered; I think the OP wants some easy equivalent for something like the following code produces \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node (label) at (0,5) {\phantom{text with line in the middle from rectangle}}; \draw[rounded corners=3pt,fill=red!20] (label) -| (-5,-5) -| (5,5) -- (label); \node at (0,5) {text with line in the middle from rectangle}; \end{tikzpicture} \end{document} – Gonzalo Medina Sep 4 '12 at 21:26
  • Maybe... I add your suggestion. – Paul Gaborit Sep 4 '12 at 21:28

May be append after command option could help you. It allows to place all nodes and draw only some part of the border. It's only a partial solution because If you want to fill them you need to use several overlays. I hope somebody will provide a better solution.

In any case here you have an example:


\draw node[label={[name=mylabel,label distance=-2mm]above:label},
    append after command={[rounded corners]
(b) {My first rectangle};

\draw node[minimum width=3cm,minimum height=3cm,align=center,
    append after command={(mylabel.north-|c.west)|-(c.north east)|-(c.south west)--(b.south-|c.west)},
(c) at (2,1) {My second rectangle};

enter image description here


My final solution

I accepted Paul Gaborit suggestion and that I need to draw rectangles by hand, instead of using something like (0,0) rectangleArc (30:360:1cm). So I ended up with:



        \node[text=black, opacity=0.45, anchor=west] (label) at (#2+0.01, #3-0.01) {#4};%
        \node[text=#1, anchor=west] at (#2,#3) {#4};%
        \draw[#1, rounded corners=3pt]
        (label) -| (#5,#6) -| (#7,#3) -- (label);


The whole picture now looks like this:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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