# TikZ: rounded rectangle specifying dimensions

I am studying Draw a rectangle with rounded ends in TikZ but it appears that the dimensions of the rectangle are dependent on the text in the node.

How can I draw a rounded rectangle specifying dimensions:

1. in a node

How to change \node (1) [draw, rounded rectangle] {some text};?

2. not in a node

How to change \draw (0,0) rectangle (4,4);

• Please give a fully compilable code. Oct 23, 2020 at 9:28
• \draw[rounded corners](0,0)rectangle(4,4) work ! Oct 23, 2020 at 9:30
• tex.stackexchange.com/a/13588 for changing size of nodes. Oct 23, 2020 at 10:24
• @Viesturs if the answer meets your requirement you may like to accept and upvote Oct 23, 2020 at 17:00

## 1 Answer

This should point you in the correct direction -- you can experiment with the style

\documentclass{article}

\usepackage{tikz}

\begin{document}
\tikzset{
rect/.style={
font=\small,
top color=white,
bottom color=blue!25,
rectangle,
rounded corners,
minimum width=1em,
text width=2em,
draw=blue!75,
very thick,
align=center,
}
}
\tikz\node[draw, rect]at (0,0)(){A};
\tikz\draw[rect] (3,0) rectangle(4,4);
\end{document}

• How could I provide color as an argument to this tikzset? Oct 23, 2020 at 13:23
• simply edit top color=#1 and bottom color=#2 and draw=#3 then in the code in the square brackets add colors with comma separated [draw, rect, red, blue] etc Oct 23, 2020 at 14:02
• ... or in the code of the rect key, you can replace blue by #1 then use, rect=blue, rect=red or rect=orange. Oct 23, 2020 at 15:07