I need to draw simple graph (for example Petersen Graph) in LaTeX. I am using Kile in Ubuntu. I exactly don't know that which package should I use. Any suggestion with example is highly expected.
TikZ-PGF – How to Draw Graphs in LaTeX
tikz-pgf
Related Solutions
Not really a proper answer, but perhaps it is useful as hint:
Based on what buffers do, the filecontents
environment combined with \input
(for \getbuffer
) and \verbatiminput
(for \typebuffer
) comes closest, I think.
With a few adjustments (the path picture bounding box
is clipped against the path picture), a few empirical values (the .6\pgflinewidth
probably won’t work for other line widths) and without vertical correction of the bar (the same reason as before), one can achieve the following.
Code
\documentclass[tikz]{standalone}
\usepackage{pgfgantt}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{Shift/.style 2 args={shift={(+#1.5\pgflinewidth,+#2.5\pgflinewidth)}}}
\newcommand*{\pgfkeysstylelet}[2]{\expandafter\let\csname pgfk@#1/.@cmd\expandafter\endcsname\csname pgfk@#2/.@cmd\endcsname}
\ganttset{
/tikz/broken/.style={
decoration={
name=zigzag,
amplitude=+1pt,
segment length=+2pt}},
broken right/.code={
\pgfkeysstylelet{/pgfgantt/bar backup}{/pgfgantt/bar}
\pgfkeysalso{
/pgfgantt/bar left shift=-.5\pgflinewidth/\ganttvalueof{x unit},
/pgfgantt/bar right shift=(.5\pgflinewidth+.5\pgfdecorationsegmentamplitude)/\ganttvalueof{x unit},
/pgfgantt/bar/.append style={
draw=none,
path picture={
\draw[/pgfgantt/bar backup, broken] ([Shift=+-] path picture bounding box.north west) |-
([Shift=-+, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.south east)
decorate {-- ([Shift=--, xshift=-\pgfdecorationsegmentamplitude-.6\pgflinewidth] path picture bounding box.north east)}
-- cycle;}}}},
broken left/.code={
\pgfkeysstylelet{/pgfgantt/bar backup}{/pgfgantt/bar}
\pgfkeysalso{
/pgfgantt/bar right shift=.5\pgflinewidth/\ganttvalueof{x unit},
/pgfgantt/bar left shift=(-.5\pgflinewidth-.5\pgfdecorationsegmentamplitude)/\ganttvalueof{x unit},
/pgfgantt/bar/.append style={
draw=none,
path picture={
\draw[/pgfgantt/bar backup, broken] ([Shift=--] path picture bounding box.north east) |-
([Shift=++, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.south west)
decorate {-- ([Shift=+-, xshift=\pgfdecorationsegmentamplitude+.6\pgflinewidth] path picture bounding box.north west)}
-- cycle;}}}}}
\begin{document}
\begin{ganttchart}[vgrid, hgrid]{15}
\ganttbar{Master 1}{7}{9} \\
\ganttbar{Master 2}{2}{4} \\
\ganttbar[broken right]{Master 3}{5}{6} \ganttbar[broken left]{}{10}{10} \\
\ganttbar{Master 4}{11}{13}
\end{ganttchart}
\end{document}
Best Answer
I think the best approach is to use the tkz-berge from Altermundus. You can also find a complete guide here.
However, to make a simple example just using
TikZ
, you can follow this approach:which leads to:
It is an example of a Markov Chain in which several
TikZ
options are used. In the same guide, you will find an example in which nodes are placed in a matrix.