tkz-berge에서 정점 이름 카운터 재설정

tkz-berge에서 정점 이름 카운터 재설정

tkz-berge라이브러리 로 구성된 다음 그래프가 있습니다 . 현재 설정에서 노드/정점은 자동으로 인덱스 0부터 시작하여 번호가 지정됩니다. 1부터 시작하기 위해 카운터를 재설정하는 방법이 궁금합니다.

\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을 호출하는 하위 수준 노드 인쇄 명령을 갱신(즉, 수정)할 수 있습니다 . 를 사용하면 노드 카운터에 1을 추가하고 결과를 매크로에 저장하며 카운터 자체 대신 라벨에 해당 매크로를 인쇄할 수 있습니다. 라벨에 추가하는 것을 피하는 대신 을 사용해야 합니다 .\Vertextkz-graphtkz-berge\pgfmathtruncatemacro\pgfmathtruncatemacro\pgfmathsetmacro.0

MWE:

\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}

결과:

여기에 이미지 설명을 입력하세요

관련 정보