Draw a rounded corner rectangle in LaTeX using Tikz
Let’s learn how to draw a rounded corner rectangle with Tikz in LaTeX.
\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[rounded corners=20pt, thick] (0,0) rectangle (4,2); \end{tikzpicture} \end{document}
Output:
Here, I am using rounded corners=20pt
so the radius of the rectangle corners becomes 20pt. You can change this value according to your needs.
Then in the second parameter, I am using thick
. This is the border thickness. You can make it thin
or ultra thick
. These are pre-defined thicknesses. If you want to customize the thickness you can use:
line width=1.5pt
. It does not matter if you are using this parameter in the first place or second. You can do it like this:
\draw[rounded corners=20pt, line width=1.5pt]
A specific corner rounded in Tikz (Top Right corner only)
If you want to make a specific corner rounded using Tikz, you can draw a straight line and only make angular corners for your rectangle where it needs to be.
\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[line width=1.5pt] (0,0) -- (4,0) % Bottom edge -- (4,1.5) % Right edge up to where the rounding starts arc[start angle=0, end angle=90, radius=0.5cm] % Round the top-right corner -- (0.5,2) % Top edge (shortened by the rounding radius) -- (0,2) % Continue to the top-left corner -- cycle; % Left edge and close \end{tikzpicture} \end{document}
Output:
You can use the same logic for other corners as well.
I know this might be tough but you can do it. Let me know if you face any issues in the comment section below.
Leave a Reply