如何命名边?

如何命名边?

我有以下图表

\begin{figure}[H]
    \centering
    \begin{tikzpicture}
    
    \node[shape=circle,draw=black] (0) at (0,0) {$0$};  
    \node[shape=circle,draw=black] (4) at (6,0)  {$1$};   
    \node[shape=circle,draw=black] (1) at  (3,-1) {$2$};  
    \node[shape=circle,draw=black] (2) at  (3,2) {$3$};  
 
    \draw (0) -- (1); 
    \draw (0) -- (2);  
  \draw (0) -- (4);
    \draw (0) -- (4); 
    \draw (4) -- (2);  
    \draw (2) -- (1);
    
    
    \end{tikzpicture}
    
\end{figure}

我不知道该如何命名边 e1、e2、e3、e4。有人能帮我吗?

答案1

在此处输入图片描述

\begin{tikzpicture}
    
    \node[shape=circle,draw=black] (0) at (0,0) {$0$};  
    \node[shape=circle,draw=black] (4) at (6,0)  {$1$};   
    \node[shape=circle,draw=black] (1) at  (3,-1) {$2$};  
    \node[shape=circle,draw=black] (2) at  (3,2) {$3$};  
    
    \draw (0) -- (1) node[pos=.5, below, sloped, rotate=0] {e1}; 
    \draw (0) -- (2);  
    \draw (0) -- (4);
    \draw (0) -- (4); 
    \draw (4) -- (2);  
    \draw (2) -- (1);
    
    
\end{tikzpicture}

答案2

不清楚哪些名称有特定路径,但更正/插入名称很简单。通过使用quotes库,您可以按如下方式添加它们:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{quotes}

\begin{document}
    \begin{tikzpicture}[
C/.style = {circle, draw}, %   C: circle
every edge quotes/.style = {auto, font=\footnotesize, inner sep=2pt, pos=0.4}
                        ]
    \begin{scope}[nodes={C}]
\node (0)           {$0$};
\node (4) at (6,0)  {$1$};
\node (1) at (3,-1) {$2$};
\node (2) at (3,2)  {$3$};
    \end{scope}
%
\path   (0) edge ["$e_3$"]  (2)
        (0) edge ["$e_1$"]  (4)
        (0) edge ["$e_2$"]  (1)
        (2) edge ["$e_4$"]  (1)
        (4) edge (2);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

附录: 可以使用tikz-cd以下包轻松绘制此简单图表:

\documentclass[border=3mm]{standalone}
\usepackage{tikz-cd}
\usepackage[low-sup]{subdepth}

\begin{document}
    \begin{tikzcd}[sep=huge,
                   cells={nodes={circle, draw, semithick, minimum size=1.1em, 
                          inner sep=2pt, outer sep=0pt}},
                   arrows = dash,
                   every label/.append style = {font=\footnotesize, inner sep=1pt, pos=0.35}             
                   ]
    &   3 \ar[dr,"e_{31}"]
          \ar[dd,"e_{32}"]  &   \\
0 \ar[ur,"e_3"]
  \ar[rr,"e_1"]
  \ar[dr,"e_2"]
    &                       & 1 \\
    &   2                   &
    \end{tikzcd}

在此处输入图片描述

相关内容