0

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. – AndréC Oct 23 at 9:28
  • 2
    \draw[rounded corners](0,0)rectangle(4,4) work ! – AndréC Oct 23 at 9:30
  • tex.stackexchange.com/a/13588 for changing size of nodes. – Torbjørn T. Oct 23 at 10:24
  • @Viesturs if the answer meets your requirement you may like to accept and upvote – js bibra Oct 23 at 17:00
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}
| improve this answer | |
  • How could I provide color as an argument to this tikzset? – Viesturs Oct 23 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 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 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.