LaTeX - 在加权图的排序边列表上方添加节点标签

发布于 2024-08-23 06:38:57 字数 251 浏览 4 评论 0原文

这看起来相当简单,但我无法在网上找到有关如何执行此操作的任何信息。我正在编写克鲁斯卡尔算法的步骤。我需要创建一个按权重排序的边列表,权重上方的标签引用边,如下所示:

a-b b-c c-e
 1   3   5  ...

Anany Levitin 的算法设计与分析 在第 4 页上使用了类似的格式。 316. 如果没有其他选择,我想逐字记录可能会起作用,尽管我希望让它看起来更好一点。有什么建议吗?

This seems like it would be fairly simple, but I've been unable to find anything about how to do this on the web. I'm writing the steps for Kruskal's algorithm. I need to create a list of edges sorted by weight, with labels above the weight referencing the edges, something like this:

a-b b-c c-e
 1   3   5  ...

Design and Analysis of Algorithms by Anany Levitin uses similar formatting on p. 316. If there are no other options, I suppose verbatim might work, though I was hoping to make it look a little nicer. Any recommendations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

就是爱搞怪 2024-08-30 06:38:57

正如有人建议的那样,TikZ 可能有点矫枉过正,但它确实有效。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[anchor=east]{a} -- (0.4,0) node[anchor=west]{b};
\draw (0.2,0) node[anchor=north]{1};
\draw (2,0) node[anchor=east]{b} -- (2.4,0) node[anchor=west]{c};
\draw (2.2,0) node[anchor=north]{3};
\draw (4,0) node[anchor=east]{c} -- (4.4,0) node[anchor=west]{e};
\draw (4.2,0) node[anchor=north]{5};
\end{tikzpicture}
\end{document}

编辑:实际上,这可能更简单并且可以实现您想要的功能:

\[ \left. \begin{array}{ccc}
   {a-b \atop 1} & {b-c \atop 3} & {c-e \atop 5}
   \end{array} \right. \]

您可以自己比较: tikzedgeweights.pdf< /a>

As someone suggested, TikZ might be overkill, but it does work.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[anchor=east]{a} -- (0.4,0) node[anchor=west]{b};
\draw (0.2,0) node[anchor=north]{1};
\draw (2,0) node[anchor=east]{b} -- (2.4,0) node[anchor=west]{c};
\draw (2.2,0) node[anchor=north]{3};
\draw (4,0) node[anchor=east]{c} -- (4.4,0) node[anchor=west]{e};
\draw (4.2,0) node[anchor=north]{5};
\end{tikzpicture}
\end{document}

EDIT: Actually, this is probably simpler and does what you want:

\[ \left. \begin{array}{ccc}
   {a-b \atop 1} & {b-c \atop 3} & {c-e \atop 5}
   \end{array} \right. \]

You can compare for yourself: tikzedgeweights.pdf

热情消退 2024-08-30 06:38:57

怎么样:

$a\xrightarrow{1}b$

or

$b\xrightarrow[{3}]{}c$

or or

$c\overset{5}{-}e$

or

$c\underset{3}{-}f$

(在序言中使用 \usepackage{amsmath}

您可以在这里找到更高级的数学技巧:http://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics

What about something like:

$a\xrightarrow{1}b$

or

$b\xrightarrow[{3}]{}c$

or

$c\overset{5}{-}e$

or

$c\underset{3}{-}f$

(with \usepackage{amsmath} in your preamble)

You can find more advanced math techniques here: http://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics

烟燃烟灭 2024-08-30 06:38:57

为了获得更多技巧和更好的外观,

\usepackage{amsmath}
\begin{document}

\[ \overset{a-b}{1} \qquad \overset{\text{\it c-b}}{2} \]

\end{document}

我在这里为您提供了两种外观不同的可能性 - 选择您更喜欢的。

通过将 Steve 的代码修改为,无需 amsmath 即可实现相同的效果

\[ \left. \begin{array}{ccc}
   {a-b \atop {\displaystyle 1}} & {b-c \atop {\displaystyle 3}}
    & {c-e \atop {\displaystyle 5}} 
   \end{array} \right. \]

For a bit more finesse and better looks use

\usepackage{amsmath}
\begin{document}

\[ \overset{a-b}{1} \qquad \overset{\text{\it c-b}}{2} \]

\end{document}

I gave you two different-looking possibilities here -- pick what you like more.

You can achieve the same effect without amsmath by modifying Steve's code to

\[ \left. \begin{array}{ccc}
   {a-b \atop {\displaystyle 1}} & {b-c \atop {\displaystyle 3}}
    & {c-e \atop {\displaystyle 5}} 
   \end{array} \right. \]
迟到的我 2024-08-30 06:38:57

tikz 可能是您最好的选择,尽管它对于您所追求的东西来说有点重量级。也许 xypic 会提供更好的解决方案,而且不像 tikz 那样密集。我不确定你想要的东西是什么样子,但这会很接近吗:

   A \ar[r]^{label} & B

或者类似的东西?

tikz is probably your best bet, though it is a little heavyweight for what you're after. Perhaps xypic would offer a better solution, and one that isn't quite as intensive as tikz. I'm not sure what you want the thing to look like, but would this be close:

   A \ar[r]^{label} & B

Or something like that?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文