3

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?

Andrea Leo
  • 1,011

2 Answers2

8

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.

output of code

\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}
Torbjørn T.
  • 206,688
5

Write your own shift

\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}

enter image description here

percusse
  • 157,807
  • 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