如何将边的箭头放在 tkz-graph 的中心?

如何将边的箭头放在 tkz-graph 的中心?

我怎样才能将箭头放在这张图的中间?

\documentclass{standalone}
\usepackage{tikz,tkz-graph,tkz-berge}
\usetikzlibrary{positioning,fit,patterns} 
\tikzset{->-/.style={decoration={
  markings,
  mark=at position #1 with {\arrow{>}}},postaction={decorate}}}
\begin{document}
\begin{tikzpicture}[>-=.5]
\SetGraphUnit{2}
\GraphInit[vstyle=Classic]
\tikzset{VertexStyle/.append style={minimum size=1.5pt, inner sep=1.5pt}}
\Vertex[Math,Lpos=90]{y}
\EA[Math,Lpos=90,unit=1.5](y){x}
\SOEA[Math,Lpos=90,unit=.8](y){z}
\SOWE[Math,Lpos=180,unit=.8](z){u}
\SO[Math,Lpos=-90,unit=1.5](u){w}
\EA[Math,Lpos=90,unit=1.5](u){v}
\EA[Math,Lpos=-90,unit=1.5](w){t}
\tikzset{EdgeStyle/.style={->,relative=false}}
\Edges(z,u)
\Edges(z,u,w,t,v,w)
\Edges(z,x,y,z,v)
\tikzset{EdgeStyle/.style = {->,>=stealth',bend right}}
\Edge(u)(y)
\tikzset{EdgeStyle/.style = {->,>=stealth',bend right}}
\Edge(y)(u) 
\end{tikzpicture} 
\end{document} 

答案1

您几乎已经准备好了一切,您只需要加载decorations.markings库,然后实际使用->-您定义的样式。

\documentclass[border=5mm]{standalone}
\usepackage{tkz-graph}

\usetikzlibrary{decorations.markings} % <-- you need this for markings

\tikzset{->-/.style={
 decoration={
   markings,
   mark=at position #1 with {\arrow{>}}
   },
   postaction={decorate}
  },
  ->-/.default=0.5 % set default value for arrow position
}
\begin{document}
\begin{tikzpicture}%[>-=.5] your style is called ->-
\SetGraphUnit{2}
\GraphInit[vstyle=Classic]
\tikzset{VertexStyle/.append style={minimum size=1.5pt, inner sep=1.5pt}}
\Vertex[Math,Lpos=90]{y}
\EA[Math,Lpos=90,unit=1.5](y){x}
\SOEA[Math,Lpos=90,unit=.8](y){z}
\SOWE[Math,Lpos=180,unit=.8](z){u}
\SO[Math,Lpos=-90,unit=1.5](u){w}
\EA[Math,Lpos=90,unit=1.5](u){v}
\EA[Math,Lpos=-90,unit=1.5](w){t}
\tikzset{EdgeStyle/.style={->,relative=false}}
\Edges(z,u)
\Edges(z,u,w,t,v,w)
\Edges(z,x,y,z,v)
\tikzset{EdgeStyle/.style = {->-,>=stealth',bend right}} % ->- instead of ->
\Edge(u)(y)
% there is no need to repeat the EdgeStyle definition from two lines above
\Edge(y)(u) 
\end{tikzpicture} 
\end{document}

在此处输入图片描述

相关内容