47

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).

2
  • 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, 2014 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, 2014 at 20:41

5 Answers 5

105

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.

5
  • 1
    +1 Exactly what I needed. Thanks
    – Joseph R.
    Feb 7, 2019 at 15:58
  • 3
    Also works with \node[rectangle, rounded corners] Apr 2, 2020 at 19:59
  • 2
    Worth noting you can use an argument for the radius of the corners: \draw[rounded corners=1cm] (0, 0) rectangle (4, 1) {}; (surprisingly, by default the unit appears to be pt rather than cm).
    – varkor
    Sep 7, 2022 at 14:54
  • 1
    I'm using overleaf and when I try this (or any other solutions), I keep getting the error "Package pgfkeys Error: I do not know the key '/tikz/roundedcorners' and I am going to ignore it." Any idea why that is?
    – mapf
    Nov 23, 2022 at 18:09
  • Worth checking whether shapes is in your \usetikzlibrary directive, eg \usetikzlibrary{svg.path,positioning,shapes,calc,arrows.meta}
    – Adam Burke
    May 9, 2023 at 6:53
31

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

2
  • Thank you...I didn't even check the documentation for that because I thought it was too unlikely a shape to have been considered! Nov 9, 2014 at 20:44
  • 1
    @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, 2014 at 20:48
29

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

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

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

1
\draw[rounded corners](0,0)--(5,0)--(5,10)--(0,10)--cycle;
1
  • or a bit shorter: \draw[rounded corners] (0,0) |- (5,10) |- cycle; ... , anyway +1
    – Zarko
    May 31, 2022 at 17:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .