# Using coordinate expressions in scope transforms

Coordinate computation is powerful, especially with the positioning library. I would like to be able to leverage this relative calculation to compute, e.g., xshift and yshift terms for a scope or other sub-part of a figure, but I can't see how to easily access the components of a coordinate or perform other general computation in the context of applying keys.

For example,

…
% assume <something> has non-0 x coordinate, so offset does too - I don't want to shift horizontally at all
\coordinate[below = of <something>] (offset)
\begin{scope}[yshift = <y component of (offset)>]
\draw (0,0) rectangle (1,1);
\end{scope}


In this case, I'm using simple relative positioning below = of <something> to compute a vertical offset. I'd like to be able to use this vertical offset to shift the coordinate system of the sub-drawing in the defined scope.

I realize it's possible to pass an unadorned (coordinate name) directly to the 2D shift key, but none of the transform keys (shift included) seem to parse any math, even with the calc library. As a result, it's difficult to express anything nontrivial in-place using these keys.

What is the most straightforward way to do something like I sketched in the above code, specifying a yshift using the y dimension of a named coordinate?

• shift={(0,0|-offset)}? – Qrrbrbirlbel Oct 16 '13 at 2:19
• @jrk, did Qrrbrbirlbel's suggestion help you? If so, self-answers are good, so this information can be useful to future visitors. If not, please edit your question to include a complete minimal working example (MWE). – Paul Gessler Mar 1 '14 at 22:41

Here are two methods:

• Use \path (offset);\pgfgetlastxy{\xcoord}{\ycoord}; to get the y-dimension
• Shift by shift = {(center|-offset)} or shift = {(0,0|-offset)} if it's relative to (0,0), as suggested by @Qrrbrbirlbel

Illustrated example for both , the concentric circles are at the y-shifted position:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newdimen\xcoord
\newdimen\ycoord
\begin{document}
\begin{tikzpicture}
\node (center) at (0,0) {+};
\node[anchor=west] at (center) {Center};
\coordinate [above right = 3cm of center] (P);
\coordinate[below = of P] (offset);
\node at (offset) {$\bullet$};
\path (offset);% use the (offset) point
\pgfgetlastxy{\xcoord}{\ycoord};% extract x,y values of last used point
\begin{scope}[yshift = \ycoord]