Graphics, Figures & TablesAbout the use of [shift=({xvalue,yvalue})]

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
tush
Posts: 11
Joined: Fri Feb 22, 2019 2:54 pm

About the use of [shift=({xvalue,yvalue})]

Post by tush »

I am following the advice in this answer, about shifting the values of an already declared node in a tikz picture.

Code: Select all

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \node (A) at (0,0) {};
    \node (B) at (-4,2) {};
    \draw[black,fill=black] (B) circle (1pt);
    \draw[black,fill=black] (A) circle (1pt);
    \draw[->] (B) -- ([shift=({1,1})]A);
    \draw[->] (B) -- ([shift=({1,1})]B);
\end{tikzpicture}
\end{document}
I expected the output to be two arrows. One from (B) to (x_A+1, y_A+1) and the other from (B) to (x_B+1,y_B+1).

But instead I get an arrow from B to A, and an arrow from B to B.

Why is that?

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Bartman
Posts: 366
Joined: Fri Jan 03, 2020 2:39 pm

About the use of [shift=({xvalue,yvalue})]

Post by Bartman »

In this case, it seems that you need to access the coordinate through the node's anchor

Code: Select all

\draw [->] (B) -- ([shift={(1,1)}]A.center);
\draw [->] (B) -- ([shift={(1,1)}]B.center);
or use the \path command with the edge operation instead.

Code: Select all

\documentclass[tikz, border=2pt]{standalone}
\usetikzlibrary{arrows.meta}

\tikzset{>=Stealth}

\begin{document}
% with nodes
\begin{tikzpicture}[nodes=circle]
    \filldraw [radius=1pt]
        circle node (A) {}
        (-4,2) circle node (B) {}
    ;
    \path [->] 
        (B) edge ([shift={(1,1)}]A)
        (B) edge ([shift={(1,1)}]B)
    ;
\end{tikzpicture}
% without nodes
\begin{tikzpicture}
    \filldraw [radius=1pt]
        circle coordinate (A)
        (-4,2) circle coordinate (B)
    ;
    \path [<-, shorten >= 5pt]
        (A) +(1,1) edge (B)
        (B) +(1,1) edge (B)
    ;
\end{tikzpicture}
\end{document}
tush
Posts: 11
Joined: Fri Feb 22, 2019 2:54 pm

About the use of [shift=({xvalue,yvalue})]

Post by tush »

Thanks a lot!

(I prefer your first suggestion).
Post Reply