Created
November 19, 2018 16:06
-
-
Save seungwonpark/14c803186083cdde60bcdcaf3a60680f to your computer and use it in GitHub Desktop.
Automatic graph drawing with TikZ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% All you have to do is replacing `{a/1/2, b/3/4, c/2/1, d/3/2}` and `{a/b, b/c, c/d}`. | |
% With given example, node (a) will be drawn at coordinate (1,2), (b) in at (3,4), ..., | |
% and edges a-b, b-c, c-d will be drawn. | |
% Within `scope` environment, all nodes will be surrounded with circle. | |
\documentclass{standalone} | |
\usepackage{tikz} | |
\usepackage{amsmath, amssymb} | |
\usepackage{pgffor} | |
\begin{document} | |
\begin{tikzpicture} | |
\begin{scope}[every node/.style={draw,circle}] | |
% draw nodes | |
\foreach \name/\xx/\yy in {a/1/2, b/3/4, c/2/1, d/3/2}{ | |
\node (\name) at (\xx, \yy) {\name}; | |
} | |
% draw edges | |
\foreach \edgefrom/\edgeto in {a/b, b/c, c/d}{ | |
\draw (\edgefrom) -- (\edgeto); | |
} | |
\end{scope} | |
\end{tikzpicture} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Preview: