TikZ 連接線和節點

TikZ 連接線和節點

我的問題如下:正如您在下面的程式碼中看到的,我放置了一些節點並希望用線連接它們。但到目前為止,我無法讓所有線路在同一點開始/結束。所以總是有漏洞,我不知道該如何避免它們。

    \documentclass{article}
    \usepackage[ngerman]{babel}
    \usepackage{tikz}
    \usetikzlibrary{positioning}
    \begin{document}
    \begin{tikzpicture}
    \node[anchor=center] (1) at (0,5) {};
        \node[above left=1 and 1 of 1.center,anchor=center] (11) {};
        \node[above left =1 and 0.5 of 1.center,anchor=center] (12) {};
        \draw (1) -- (11);
        \draw (1) -- (12);
    \node[anchor=center] (2) at (5,3) {};
        \node[above right=1 and 1 of 2.center,anchor=center] (21) {};
        \node[above right=0.5 and 1 of 2.center,anchor=center] (22) {};
        \draw (2) -- (21);
        \draw (2) -- (22);
    \draw (1) -- (2);
    \end{tikzpicture}
    \end{document}

答案1

更短且正確:

\documentclass{article}
%\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (1) at (0,5);
    \draw (1) -- ++ (-1.0,1);
    \draw (1) -- ++ (-0.5,1);
\coordinate (2) at (5,3);
    \node[above right=1 and 1 of 2.center,anchor=center] (21) {};
    \node[above right=0.5 and 1 of 2.center,anchor=center] (22) {};
    \draw (2) -- ++ (1.0,1);
    \draw (2) -- ++ (0.5,1);
\draw (1) -- (2);
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容