I have a rectangular style in latex and I want to fix the size of that. however, in the setting I can only set the minimum width and minimum height. Here is my style;

direct/.style={rectangle, minimum height =4 cm, rounded corners=4.4mm, minimum width=10 cm, fill=red!15, draw,thick,},

And then the size of this shape change based on the text in it. I want a constant rectangular. Do you know how I can solve this? Thanks

  • You are trying to draw a rectangle as a style of a node. node have a content to respect {} and thus must keep a size that contains that content. If you want a rectangle of exact height and width, you need to draw it as a path aka: \draw (A) rectangle (B) where A and B are nodes or coordinates.
    – anis
    Commented Feb 10, 2023 at 8:33

3 Answers 3


Anis' comment already tells you a lot. Just as add-on, I want to mention few possibilities if you really have content in your nodes and would like to have a homogeneous size. Without knowing your context and needs, mine is just speculation. Hopefully it serves as starting point.

  • You could use text width set to the minimum width (or slightly less) and let TikZ wrap your text (to change alignment, use the align key). This approach prevents the node content, if too long, to exceed the minimum desired width, but it does not prevent the same for the height, though.
  • You could then define a style to scale by hand the font, using e.g. the relsize package. You would use this style to manually reduce the node content when needed. This requires some fine tuning, though.
  • You could automatise the previous approach, by getting inspired here. I took one of the answers there in my example below. The idea is to automatically scale the node content to fit a box that in turn fits your node desired size.

As general advice, you might have a look in general to the PGF manual, maybe starting with the minimal introduction to TikZ to get a general overview. Both documents are here.

Here a proof of concept.



        minimum height=\fixedHeigth,
        minimum width=\fixedWidth,
        rounded corners=4.4mm,

% Taken from https://tex.stackexchange.com/a/26004/128737

        \node [direct] (N1) {Short};
        \node [direct, below = of N1] (N2) {
            Very long text whose width exceeds the specified minimum
            width of the node and hence the desired shape
        \node [direct, below = of N2, text width=10cm] (N3) {\lipsum[1-2]};
        \node [direct, below = of N3, text width=10cm, fontsmaller=3.5] (N4) {\lipsum[1-2]};
        \node [direct, below = of N4, text width=10cm] {



Another option is to typeset the text in a fixed shape, and telling nothing about it to TikZ. If the text will not fit, it will leak...

\newcommand{\FixedSizeText}[3]{% width, height
    \tikzset{my rect/.style={
        rectangle, draw=red, inner sep=0pt, rounded corners},
    \path (0,0) node [my rect]{\FixedSizeText{3cm}{2cm}{A little text}}
        (3,0) node [my rect]{\FixedSizeText{3cm}{2cm}{A little text}}
        (0,-3) node [my rect]{\FixedSizeText{3cm}{2cm}{Longer text that will arguably not fill in the minipage, and so the thing will be leaked around}}

enter image description here


Perhaps You search for something like this (equals boxes, not the same quantity of text inside): enter image description here




    \begin{tcolorbox}[enhanced,fit to height=8cm, width=10cm,
        colback=gray!35!black!20!white,colframe=gray!75!black,title=Fit box (8cm),
        drop fuzzy shadow]
    \begin{tcolorbox}[enhanced,fit to height=8cm, width=10cm,
        colback=gray!35!black!20!white,colframe=gray!75!black,title=Fit box (8cm),
        drop fuzzy shadow]

You must log in to answer this question.

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