22

I want to draw some round-ended rectangles to use as labels, so I thought a filled arc either end would work (silly me :-)

\draw [fill](0,0) arc[radius=5pt,start angle= 90,end angle=270];
\draw [fill](0,0) rectangle (40,-20);
\draw [fill](40,0) arc[radius=5pt,start angle=270,end angle=90];

But this places the right-hand end-cap above the rectangle, and facing the wrong way. I have obviously misunderstood the implications of the direction angles.

How do I draw a filled arc that points right, not left? (that is, D-shaped, the mirror of the first one).

  • If you load the shapes.misc TiKZ library, you can use the shape rounded rectangle which does exactly what I think you want. – cfr Nov 9 '14 at 20:31
  • I think you want a start angle of 90 and an end angle of -90 (because you want the curve to go in the opposite direction). – cfr Nov 9 '14 at 20:41
18

This shows how to adjust the angles in your original commands (I've scaled the rectangle down just so the labels show up better) and then demonstrates the use of rounded rectangle from the shapes.misc library.

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{shapes.misc, positioning}
\begin{document}
  \begin{tikzpicture}
    \draw (0,0) arc[radius=5pt,start angle= 90,end angle=270];
    \draw (0,0) rectangle (40pt,-20pt);
    \draw (40pt,0) arc[radius=5pt,start angle=90,end angle=-90];
  \end{tikzpicture}
  \begin{tikzpicture}
    \node (1) [draw, rounded rectangle] {rounded rectangle};
    \node (2) [below=of 1, draw, rounded rectangle, rounded rectangle west arc=0pt] {rounded rectangle};
    \node (3) [below=of 2, draw, rounded rectangle, rounded rectangle east arc=0pt] {rounded rectangle};
  \end{tikzpicture}
\end{document}

rounded rectangles - multiple ways

  • Thank you...I didn't even check the documentation for that because I thought it was too unlikely a shape to have been considered! – Peter Flynn Nov 9 '14 at 20:44
  • @PeterFlynn There are some weird and wonderful shapes in the shapes library. Who would have thought that there would be specific shapes for magnetic tape and chamfered rectangle shapes, for example? – cfr Nov 9 '14 at 20:48
34

If people come to this question via Google (like me) and want to get only a rectangle with rounded corners:

\draw[rounded corners] (0, 0) rectangle (4, 1) {};

This is an empty rectangle with rounded corners. The rectangle is from (0, 0) - the lower left corner - to (4, 1) - the upper right corner.

  • +1 Exactly what I needed. Thanks – Joseph R. Feb 7 at 15:58
19

Why not using rounded corners locally/globally on the path?

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw
  (0,0) {[rounded corners=15pt] --
  ++(2,0)  -- 
  ++(0,1)} --
  ++(-2,0) --
  cycle;
\draw[rounded corners=15pt]
  (4,0) rectangle ++(2,1);
\end{tikzpicture}

\end{document}

enter image description here

  • @Gonzalo Mendina What do -- and plus plus do – Vaibhav Nov 10 '14 at 4:02
  • @gonzalo Medina please how to write under it ? – Vrouvrou Mar 26 '18 at 19:29
2

A PSTricks solution:

\documentclass{article}

\usepackage{pstricks}

\begin{document}

\begin{pspicture}(2.6,2.8)
  % right end round
  \psline(2.2,2.8)(0,2.8)(0,2)(2.2,2)
  \psarc(2.2,2.4){0.4}{270}{90}
  \rput(1.3,2.4){Text~C}
  % left end round
  \psarc(0.4,1.4){0.4}{90}{270}
  \psline(0.4,1)(2.6,1)(2.6,1.8)(0.4,1.8)
  \rput(1.3,1.4){Text~B}
  % both ends round
  \psarc(0.4,0.4){0.4}{90}{270}
  \psline(0.4,0)(2.2,0)
  \psline(0.4,0.8)(2.2,0.8)
  \psarc(2.2,0.4){0.4}{270}{90}
  \rput(1.3,0.4){Text~A}
\end{pspicture}

\end{document}

output

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.