答案1
将图形绘制为tikzpicture
s 并使用baseline
选项指示图片应在哪个节点上对齐。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{vertex/.style={circle,draw,minimum width=3mm}}
\begin{tikzpicture}[auto,baseline=(c)]
\node[vertex] (a) at (0,0) {};
\node[vertex] (b) at (1,0) {};
\node[vertex] (c) at (2,0) {};
\node[vertex] (d) at (3,0) {};
\draw (a) -- node{1} (b)
-- node{2} (c)
-- node{3} (d);
\end{tikzpicture}
\qquad
\begin{tikzpicture}[auto,baseline=(c)]
\node[vertex] (a) at (0, 0.5) {};
\node[vertex] (b) at (0,-0.5) {};
\node[vertex] (c) at (1, 0 ) {};
\node[vertex] (d) at (2, 0 ) {};
\draw (a) -- node{1} (c)
-- node{2} (d)
(b) -- node[swap]{3} (c);
\end{tikzpicture}
\end{document}