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?

3
  • 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
4

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

2
  • 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
6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.