# Setting unit length in TikZ?

As I understand it, the basic unit length in TikZ is 1cm, so that for example

\draw (0,0) -- (1,0);


draws a line 1cm in length. What I want to do is to redefine that length so that all drawings in my document are a different size. Using ConTeXt, how can I do this?

• Ummm... discovered it myself soon after posting; it's \tikzset{every picture/.style={scale=1.5}} – Alasdair Apr 17 '11 at 10:21
• Please consider accepting my answer by clicking at the tick mark below the voting arrows at the top left side of the answer. This will mark the question as concluded. Thanks! – Martin Scharrer Apr 23 '13 at 18:30
• @Alasdair: Or, if you don't like Martin Sharrer's answer, write one of your own and accept it. – jvriesem Jan 6 '16 at 19:03

You can set the units length in TikZ for X, Y and even Z coordinates independently using the x, y and z keys:

\begin{tikzpicture}[x=2cm,y=1.5cm]
...


See the pgfmanual p.249 section 22.2 The XY- and XYZ-Coordinate Systems.

Note that TikZ actually doesn't has unit length, but uses vectors. The above keys therefore also accept (a,b) coordinates (which must be enclosed in { } to hide the ,). The X and Y unit vectors do not need to be orthogonal to each other. The above code is the short version of [x={(2cm,0cm)},y={(0cm,1.5cm)}].

You can the mentioned option scale as well, but I would prefer the above options. One difference will be that coordinates with explicit units are scaled as well with scale. For example (2cm,2) will be 3cm in both directions when scale=1.5 is set, but (2cm,3cm) with x=1.5cm,y=1.5cm.

One problem with the use of vectors is that you can't access the effective unit length even for the default setup of an XY (no Z) orthogonal coordinate system. I personally needed that for my tikz-timing package. You need to use PGF code for this: \pgfpointxy{1}{1} will give you the X and Y unit length as \pgf@x and \pgf@y. This length register will be overwritten by the next PGF or TikZ command.

• In case you want to make a triangular grid, it turns out that you shouldn't scale the x component of the y vector by the unit length. i.e. [x={(<unit length>,0)},y={(cos(60),<unit length>*sin(60))}] works, but [x={(<unit length>,0)},y={(<unit length>*cos(60),<unit length>*sin(60))}] is skewed. Or at least, in my attempts. – repurposer Nov 3 '15 at 17:09