2

I have noticed that when I use the scale option in a TikZ picture, the values of minimum width and minimum height are not scaled. A MWE (both pictures are exactly the same, only the scale parameter changes):

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1]
    \draw[dotted] (-1, 0) -- (4, 0);
    \draw[dotted] (-1, 2) -- (4, 2);
    \draw[dotted] (0, -1) -- (0, 3);
    \draw[dotted] (3, -1) -- (3, 3);
    \node[minimum width=3cm, minimum height=2cm, draw] at (1.5, 1) {A box};
\end{tikzpicture}

\hspace{1cm}

\begin{tikzpicture}[scale=2]
    \draw[dotted] (-1, 0) -- (4, 0);
    \draw[dotted] (-1, 2) -- (4, 2);
    \draw[dotted] (0, -1) -- (0, 3);
    \draw[dotted] (3, -1) -- (3, 3);
    \node[minimum width=3cm, minimum height=2cm, draw] at (1.5, 1) {A box};
\end{tikzpicture}

\end{document}

Which produces:

Bad scaling

The problem would be fixed use transform shape on the picture; however, that would change the size of the text, too. Is not there any way to have coordinate-scalable boxes?

javidcf
  • 329

1 Answers1

2

The scaling options applies to the whole node. This means that even the text is scaled and I don't think there is an option to avoid it.

However scaling does not apply to \draw. Attaching a node to a draw command will render the text immune to the scale command.

Output

enter image description here

Code

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[scale=1]
    \draw[dotted] (-1, 0) -- (4, 0);
    \draw[dotted] (-1, 2) -- (4, 2);
    \draw[dotted] (0, -1) -- (0, 3);
    \draw[dotted] (3, -1) -- (3, 3);
    \draw (0,0) rectangle (3,2) node[midway] {a box};
    %\node[minimum width=3cm, minimum height=2cm, draw] at (1.5, 1) {A box};
\end{tikzpicture}

\hspace{1cm}

\begin{tikzpicture}[scale=2]
    \draw[dotted] (-1, 0) -- (4, 0);
    \draw[dotted] (-1, 2) -- (4, 2);
    \draw[dotted] (0, -1) -- (0, 3);
    \draw[dotted] (3, -1) -- (3, 3);
    \draw (0,0) rectangle (3,2) node[midway] {a box};
    %\node[minimum width=3cm, minimum height=2cm, draw] at (1.5, 1) {A box};
\end{tikzpicture}
\end{document}
Alenanno
  • 37,338