根据节点 x 坐标计算 xshift

根据节点 x 坐标计算 xshift

有没有什么办法可以计算出节点的 x 坐标\begin{scope}[xshift=???]在哪里????

用例示例:我希望绘图位于每个节点的中心;在这里,我在每种情况下都选择了一个 x 坐标,但我希望它是从给定节点计算出来的。

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows,arrows,positioning,shapes,calc}
\begin{document}
\begin{tikzpicture}[node distance=5mm, auto,
       blockcolors/.style={
        % The rest
        thick,draw=black,
        top color=white,
        bottom color=black!10,
        font=\sffamily\small
    },
    block/.style={
        rectangle, minimum size=6mm, minimum height=10mm, minimum width=16mm,
        node distance=8mm,
        % The rest
        blockcolors,
        drop shadow
    },
    every label/.style={
        font=\sffamily\scriptsize
    },
    >=latex
    ]
\node (lions) [block] at (0,0) {lions};
\node (tigers) [block, right=of lions] {tigers};
\node (bears) [block, right=of tigers] {bears (oh my!)};

\draw[->] (lions) -- (tigers);
\draw[->] (tigers) -- (bears);

\foreach \xnode/\dx in {lions/0, tigers/2cm, bears/4cm} {
\begin{scope}[yshift=15mm, xshift=\dx]
    \draw[variable=\t,samples at={0,0.02,...,1}]
    plot (\t-0.5,{0.5*sin(2*3.14159*\t r)},0);
    \node (dot) [fill=black, circle, inner sep=0.25mm] at (0,0){};
    \draw[->] (dot) -- (\xnode);
\end{scope}
}

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

哦,我明白了,我只需要使用shift=(ynode -| xnode)节点ynode(或坐标)和我想要的 y 轴位置即可:

在此处输入图片描述

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows,arrows,positioning,shapes,calc}
\begin{document}
\begin{tikzpicture}[node distance=5mm, auto,
       blockcolors/.style={
        % The rest
        thick,draw=black,
        top color=white,
        bottom color=black!10,
        font=\sffamily\small
    },
    block/.style={
        rectangle, minimum size=6mm, minimum height=10mm, minimum width=16mm,
        node distance=8mm,
        % The rest
        blockcolors,
        drop shadow
    },
    every label/.style={
        font=\sffamily\scriptsize
    },
    >=latex
    ]
\node (lions) [block] at (0,0) {lions};
\node (tigers) [block, right=of lions] {tigers};
\node (bears) [block, right=of tigers] {bears (oh my!)};

\draw[->] (lions) -- (tigers);
\draw[->] (tigers) -- (bears);

\node (baseline) [fill=black, circle, inner sep=0.25mm, label={baseline}] at (-2cm,2cm){};

\foreach \xnode in {lions, tigers, bears} {
\begin{scope}[shift=(baseline -| \xnode)]
    \draw[variable=\t,samples at={0,0.02,...,1}]
    plot (\t-0.5,{0.5*sin(2*3.14159*\t r)},0);
    \node (dot) [fill=black, circle, inner sep=0.25mm] at (0,0){};
    \draw[->] (dot) -- (\xnode);
\end{scope}
}

\end{tikzpicture}
\end{document}

相关内容