如何在 LaTeX 中绘制图形?

首先,让我说我使用 LyX,虽然我没有问题使用 ERT。

其次,在 Latex 中绘制这样的简单图形最简单的方法是什么? alt text

我看过一些带有图表的文档,也看过一些示例,但是我不知道如何仅仅绘制一个简单的图表——我需要什么包,等等?

154546 次浏览

In my experience, I always just use an external program to generate the graph (mathematica, gnuplot, matlab, etc.) and export the graph as a pdf or eps file. Then I include it into the document with includegraphics.

Perhaps use tikz.

TikZ can do this.

A quick demo:

\documentclass{article}


\usepackage{tikz}


\begin{document}


\begin{tikzpicture}
[scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
\node (n6) at (1,10) {6};
\node (n4) at (4,8)  {4};
\node (n5) at (8,9)  {5};
\node (n1) at (11,8) {1};
\node (n2) at (9,6)  {2};
\node (n3) at (5,5)  {3};


\foreach \from/\to in {n6/n4,n4/n5,n5/n1,n1/n2,n2/n5,n2/n3,n3/n4}
\draw (\from) -- (\to);


\end{tikzpicture}


\end{document}

produces:

enter image description here

More examples @ http://www.texample.net/tikz/examples/tag/graphs/

More information about TikZ: http://sourceforge.net/projects/pgf/ where I guess an installation guide will also be present.

Aside from the (excellent) suggestion to use TikZ, you could use gastex. I used this before TikZ was available and it did its job too.

I have used graphviz ( https://www.graphviz.org/gallery ) together with LaTeX using dot command to generate graphs in PDF and includegraphics to include those.

If graphviz produces what you are aiming at, this might be the best way to integrate: dot2tex: https://ctan.org/pkg/dot2tex?lang=en