Setting “cm” as default unit of measures in tikzpicture

Is there a way in order to avoid to manually setting the unit of measures in every line of a tikzpicture code? For instance there is a way in order to just write xshift=+3 instead of xshift=+3cm?

• it is already in cm by default – percusse Dec 27 '17 at 23:06
• @percusse Yes, but xshift/yshift requires a dimension, so a unitless number is read as pt. – Torbjørn T. Dec 27 '17 at 23:07
• @TorbjørnT. Yes that one *requires*(!) a dimen so there is no escape from that. In other places where it is optional cm is the default unit – percusse Dec 27 '17 at 23:10

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[myx/.style={xshift=#1*1cm}, myy/.style={yshift=#1*1cm}]
\draw[style=help lines] (-2,-2) grid[step=1] (1,1);
\draw ([myx=-1,myy=-1]0,0) -- (0,0);
\end{tikzpicture}
\end{document}


• Thank you! However, for instance, if you use myx=+1 it will not work. To solve the problem: myx/.style={xshift=(#1)*1cm} – Andrea Leo Dec 28 '17 at 10:29
• @AndreaLeo Don't use + as the first char of calculations for positive numbers. It might have strange effects. PGF treats that as don't worry there is no calculation happening, parse it directly signal. – percusse Dec 28 '17 at 10:45

You can use

shift={(3,0)}


instead of xshift=3cm.

It's not less verbose, but it does mean that shifts will change if you change the unit vectors.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [shift={(-0.5,-0.5)}] (0,0) grid (4,1);

\node {a};
\node [shift={(3,0)}] {b};
\end{tikzpicture}
\end{document}