重置 tkz-berge 中的頂點名稱計數器

重置 tkz-berge 中的頂點名稱計數器

我有一個用庫建構的下圖tkz-berge。在目前設定中,節點/頂點會自動從索引 0 開始編號。

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{tkz-berge}
\begin{document}
\begin{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Normal]
\SetUpVertex[Math,Lpos=-180,LabelOut]
\SetVertexNormal[FillColor=red,OuterSep=0pt]
\grEmptyPath[form=2,x=0,y=0,RA=2,rotation=90,prefix=u,Math]{5}
\SetUpVertex[Lpos=0]
\SetVertexNormal[FillColor=blue]
\grEmptyPath[form=2,x=6,y=0,RA=2,rotation=90,prefix=v,Math]{4}
\Edges(u4,v3,u3,v2,u1)
\Edges(u3,v3,u0,v0,u2,v1)
\end{tikzpicture}
\end{tikzpicture}
\end{document}

圖1

答案1

節點計數器在整個程式碼中用於tkz-berge計算位置並產生內部節點名稱,因此當您更改計數器時,所有事情都會崩潰。但是,您可以更新(即修改)較低層級的節點列印命令,該命令以節點標籤作為參數之一\write@math呼叫\Vertex(由套件定義tkz-graph,由 載入)。tkz-berge使用\pgfmathtruncatemacro您可以將節點計數器加 1,將結果儲存在巨集中,然後在標籤中而不是計數器本身中列印該巨集。注意\pgfmathtruncatemacro應該使用而不是\pgfmathsetmacro避免.0在標籤中添加。

微量元素:

\documentclass{article}
\usepackage{tkz-berge}
\makeatletter
\renewcommand*{\write@math}[3]{%
            \pgfmathtruncatemacro{\printindex}{#3+1}
            \Vertex[x = #1,y = #2,%
                    L = \cmdGR@cl@prefix\grMathSep{\printindex}]{\cmdGR@cl@prefix#3}}
\makeatother
\begin{document}
\begin{tikzpicture}
\GraphInit[vstyle=Normal]
\SetUpVertex[Math,Lpos=-180,LabelOut]
\SetVertexNormal[FillColor=red,OuterSep=0pt]
\grEmptyPath[form=2,x=0,y=0,RA=2,rotation=90,prefix=u,Math]{5}
\SetUpVertex[Lpos=0]
\SetVertexNormal[FillColor=blue]
\grEmptyPath[form=2,x=6,y=0,RA=2,rotation=90,prefix=v,Math]{4}
\Edges(u4,v3,u3,v2,u1)
\Edges(u3,v3,u0,v0,u2,v1)
\end{tikzpicture}
\end{document}

結果:

在此輸入影像描述

相關內容