带箭头的内联图形符号

带箭头的内联图形符号

基于图论中的旗代数符号,我尝试添加箭头。我可以通过添加 为具有 2 个节点的符号添加箭头\draw [->] (tmp1) to (tmp2)。但是,我在设计多边形边缘的样式时遇到了麻烦。有没有人知道如何在多边形边缘添加箭头?谢谢!

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\tikzset{gon/.style={name=tmp,regular polygon,regular polygon sides=#1,minimum
size=10pt,inner sep=0pt},
polygon side/.style args={#1--#2}{
insert path={(tmp.corner #1)-- (tmp.corner #2)}}}
\newcommand{\FlagGraph}[3][]{\ifnum#2=2%
\tikz[baseline=(tmp1)]{\node[circle,inner sep=0.7pt,fill] (tmp1) at (0,0){};
\node[#1,circle,inner sep=0.7pt,fill] (tmp2) at (10pt,0){};
\ifx#3\empty%
\else
\draw[#1] (tmp1) -- (tmp2);
\draw [->] (tmp1) to (tmp2);
\fi}
\else%
\tikz[baseline=(tmp.south)]{\node[#1,gon=#2]{};
\foreach \X in {1,...,#2}{\fill (tmp.corner \X) circle (1pt);}
\draw[#1,polygon side/.list={#3}]}
\fi}

答案1

欢迎!这里有一个小修改,允许您附加箭头。(对于两个节点的情况,添加箭头的选项已经隐含在您链接的代码中,但没有记录。)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\tikzset{gon/.style={name=tmp,regular polygon,regular polygon sides=#1,minimum
size=10pt,inner sep=0pt},flag connection/.style={-},
polygon side/.style args={#1--#2}{
insert path={(tmp.corner #1) edge[flag connection] (tmp.corner #2)}}}
%
\newcommand{\FlagGraph}[3][]{\ifnum#2=2%
\tikz[baseline=(tmp1)]{\node[circle,inner sep=0.7pt,fill] (tmp1) at (0,0){};
\node[#1,circle,inner sep=0.7pt,fill] (tmp2) at (10pt,0){};
\ifx#3\empty%
\else
\draw[#1] (tmp1) edge[flag connection] (tmp2);
\fi}
\else%
\tikz[baseline=(tmp.south)]{\node[#1,gon=#2]{};
\foreach \X in {1,...,#2}{\fill (tmp.corner \X) circle (1pt);}
\draw[#1,polygon side/.list={#3}]}
\fi}
\begin{document}
This answer comes with a command 
\[ \texttt{\textbackslash FlagGraph}[\langle\texttt{options}\rangle]\{n\}\{\langle\texttt{connection}~1\rangle,
\langle\texttt{connection}~2\rangle,\dots\}\;,\]
where $n$ denotes the number of corners and the second argument is a list of
connections that are to be drawn. The $\langle\texttt{options}\rangle$ can be
used to change the styles of the edges.

These are some sample graphs: 
\FlagGraph[flag connection/.style={-stealth}]{5}{1--2,1--4} 
\FlagGraph[flag connection/.style={stealth-stealth,red}]{3}{1--2} 
\FlagGraph{2}{1--2} \FlagGraph{2}{}
\FlagGraph[flag connection/.style={-stealth,blue}]{5}{3--1,3--2,3--4,3--5}

\end{document}

在此处输入图片描述

图表缩放:

在此处输入图片描述

相关内容