# Draw a rectangle with rounded ends in TikZ

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


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, 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

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 Feb 7, 2019 at 15:58
• Also works with \node[rectangle, rounded corners] Apr 2, 2020 at 19:59
• 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). Sep 7, 2022 at 14:54
• 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

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);
\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}


• 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
• @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

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}


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

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}


\draw[rounded corners](0,0)--(5,0)--(5,10)--(0,10)--cycle;

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