您的位置:首页 > 其它

[pgf and tikz]foreach的高级用法:同时循环两个变量

2013-03-25 11:51 369 查看
[pgf and tikz]foreach的高级用法:同时循环两个变量\from 和 \to:

\documentclass{beamer}
\input{tikzall.tex} %包含所有的tikz包

\begin{document}
%
\begin{frame}
\begin{tikzpicture}
[scale=1,auto=left,every node/.style={circle,fill=blue!25}]
\node (a) at (-1,-2) {a};
\node (b) at ( 1,-2) {b};
\node (c) at ( 2,-1) {c};
\node (d) at ( 2, 1) {d};
\node (e) at ( 1, 2) {e};
\node (f) at (-1, 2) {f};
\node (g) at (-2, 1) {g};
\node (h) at (-2,-1) {h};
\foreach \from/\to in {a/b,b/c,c/d,d/e,e/f,f/g,g/h,h/a}
\draw [->] (\from) -- (\to)
node[midway,fill=red!25] {\from--\to};
\end{tikzpicture}
\end{frame}

\end{document}


结果如图所示:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: