在适当的位置绘制节点

在适当的位置绘制节点

我正在努力绘制这张图,将节点放在我想要的位置。节点 2 和 7 应该稍微向下移动,以便整个图关于 x 轴对称。我相信如果你知道命令,这一定是一件非常简单的事情,但我找不到它。任何帮助都值得感激,问候。

\begin {center}
\begin {tikzpicture}[-latex ,auto ,node distance =3 cm and 3cm ,on grid ,
semithick ,
state/.style ={ circle ,top color =white , bottom color = processblue!20 ,
draw,processblue , text=blue , minimum width =1 cm}]
\node[state] (1) {1};
\node[state] (2) [right=of 1] {2};
\node[state] (3) [right=of 2] {3};
\node[state] (4) [below=of 1] {4};
\node[state] (7) [below=of 2] {7};
\node[state] (5) [right=of 7] {5};
\node[state] (6) [below=of 4] {6};
\node[state] (8) [below=of 5] {8};
\path[-] (1) edge (2);
\path[-] (1) edge (4);
\path[-] (2) edge (3);
\path[-] (2) edge (4);
\path[-] (2) edge (5);
\path[-] (3) edge (5);
\path[-] (4) edge (6);
\path[-] (4) edge (7);
\path[-] (5) edge (7);
\path[-] (5) edge (8);
\path[-] (6) edge (7);
\path[-] (7) edge (8);
%\path[-] (D) edge  [bend right = 60] (E);
\end{tikzpicture}
\end{center}

答案1

在此处输入图片描述

如有疑问,请始终提供 MWE。由于您没有,我使用standalonedocumentclass 和标准颜色。此外,还tickpicture进行了一些更改,目标是使代码更加一致:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}

\begin{document}
    \begin{tikzpicture}[auto, semithick, 
node distance = 15mm and 30mm, on grid ,
%
 state/.style = {circle, draw=blue,  
                 top color=white, bottom color=blue!20 ,
                 text=blue, minimum size =1 cm}
                        ]
    \begin{scope}[nodes={state}]
\node (1) {1};
\node (2) [below right=of 1] {2}; % <---
\node (3) [above right=of 2] {3}; % <---
\node (4) [below  left=of 2] {4};
\node (7) [below right=of 4] {7};
\node (5) [above right=of 7] {5};
\node (6) [below  left=of 7] {6};
\node (8) [below right=of 7] {8};
    \end{scope}
\draw       (1) -- (2) -- (3) -- (5) -- (2) --
                   (4) -- (7) -- (5) -- (8) --
                   (7) -- (6) --
            (4) -- (1);
    \end{tikzpicture}
\end{document}

相关内容