在 tikz 中绘制图表

在 tikz 中绘制图表
\documentclass{book}
\usepackage{graphs}
\usetikzlibrary{graphs}

\begin{doument}
\begin{tikzpicture}[new set=import nodes]
\begin{scope}[nodes={set=import nodes}] % make all nodes part of this set
\node [red] (a) at (0,1) {$a$};
\node [red] (b) at (1,1) {$b$};
\node [red] (d) at (2,1) {$d$};
\end{scope}
\graph {
(import nodes);
% "import" the nodes
a -> b -> c -> d -> e;
};
\end{tikzpicture}
\end{document}

当我编译此代码时,出现错误

! LaTeX Error: File `graphs.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name: 

答案1

LaTeX 只能加载已存在的包。如果你尝试加载不存在的包,它会报错。

我的系统上不graphs.sty存在。我认为您可能需要的包是 TikZ:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{graphs}

\begin{document}
\begin{tikzpicture}[new set=import nodes]
\begin{scope}[nodes={set=import nodes}] % make all nodes part of this set
\node [red] (a) at (0,1) {$a$};
\node [red] (b) at (1,1) {$b$};
\node [red] (d) at (2,1) {$d$};
\end{scope}
\graph {
(import nodes);
% "import" the nodes
a -> b -> c -> d -> e;
};
\end{tikzpicture}
\end{document}

节点图

相关内容