2

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

Viesturs
  • 7,895

1 Answers1

2

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

enter image description here

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

js bibra
  • 21,280
  • How could I provide color as an argument to this tikzset? – Viesturs Oct 23 '20 at 13:23
  • 1
    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 – js bibra Oct 23 '20 at 14:02
  • 1
    ... or in the code of the rect key, you can replace blue by #1 then use, rect=blue, rect=red or rect=orange. – Paul Gaborit Oct 23 '20 at 15:07