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}

在此处输入图片描述

相关内容