Changing the default length unit in tikz

calculationscoordinateslengthstikz-pgf

Is there a way to change the default length unit in tikz to the ex unit? I have trouble while calculating complicated coordinates in tikz when I'm using the ex unit (I always get an error or a wrong result). However, as soon as I get rid of the length unit, I do more complicated computations with parenthesis involved and won't get any errors. I thought maybe if I can set ex to be the default length unit and drop it in the syntax, I can still work with this unit and won't run into the errors.

Best Answer

You can set the x and y vectors:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1ex, y=1ex]
    \draw[ultra thick, cyan] (0,0) -- (1cm,1cm);
    \draw[thick, red] (0,0) -- (1ex,1ex);
    \draw[thin, black] (0,0) -- (1,1);
\end{tikzpicture}
\end{document}

enter image description here

But notice that the ex unit is font-dependent, so it will change with the font in use outside the tikzpicture (which is probably what you want, but...)

Related Question