TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to specify the width and height of a tikzpicture? To scale a tikzpicture I use the option scale, i.e. for instance

\begin{tikzpicture}[scale = 2]

I tried to change the width and height as

\begin{tikzpicture}[width = 2in, height = 3in]

but this gives me an error "I do not know the key /tikz/width".

share|improve this question
With a tikzpicture, you specify all the coordinates, so the picture is as big as needed. With pgfplots, the size of the plot is computed, so you can specify the width and height options to the axis environment within a tikzpicture. – Peter Grill Oct 5 '12 at 17:52
@PeterGrill Yes. I am not using pgfplots though. I should have not tagged the question with pgfplots. I have removed the tag now. – user1876 Oct 5 '12 at 18:29
Ok, but I was trying to explain why it does not make sense to specify the height/width of a tikzpicture, but does make sense to be able to specify the height/width of a pgfplots graph. With a tikzpicture only the scale option makes sense. – Peter Grill Oct 5 '12 at 18:31
@PeterGrill Ok. Yes I understood. – user1876 Oct 5 '12 at 18:46
Related: tex.stackexchange.com/questions/6388/… – Torbjørn T. Oct 5 '12 at 20:43

Use resizebox outside of tikzpicture.


For example:

\documentclass [tikz] {standalone}

\begin {document}
    \begin {figure}
        \resizebox {\columnwidth} {!} {
            \begin {tikzpicture}
                \node [draw] (my node 1) {my node 1};
                \node [draw, anchor = west] (my node 2) at (my node 1.east) {centro};
                \node [draw, anchor = west] at (my node 2.east) {my node 3};
            \end {tikzpicture}
    \end {figure}
\end {document}
share|improve this answer
But in this solution also things like line widths and font sizes get resized, right? In this case graphics would no longer stay consistent when they have to be resized by different amounts. – Benedikt Bauer Oct 5 '12 at 18:04
I agree with you, but doing so is the purpose of the question, no? – tecepe Oct 5 '12 at 18:37
Not sure about that. I could imagine that the intention is that you can draw your graphic in any relative coordinates or units of measure such that it is automagically sized to a certain width or height. Of course this should happen in a way that the line widths and fonts keep their sizes. Theoretically you could achieve that by drawing everything in units of a variable \picturewidth or so, but this would be rather unconvenient. – Benedikt Bauer Oct 5 '12 at 18:51
Oh I forgot before: I think the idea is that you don't have to care that much about how large your graphic will get at the end. Instead you can just start drawing and will in most cases end up with a graphic that has the desired width or height. – Benedikt Bauer Oct 5 '12 at 19:12

Converting my comments to an answer as I think question is more about specifying a height, width option rather than how to scale picture to get it to be of the appropriate size.


It does not make sense to specify the height/width of a tikzpicture, but does make sense to be able to specify the height/width of a pgfplots graph. With a tikzpicture only the scale option makes sense.


Within a tikzpicture, you specify all the coordinates, so the picture is as big as needed. So, if you say draw a line from (0,0) to (4,0) you get a line that is 4cm long (cm being the default unit of measurement). So applying a scale factor of say 0.5 would make this line 2cm long. But what does it mean to say draw a line of 4cm in a box that is 2cm wide?
Perhaps you want to only view the parts of the picture in the first 2.0cm, then you are clipping the picture, and there is a macro to do that called \clip.

Now, by default the units are assumed to be cm, so (4,0) corresponds to 4cm in the x-direction. There is an option to specify to use different units with the x=<length>, but again this is scaling.

However, with graphing packages such as pgfplots, the size of the plot is computed, and one can make a determination as to what physical size corresponds to a unit in each of the axis directions. So, for the case of plotting graphs it makes perfect sense to have options to specify the height, or width of the graph.

So, in my mind it does not make sense to have options to specify the height or width of a tikzpicture but does make sense to be able to apply a scale option. For graphing environments such as pgfplots it makes prefect sense to be able to specify a height, and width, and these are available in the axis environment options.

share|improve this answer
I don't understand. Why wouldn't it make sense to draw the picture, then scale it by whatever factor gives width = \textwidth? – Chris Chudzicki Nov 4 '13 at 1:22
@mrc: Perhaps my answer was not clear: It does make sense to scale a tikzpicture. – Peter Grill Nov 4 '13 at 2:12
I'm sure I misunderstood your answer. I know you said scaling makes sense, but why not scaling by specifying what the width should be after the picture is scaled? – Chris Chudzicki Nov 4 '13 at 2:31
@mrc: Sorry for the delayed response. When you specify to tikz that a picture should consist of a horizontal line that is 1cm long, and a scale=0.5, and that the width of the picture be 3cm, which one is supposed to determine how wide the picture is? Perhaps what you are asking about is How to scale a tikzpicture to \textwidth. – Peter Grill Jan 12 '15 at 20:58
I certainly wouldn't expect to be able to specify scale=0.5 and width=3cm simultaneously. The question you linked to is interesting. Still, I would have expected that tikz would accept keys like width=0.8\textwidth . . . the behavior I would expect is that tikz would draw the unscaled picture, then scale it proportionally so that the width has the desired value. I didn't look too carefully---that seems to be what is described in the question you linked to---I am just confused about why that isn't the default behavior of tikz. – Chris Chudzicki Jan 13 '15 at 23:02

This uses part of my answer to this question: first, the image is drawn virtually to get the scaling factors, then it is drawn using these factors.



\newcommand{\getsizes}[2]% width, height
{   \path (current bounding box.south west);
    \path (current bounding box.north east);

\newcommand{\xyscaledtikz}[3]% draw commands, width, height
{ \smash{\vphantom{

\draw[rotate=30,left color=red,right color=blue] (0,0) rectangle (5,5);






enter image description here

share|improve this answer
This is the correct answer. Very good. If you just want to scale to a given height but leave the aspect ratio, replace xscale=\xsca by xscale=\ysca. The same applies for defining width and compute height automatically. – kap Sep 15 '14 at 12:13

Just add


after axis as described in the pgfplots manual, page 232.

Note that the manual describes TikZ commands there.

Also which version are you using? I had problems with an older version of LaTeX where TikZ/PGF did not know half the commands that are in use now.

share|improve this answer
...but this is what the OP suggests doesn't work... – Werner Jan 31 '14 at 21:28
also this is pgfplots syntax and TikZ doesn't know these options. – percusse Jan 31 '14 at 23:01
this works for me :) – LCFactorization Jul 11 '14 at 23:49

Try something like \draw[use as bounding box] (0,0) rectangle (3,2) or(\path) if you don't want to draw) to change the aspect ratio of your image, then use scale to change the size. But I agree with Benedikt and Peter that scaling the dimensions separately will warp the picture you are trying to draw, and that you should probably not be looking for such an option in the first place.

share|improve this answer

I know this is a rather old post, but it did show up in google as a first result, so I want to add one solution here that is still missing.

If you have your tikzpicture in a individual file, like in Tom Bombadil's answer, you can use the package tikzscale. Then in your document you can use


The file mytikzpic.tikz only includes the tikzcode:


%some tikz code


tikzscale uses an iterative approach to scale the picture to the desired size, thereby compiling the picture code several times. This will lengthen the compile time of the document. It works well with tikz externalize library though, with which one can save most of that overhead again.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.