在 `\graph` 环境内定位

在 `\graph` 环境内定位

定位\graph环境内部。可以吗?我做错了什么?L 2 不在它应该在的位置。

\documentclass [border = 2mm] {standalone}

\usepackage{tikz}
\usetikzlibrary{ graphs, graphs.standard }
\usetikzlibrary{ positioning, calc }

\tikzset{ myVrtxStyle/.style = {
    circle, minimum size= 4mm, fill = #1
    },
    myVrtxStyle/.default = blue
}

\begin{document} 
    
    \begin{tikzpicture} 
        \node[myVrtxStyle] at (0, 0) (A) {};
        \begin{scope}
            \graph[nodes = {myVrtxStyle}, empty nodes]{
                (A) -- L 1 [ below left = 1cm and 1cm of $(A)$ ] -- L 2 [below left = 1cm and 1cm of $(L 1)$];
            };
        \end{scope}
        \draw[red] (L 1) -- ++(1cm, 0) -- +(0, 1cm);
        \draw[blue] (L 2) -- ++(1cm, 0) -- +(0, 1cm);
        \node [myVrtxStyle = red, below left = 1cm and 1cm of $(L 1)$] {}; %Should be here
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

如果您希望自己进行布局,那么您需要告诉图表使用no placement

\documentclass [border = 2mm] {standalone}
\usepackage{tikz}
\usetikzlibrary{ graphs, graphs.standard }
\usetikzlibrary{ positioning, calc }
\tikzset{ myVrtxStyle/.style = {
    circle, minimum size= 4mm, fill = #1
    },
    myVrtxStyle/.default = blue
}
\begin{document}    
    \begin{tikzpicture} 
        \node[myVrtxStyle] at (0, 0) (A) {};
        \begin{scope}
            \graph[nodes = {myVrtxStyle}, empty nodes, no placement]{
                (A) -- L 1 [ below left = 1cm and 1cm of $(A)$ ] -- L 2 [below left = 1cm and 1cm of $(L 1)$];
            };
        \end{scope}
        \draw[red] (L 1) -- ++(1cm, 0) -- +(0, 1cm);
        \draw[blue] (L 2) -- ++(1cm, 0) -- +(0, 1cm);
        \node [myVrtxStyle = red, below left = 1cm and 1cm of $(L 1)$] {}; %Should be here
    \end{tikzpicture}
\end{document}

正确放置的图表

相关内容