我今天开始学习 TikZ,并得到了以下图像:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,positioning,arrows,shapes.misc,decorations.pathmorphing}
\tikzset{
>=stealth,
every picture/.style={thick},
graphs/every graph/.style={empty nodes},
}
\tikzstyle{vertex}=[
draw,
circle,
fill=black,
inner sep=1pt,
minimum width=5pt,
]
\begin{document}
\begin{tikzpicture}
\begin{scope}
\graph[ grow right = 2 ] {
u [vertex, label=$u$]
--[edge label=$e$]
v [vertex, label=$v$]
};
\end{scope}
\draw[->,thin] (3,0) -- (5,0) node [midway,above] {subdividing};
\begin{scope} [xshift=6cm]
\graph[ grow right = 1 ] {
u [vertex, label=$u$]
-- %[edge label=$e_{uv}$]
e [vertex, label=$v_e$]
-- %[edge label=$e_{vu}$]
v [vertex, label=$v$]
};
\end{scope}
\end{tikzpicture}
\end{document}
有没有办法自动将v_e
标签与右侧图表中u
的垂直对齐?v
另外,我喜欢这种graph
语法,但我还没有找到一种简单的方法让它在圆圈旁边制作节点标签(如图所示),而不是在圆圈内制作名称节点,而无需明确使用该label
选项。
答案1
我不确定这里是否有必要。如果设置为,则s\smash
不需要它。但是,它似乎是 所必需的。但这可能是由于我不熟悉该库。edge label
anchor
mid
node
label
graphs
您可以使用该quotes
库来更轻松地标记edge
s,但我认为您仍然需要label
标记node
s。
\documentclass[border=20pt,tikz]{standalone}
\usetikzlibrary{graphs,quotes,positioning}
\tikzset{
>=stealth,
every picture/.style={thick},
graphs/every graph/.style={empty nodes},
every edge quotes/.append style={above=7.5pt, anchor=mid, inner sep=0pt},
every label/.append style={above=2.5pt, anchor=mid, inner sep=0pt},
vertex/.style={
draw,
circle,
fill=black,
inner sep=0pt,% doesn't actually change the size and makes it easier to calculate things - or, more accurately, it makes it more obvious how to calculate them
outer sep=0pt,
minimum size=5pt,
},
}
\begin{document}
\begin{tikzpicture}
\graph[ grow right = 2 ] {
u [vertex, label=$u$]
-- ["$e$"]
v [vertex, label=$v$]
};
\draw (3,0) edge ["subdividing",->,thin] (5,0);
\begin{scope} [xshift=6cm]
\graph[ grow right = 1 ] {
u [vertex, label=$u$]
-- ["$e_{uv}$"]
e [vertex, label=$v\smash{_e}$]
-- ["$e_{vu}$"]
v [vertex, label=$v$]
};
\end{scope}
\end{tikzpicture}
\end{document}
\smash
请注意,中的下标似乎没有必要使用$e_{uv}$
。