Draw a rectangle with rounded ends in TikZ
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.
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}
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}