如何给图片添加标签

如何给图片添加标签

我想用 v1、v2、...、v7 标记 Fano 超图的每个顶点,但我不知道如何标记其 Fano 超图。这是我所做的:

  \newcommand\FanoPlane[1][1cm]{%
  \begin{tikzpicture}[
     mydot/.style={
     draw,
     circle,
     fill=black,
     inner sep=3pt}
]
 \draw
 (0,0) coordinate (A) --
 (#1,0) coordinate (B) --
 ($ (A)!.5!(B) ! {sin(60)*2} ! 90:(B) $) coordinate (C) -- cycle;
\coordinate (O) at
   (barycentric cs:A=1,B=1,C=1);
\draw (O) circle [radius=#1*1.717/6];
\draw (C) -- ($ (A)!.5!(B) $) coordinate (LC); 
\draw (A) -- ($ (B)!.5!(C) $) coordinate (LA); 
\draw (B) -- ($ (C)!.5!(A) $) coordinate (LB); 
\foreach \Nodo in {A,B,C,O,LC,LA,LB}
\node[mydot] at (\Nodo) {};    
\end{tikzpicture}%
}
\begin{figure}[H]
\centering
\quad\FanoPlane[5cm]
\caption{An example of a hypergraph, with $X= \{ v_1, v_2, ..., v_7 \}$} and $E= \{e_1, e_2, . . ., e_7 \}= \{ \{v_1,v_2,v_3\}, \{v_1,v_4,v_5\}, \{v_1,v_6,v_7\}, \{v_2,v_4,v_6\}, \{v_2,v_5,v_7\},\{v_3,v_4,v_7\}, \{v_3,v_5, v_6\}\}$      \label{fig:figurelabel}
 \end{figure}

答案1

一个选项是将\foreach循环修改为

\foreach [count=\i] \Nodo/\pos in {A/left,B/right,C/left,O/left,LC/below,LA/right,LB/left}
  \node[mydot,label=\pos:$v_\i$] at (\Nodo) {};

\foo/\bar语法允许您使用两个循环变量。这里,一个用于节点名称,另一个用于标签相对于节点的位置。count顾名思义,这是一个计数器,用于计数循环运行的次数。

代码输出

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\FanoPlane[1][1cm]{%
\begin{tikzpicture}[
  mydot/.style={
     draw,
     circle,
     fill=black,
     inner sep=3pt}
]
 \draw
 (0,0) coordinate (A) --
 (#1,0) coordinate (B) --
 ($ (A)!.5!(B) ! {sin(60)*2} ! 90:(B) $) coordinate (C) -- cycle;
\coordinate (O) at
   (barycentric cs:A=1,B=1,C=1);
\draw (O) circle [radius=#1*1.717/6];
\draw (C) -- ($ (A)!.5!(B) $) coordinate (LC); 
\draw (A) -- ($ (B)!.5!(C) $) coordinate (LA); 
\draw (B) -- ($ (C)!.5!(A) $) coordinate (LB); 
\foreach [count=\i] \Nodo/\pos in {A/left,B/right,C/left,O/left,LC/below,LA/right,LB/left}
  \node[mydot,label=\pos:$v_\i$] at (\Nodo) {};   
\end{tikzpicture}%
}
\begin{document}
\FanoPlane[5cm]
\end{document}

相关内容