我有以下图表代码:
\begin{tikzpicture}[blueringnode/.style={circle, draw=blue!100, fill=white, thick, minimum size = 7mm},
redfillnode/.style={circle, draw=black!100, fill=red!100, thick, minimum size = 7mm},
commonnode/.style={circle, draw=black!100, fill=white, thick, minimum size = 7mm},
redringgreenfillnode/.style={circle, draw=red!100, fill=green!60, thick, minimum size = 7mm},
blackringcyanfillnode/.style={circle, draw=black!100, fill=cyan!60, thick, minimum size = 7mm}, auto
]
\node[redfillnode](maintopic){\textit{F}};
\node[commonnode](topcircle)[above=of maintopic]{\textit{B}};
\node[commonnode](leftcircle)[left=of maintopic]{\textit{I}};
\node[redringgreenfillnode](bottomcircle)[below=of maintopic]{\textit{A}};
\node[commonnode](rightcircle)[right=of maintopic]{\textit{D}};
\node[commonnode](toprightcircle)[right=of topcircle]{\textit{C}};
\node[blueringnode](topleftcircle)[left=of topcircle]{\textit{H}};
\node[commonnode](bottomleftcircle)[left=of bottomcircle]{\textit{G}};
\node[blackringcyanfillnode](bottomrightcircle)[right=of bottomcircle]{\textit{E}};
\draw[-](leftcircle.east)--node{$7$}(maintopic.west);
\draw[-](topcircle.south)--(maintopic.north);
\draw[-](bottomcircle.north)--(maintopic.south);
\draw[-](leftcircle)--(topcircle);
\draw[-](topcircle)--(rightcircle);
\draw[-](bottomcircle)--(leftcircle);
\draw[-](bottomcircle)--(bottomleftcircle);
\draw[-](bottomcircle)--(bottomrightcircle);
\draw[-](rightcircle)--(bottomrightcircle);
\draw[-](rightcircle)--(toprightcircle);
\draw[-](topcircle)--(toprightcircle);
\draw[-](leftcircle)--(topleftcircle);
\draw[-,red](topleftcircle)--(topcircle);
\draw[-,line width=0.5mm](leftcircle)--(bottomleftcircle);
\draw[-,green](maintopic)--(rightcircle);
\draw[->,magenta](rightcircle)--(bottomcircle);
\end{tikzpicture}
我在最后一行(\draw->,magenta--(bottomcircle);)出现错误,我原本想要得到一个从右侧节点到底部中心节点的箭头;这是我想要得到的说明:
但我得到的却是:
知道为什么会发生这种情况吗?谢谢!
答案1
使用您的代码,将其完成为可编译的小文档后,我得到了您的第一张图像,但没有边缘标签。对于它们,我建议使用quotes
TikZ 库。
编辑:
对所有节点使用通用样式,将顶行节点重命名为 和tl
,对其他行使用类似方法,并在循环中绘制线条(如下面评论中薛定谔的猫所建议的)使您的代码更短:tm
tr
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{positioning,
quotes}
\begin{document}
\begin{tikzpicture}[
V/.style args = {#1/#2}{circle, draw=#1, thick, fill=#2, minimum size=7mm, font=\itshape},
V/.default = {black/none},
every edge quotes/.style = {font=\footnotesize, inner sep=1pt, minimum size=3pt, auto},
]
\node[V=blue/none] (tl) {H}; % top left
\node[V,right=of tl] (tm) {B};
\node[V,right=of tm] (tr) {C};
%
\node[V,below=of tl] (ml) {I};
\node[V=black/red,
right=of ml] (mm) {F};
\node[V,right=of mm] (mr) {D};
%
\node[V,below=of ml] (bl) {G};
\node[V=red/green,
right=of bl] (bm) {A};
\node[V=black/cyan,
right=of bm] (br) {E}; % bottom right
% the lines are drawn in a loop
\draw (tl) edge[red,"$5$"] (tm)
(tm) to["$4$"] (tr)
to["$3$"] (mr) to["$4$"] (br)
to["$2$"] (bm) to["$4$"] (bl)
edge[line width=.5mm, "$6$"] (ml)
(ml) to["$2$"] (tl)
%
(ml) to["$7$"] (mm) to["$5$"] (tm)
to["$3$" '] (ml)
%
(tm) to["$6$"] (mr) edge[green,"$1$"] (mm)
(mm) to["$3$" '] (bm) to["$8$"] (ml)
%
(mr) edge[->,thick,magenta,"$4$"] (bm);
\end{tikzpicture}
\end{document}