在 Latex 中绘制仅包含文本顶点的图形

在 Latex 中绘制仅包含文本顶点的图形

我想扩展示例的实现这里以图所示的方式用文本简单表示顶点的图形 以下

我在 tikz 手册中找不到类似的模板/示例。有人能告诉我 MWE 吗?

答案1

您可以修改贡萨洛代码(来自您所提到的问题的公认答案)仅包含文本,例如

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

\begin{document}
\begin{tikzpicture}[thick]

% the vertices of U
\begin{scope}[start chain=going below,node distance=7mm]
\foreach [count=\i] \txt/\xcoord/\ycoord in {ABC/6/8,CDE/5/1,FGH/-4/7,IJK/6/9,LMN/0/-3}
  \node[on chain] (f\i) {\txt};
\end{scope}

% the vertices of V
\begin{scope}[xshift=4cm,yshift=-0.5cm,start chain=going below,node distance=7mm]
\foreach [count=\i from 6] \txt/\xcoord/\ycoord in {OPQ/0/3,RST/1/4,UVW/-2/1,XYZ/5/9}
  \node[on chain] (s\i) {\txt};
\end{scope}


% the edges
\begin{scope}[auto]
\draw (f1) --node{1} (s6);
\draw (s6) --node[swap]{2} (f2);
\draw (f2) --node{3} (s7);
\draw (s7) --node{4} (f3);
\draw (s8) --node{5} (f3);
\draw (f3) --node[swap]{6} (s9);
\draw (s9) --node{7} (f5);
\draw (f5) --node{8} (s6);
\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容