254

It seems that the scale option scales only the length of lines, but not the size of texts. For instance, 1 and true and not scaled in the following code.

\begin{tikzpicture}[thick, scale=0.6]
\draw [dashed] (1,12) -- (11,12);
\node[above] at (4,11) {1}; \node[above] at (8,11) {true};
\end{tikzpicture}

Could anyone tell me how to scale everything together within a tikzpicture? Thank you very much!

PS: It is a picture in a presentation with Beamer.

4
  • 8
    Seems to be a duplicate of Correctly scaling a tikzpicture. Please confirm. Aug 29, 2011 at 11:21
  • 2
    @Martin: I agree. Didn't know we already had that one! Aug 29, 2011 at 11:30
  • 3
    @MartinScharrer It is true that the question is similar, but this question focuses on text. And the answer here is different from the question you cite.
    – jarauh
    Aug 24, 2016 at 14:37
  • 4
    Does this answer your question? Correctly scaling a tikzpicture
    – clel
    Jul 14, 2021 at 15:32

5 Answers 5

314

There are a few things that scaling doesn't affect; the most noticeable are node sizes and line widths. In a simple picture, it isn't hard to adjust the line width accordingly but the nodes can be difficult. It is possible to force a node to be scaled: put the scale option directly in the node's attributes. Thus \node[above,scale=0.6] at (8,11) {true}; would scale the node. This is a bit annoying to put on every node, so there's an every node style that can be used to do this. Thus:

\begin{tikzpicture}[thick,scale=0.6, every node/.style={scale=0.6}]

Even so, you'd still have to remember to change two things each time here if you wanted to change the scale factor. Fortunately, there's a key transform shape which means that the current transformation is applied to the node. The danger with using this is that this will also apply any rotations that happen to be in effect to the node (normally only translations are applied). If you don't have any rotations, then:

\begin{tikzpicture}[thick,scale=0.6, every node/.style={transform shape}]

will do just fine.

If you do have or worry about those rotations (or for anyone else interested) it would be simple to set a global scale key to fix this:

\tikzset{global scale/.style={
    scale=#1,
    every node/.style={scale=#1}
  }
}

Back to the "normal" solutions. Here's the various solutions:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\framebox{\begin{tikzpicture}[thick]
\draw [dashed] (1,12) -- (11,12);
\node[above] at (4,11) {1}; \node[above] at (8,11) {true};
\end{tikzpicture}}

\framebox{\begin{tikzpicture}[thick, scale=0.6]
\draw [dashed] (1,12) -- (11,12);
\node[above] at (4,11) {1}; \node[above] at (8,11) {true};
\end{tikzpicture}}

\framebox{\begin{tikzpicture}[thick, transform canvas={scale=0.6}]
\draw [dashed] (1,12) -- (11,12);
\node[above] at (4,11) {1}; \node[above] at (8,11) {true};
\end{tikzpicture}}

\framebox{\begin{tikzpicture}[thick,scale=0.6, every node/.style={scale=0.6}]
\draw [dashed] (1,12) -- (11,12);
\node[above] at (4,11) {1}; \node[above] at (8,11) {true};
\end{tikzpicture}}

\framebox{\begin{tikzpicture}[thick,scale=0.6, every node/.style={transform shape}]
\draw [dashed] (1,12) -- (11,12);
\node[above] at (4,11) {1}; \node[above] at (8,11) {true};
\end{tikzpicture}}

\end{document}

I put the \frameboxs in because if you count carefully, you'll see that the third example isn't there! In fact, it ended up somewhere at the top of the page, outside what the standalone package thought the page was. So it got clipped out.

scaled pictures

3
  • Sorry for necro, but is there a way to scale the coordinates as well? \node[above,scale=0.6] at (8,11) {true}; I would like the (8,11) to also scale. They don't in my case when I do \node [scale=1.5] (label) at (13,28.5) {Foo};, only the size of "Foo" scales.
    – Normadize
    Mar 28, 2019 at 21:11
  • Further to my comment above, curiously, it does scale the coordinates for a line drawn with \draw, but not the coordinates of \node, i.e. the following is scaled as (I) expected, in both coordinates and size, \draw [line width=1pt, dotted, color=red, scale=\@myscale] (17.5,0.1) -- (17.5,35.17); but the following is only scaled in size, not also in coordinates, \node [scale=1.5] (label) at (13,28.5) {Foo};. if it matters, my tikz figure has \begin{tikzpicture}[every node/.style={anchor=south west,inner sep=0pt},x=1mm, y=1mm]
    – Normadize
    Mar 28, 2019 at 21:23
  • @Normadize I think I know what's going on with that, but comments aren't really suited to answering questions. I suggest that you ask a fresh question (link to this one if you like) with a MWE. Mar 28, 2019 at 21:39
33

If you want to scale everything in your tikz picture, you could also place it within a \scalebox or \resizebox (from package graphics/x)

Examples:

\scalebox{0.6}{
[Your tikz goes here]
}
\resizebox{.75\textwidth}{!}{
[Your tikz goes here]
}

This will also work for nodes, text, etc and contrarily to transform canvas it will not beam your picture to places no one would have ever thought of, which happened to me once.

5
  • 2
    this gives a control sequence error when wrapped on tikzpicture environment
    – develarist
    Apr 27, 2020 at 3:07
  • @develarist I just ckecked that and it didn't. Obviously, you would exchange "[Your tikz goes here]" for a complete and working tikz-picture... which I did several times without any errors. Apr 28, 2020 at 13:35
  • 4
    yes i put a tikzpicture environment there that renders fine stand-alone, but putting resizebox on it gives the error. which tikz or pgf package does that command cone from
    – develarist
    Apr 28, 2020 at 15:03
  • 1
    I just found that you might have to \usepackage{graphix} which I include regularly so I didn't notice \resizebox could be a non basic command Apr 29, 2020 at 16:15
  • 3
    In my humble amateur latex user I think this should be the preferred answer, as the other solutions caused my nodes that used fit to be the wrong size when scaled to factors below 1 (this solution didn't). May 8, 2020 at 8:31
17

The transform canvas option scales everything, including text. Be aware that this may lead to the bounding boxes being wrong...

2
  • 1
    That is true, I tried \begin{tikzpicture}[thick, scale = 0.6, transform canvas={scale=0.6}], the size is really good, but it is no more in a good position, so what can I do with that?
    – SoftTimur
    Aug 29, 2011 at 10:45
  • @SoftTimur you shouldn't need to do both of transform canvas and scale. that will shrink it twice... Like I said, transform canvas will mess with the bounding box (where TeX thinks the picture is). I think "How to adjust position of a TikZ picture when using transform canvas" is a separate question...
    – Seamus
    Aug 29, 2011 at 11:01
5

For a matrix of nodes transform canvas works enough fine

\begin{figure}
%\shorthandoff{<>} 
\begin{tikzpicture}[thick, scale = 0.6, transform canvas={scale=0.6}]
\matrix (m) [matrix of math nodes,left delimiter=(,right delimiter=)]
 {
 0 &1 &0 &0 &0 &0 \\ 
 1 &0 &0 &0 &0 &0 \\        
 0 &0 &2 &0 &0 &0 \\        
 0 &0 &0 &1 &0 &2 \\       
 0 &0 &0 &0 &1 &0 \\        
 0 &0 &0 &1 &0 &1 \\        
 };

 \draw[color=purple,thick] (m-1-1.north west)  rectangle  (m-2-2.south east);
 \draw[color=purple,thick] (m-3-3.south east)  rectangle  (m-3-3.north west);
 \draw[color=purple,thick] (m-4-4.north west)  rectangle  (m-6-6.south east);

\end{tikzpicture}
%\shorthandon{<>} 
\end{figure}
-1

The package adjustbox can be used for that. It is rather straightforward to use and seems to be more robust and versatile compared to resizebox and scalebox.

2
  • How is it more robust/versatile compared to the alternatives? Or conversely how are resizebox and scalebox brittle or too specific for the job? Jul 12, 2022 at 19:38
  • I am not sure anymore about the details, as I posted this already some time ago. Possibly, I relied on the package description: ctan.org/pkg/adjustbox ("This allows for all forms of content including special material like verbatim content."). But not sure, how I came to the conclusion that this behavior is different with resizebox or scalebox.
    – clel
    Jul 14, 2022 at 13:25

You must log in to answer this question.

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