如何在乳胶中绘制下面的全连接图链接图片?

如何在乳胶中绘制下面的全连接图链接图片?

在此处输入图片描述这个图表示一个连接到每个节点的图。如何使用 tikz 绘制这种图?

在此处输入图片描述

答案1

这是不是您的图表,但我推荐它的变体。

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}[every node/.style={circle,minimum size=.75cm,draw}]
    \node (a) at (0,2) {Goal};
    \node (c2) at (0,0) {$c_2$};
    \node (c3) at (2,0) {$c_3$};
    \node (c1) at (-2,0) {$c_1$};
    \node (a1) at (-1,-2) {$a_1$};
    \node (a2) at (1,-2) {$a_2$};
\end{scope}
\draw (a)--(c1)--(a1)--(c2)--(a2)--(c3)--(a)--(c2) (c1)--(a2) (c3)--(a1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

一些说明:

  • 节点的大小不宜过大。因此我使用minimum size=.75cm
  • 节点应呈圆形。
  • 您不应该将来自特定节点的所有路径连接起来。例如,在我看来,这是不好的。

    在此处输入图片描述

    如果还想加箭头就更糟了。

  • 节点应具有良好的对齐方式。在此图中,它们应水平居中。

  • 将节点标签置于数学模式,如果它们类似于Ab1n2

答案2

基于铅笔画,这里有一个示例代码,您可以根据需要改进它:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{squarenode/.style = {
    shape  = rectangle,
    draw   = black,
    minimum height = 2cm,
    minimum width  = 2cm
}}

\begin{document}
\begin{tikzpicture}[node distance=2cm]
  \node (a) at (0,0) [squarenode] {Goal};
  \node[below=of a] (c2) [squarenode] {C2};
  \node[left=of c2] (c1) [squarenode] {C1};
  \node[right=of c2] (c3) [squarenode] {C3};
  \node[below=of c1] (a1) [squarenode] {A1};
  \node[below=of c2] (a2) [squarenode] {A2};

  \draw (a.south) to (c1.north);
  \draw (a.south) to (c2.north);
  \draw (a.south) to (c3.north);
  \draw (c1.south) to (a1.north);
  \draw (c1.south) to (a2.north west);
  \draw (c2.south) to (a2.north);
  \draw (c2.south) to (a1.north east);
  \draw (c3.south) to (a1.north);
  \draw (c3.south) to (a2.north);
\end{tikzpicture}
\end{document} 

在此处输入图片描述

要了解使用的锚点,请参考下面的图表和代码:

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{dot/.style = {
    shape  = circle,
    draw   = black,
    fill = black,
    minimum size = 0.2cm
}}

\tikzset{squarenode/.style = {
        shape  = rectangle,
        draw   = black,
        minimum height = 10cm,
        minimum width  = 10cm
}}

\begin{document}
\begin{tikzpicture}[node distance=2cm]
  \node (a) at (0,0) [squarenode] {};
  \node[label=a.center] at (a.center) [dot] {};
  \node[label=a.north] at (a.north) [dot] {};
  \node[label=a.south] at (a.south) [dot] {};
  \node[label=a.east] at (a.east) [dot] {};
  \node[label=a.west] at (a.west) [dot] {};
  \node[label=a.north east] at (a.north east) [dot] {};
  \node[label=a.north west] at (a.north west) [dot] {};
  \node[label=a.south east] at (a.south east) [dot] {};
  \node[label=a.south west] at (a.south west) [dot] {};
\end{tikzpicture}
\end{document} 

答案3

我认为这是 TikZ 矩阵的工作。

<matrix-name>-<row-number>-<column-number>可以将矩阵单元称为节点。

这里有两版图表,如果您希望节点为平方,请省略该circle选项:

\documentclass{book}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
    mymatrix/.style={
        matrix of math nodes,
        nodes={draw, circle},
        row sep=10ex,
    }
}
\begin{document}
\begin{tikzpicture}
    \matrix[
        mymatrix,
        column sep=3em
        ](mymatr){
        &\text{Goal}\\
        C_1 & C_2& C_3\\
        A_1 & A_2\\
    };
    \foreach \ind in {1,2,3} {
        \draw (mymatr-1-2) -- (mymatr-2-\ind);
        \draw (mymatr-3-1) -- (mymatr-2-\ind);
        \draw (mymatr-3-2) -- (mymatr-2-\ind);
    }
\end{tikzpicture}

\begin{tikzpicture}
    \matrix[
        mymatrix,
        column sep=1.5em
        ](mymatr){
        &&\text{Goal}\\
        C_1 && C_2&& C_3\\
        &A_1 && A_2\\
    };
    \foreach \ind in {1,3,5} {
        \draw (mymatr-1-2) -- (mymatr-2-\ind);
        \draw (mymatr-3-2) -- (mymatr-2-\ind);
        \draw (mymatr-3-4) -- (mymatr-2-\ind);
    }
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容