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);

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?

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

  \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]
    \draw (0,0) circle[radius=2pt];
  \begin{scope}[shift = {(center|-offset)}]
    \draw (0,0) circle[radius=4pt];

y-shifted circles

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.