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

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

1 Answer 1

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}
3
  • How could I provide color as an argument to this tikzset?
    – Viesturs
    Commented Oct 23, 2020 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
    Commented Oct 23, 2020 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. Commented Oct 23, 2020 at 15:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .