我正在使用TikZ
和tkz-berge
包来创建直接无环图。我已将代码粘贴在下面。我希望变量标签“variable1”、“variable2”等周围有轮廓和白色背景,以便于通过箭头轻松读取。有办法吗?(我想保留LabelOut=true
)
\documentclass[]{article}
\usepackage{tikz}
\usepackage{tikz,fullpage}
\usetikzlibrary{arrows,%
petri,%
topaths}%
\usepackage{tkz-berge}
\usepackage[position=top]{subfig}
\usepackage{verbatim}
\begin{document}
\begin{figure}
\centering
\subfloat[]{
\begin{tikzpicture}[scale=0.75,transform shape]
\Vertex[x=2.221,y=2.379, LabelOut=true, Lpos=-90]{variable1}
\Vertex[x=-1.786,y=-2.495, LabelOut=true, Lpos=-90]{variable2}
\Vertex[x=-0.808,y=-0.482, LabelOut=true, Lpos=-90]{variable3}
\Vertex[x=1.834,y=-5.724, LabelOut=true, Lpos=-90]{variable4}
\Vertex[x=1.855,y=-1.202, LabelOut=true, Lpos=-90]{variable5}
\Vertex[x=2.820,y=5.684, LabelOut=true, Lpos=-90]{variable6}
\Vertex[x=-3.821,y=-0.308, LabelOut=true, Lpos=-90]{variable7}
\Vertex[x=-1.800,y=-5.955, LabelOut=true, Lpos=-90]{variable8}
\Vertex[x=-4.797,y=-4.289, LabelOut=true, Lpos=-90]{variable9}
\Vertex[x=5.243,y=3.474, LabelOut=true, Lpos=-90]{variable10}
\Vertex[x=4.377,y=-0.046, LabelOut=true, Lpos=-90]{variable11}
\Vertex[x=1.025,y=-3.360, LabelOut=true, Lpos=-90]{variable12}
\Vertex[x=-1.086,y=1.824, LabelOut=true, Lpos=-90]{variable13}
\Vertex[x=1.200,y=0.993, LabelOut=true, Lpos=-90]{variable14}
\tikzstyle{LabelStyle}=[fill=blue,sloped]
\tikzstyle{EdgeStyle}=[post]
\Edge[](variable3)(variable2)
\Edge[](variable4)(variable2)
\Edge[](variable4)(variable5)
\Edge[](variable5)(variable2)
\Edge[](variable5)(variable1)
\Edge[](variable1)(variable14)
\Edge[](variable6)(variable1)
\Edge[](variable7)(variable2)
\Edge[](variable7)(variable13)
\Edge[](variable8)(variable2)
\Edge[](variable9)(variable2)
\Edge[](variable10)(variable1)
\Edge[](variable11)(variable1)
\Edge[](variable11)(variable5)
\Edge[](variable12)(variable2)
\Edge[](variable12)(variable5)
\Edge[](variable13)(variable1)
\Edge[](variable14)(variable3)
\end{tikzpicture}
}
\end{figure}
\end{document}
答案1
因为说实话,我不想阅读手册tkz-berge
,所以我随便写了这个例子。这pgfonlayer
是用于在背景中绘制边缘,因此在标签后面:
\documentclass{article}
\usepackage{tikz}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\newcommand{\Vertex}[2]% pos, name
{ \node[circle,draw,minimum width=0.5cm,inner sep=0] (#2) at (#1) {};
\node[rounded corners=3pt,below,draw=black,fill=white,inner sep=1.5pt] at (#2.south) {\footnotesize#2};
}
\newcommand{\Edge}[2]%
{ \begin{pgfonlayer}{background}
\draw (#1) -- (#2);
\end{pgfonlayer}
}
\begin{document}
\begin{tikzpicture}
\Vertex{2.221,2.379}{variable1}
\Vertex{2.221,2.379}{variable1}
\Vertex{-1.786,-2.495}{variable2}
\Vertex{-0.808,-0.482}{variable3}
\Vertex{1.834,-5.724}{variable4}
\Vertex{1.855,-1.202}{variable5}
\Vertex{2.820,5.684}{variable6}
\Vertex{-3.821,-0.308}{variable7}
\Vertex{-1.800,-5.955}{variable8}
\Vertex{-4.797,-4.289}{variable9}
\Vertex{5.243,3.474}{variable10}
\Vertex{4.377,-0.046}{variable11}
\Vertex{1.025,-3.360}{variable12}
\Vertex{-1.086,1.824}{variable13}
\Vertex{1.200,0.993}{variable14}
\Edge{variable3}{variable2}
\Edge{variable4}{variable2}
\Edge{variable4}{variable5}
\Edge{variable5}{variable2}
\Edge{variable5}{variable1}
\Edge{variable1}{variable14}
\Edge{variable6}{variable1}
\Edge{variable7}{variable2}
\Edge{variable7}{variable13}
\Edge{variable8}{variable2}
\Edge{variable9}{variable2}
\Edge{variable10}{variable1}
\Edge{variable11}{variable1}
\Edge{variable11}{variable5}
\Edge{variable12}{variable2}
\Edge{variable12}{variable5}
\Edge{variable13}{variable1}
\Edge{variable14}{variable3}
\end{tikzpicture}
\end{document}