Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I draw a graph like the below image?

It seems that I could use some package for drawing graphs but I am new and I dont know if they have limitations.

enter image description here

The requirements are:

-There is a black solid node at the beginning

-Each node has a label at the top and a number at the bottom

-There could be dotted or solid arrows

-At the bottom there is a label that indicates time.

Any suggestions? Or should I just draw it using some software and add it as an image?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

If possible, it's always nice to provide a Minimal Working Example (MWE), to show us what you've tried so far, so that we can try and provide a solution along the lines that you're looking for. Nonetheless, since you had some general questions as well, I thought that I would provide an answer with one possible way of doing this (using TikZ) and try to answer some of your general questions.

TikZ is a pretty powerful drawing package that allows you to draw almost anything (see texample.net; PStricks is another package, but I'm not too familiar with it), so you don't have to draw an image like this with other software and then include it as an image. That is a possibility, but if you can write the image using a package without too much hassle, I would generally do that since including images of certain file types (e.g., .eps, .pdf, etc.) can sometimes cause problems in certain cases (see Which figure type to use: pdf or eps?).

So anyway, you can do this in TikZ. The solution I've provided also makes use of the varwidth package in order to allow linebreaks inside the TikZ nodes (see Manual/automatic line breaks and text alignment in TikZ nodes) as well as the TikZ library positioning in order to place the nodes relative to one another:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\usepackage{varwidth}

\begin{document}

\begin{tikzpicture}

\node [draw,circle,fill=black] (begin-node) {};
\node [below=2.5cm of begin-node] (0) {0};
\node [right=1.5cm of 0] (1) {1};
\node [right=2cm of 1] (2) {2};
\node [right=2cm of 2] (3) {3};
\node [above=0.5cm of 1,draw,circle] (F1) {\begin{varwidth}{1cm}\centering F \\ 1\end{varwidth}};
\node [above=2.5cm of F1,draw,circle] (T1) {\begin{varwidth}{1cm}\centering T \\ 1\end{varwidth}};
\node [above=0.5cm of 2,draw,circle] (F2) {\begin{varwidth}{1cm}\centering F \\ 2\end{varwidth}};
\node [above=2.5cm of F2,draw,circle] (T2) {\begin{varwidth}{1cm}\centering T \\ 2\end{varwidth}};
\node [above=0.5cm of 3,draw,circle] (F3) {\begin{varwidth}{1cm}\centering F \\ 3\end{varwidth}};
\node [above=2.5cm of F3,draw,circle] (T3) {\begin{varwidth}{1cm}\centering T \\ 3\end{varwidth}};
\draw[->] (begin-node) -- (T1);
\draw[->] (begin-node) -- (F1);
\draw[->] (T1) -- (T2);
\draw[->] (F1) -- (F2);
\draw[->] (T2) -- (T3);
\draw[->,dashed] (F2) -- (F3);
\draw[->,dashed,very thick] (F1) -- (T2);
\draw[->,dashed,thick] (T2) -- (F3);

\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer

TikZ and its chains library (also loads the positioning library).

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}
  \node[circle, fill, draw, inner sep=+0pt, minimum size=2ex, alias=F-0] (A) {};
  \begin{scope}[
    every node/.append style={circle, align=center, draw},
    every on chain/.append style={join},
    every join/.append style={->},
    start chain=T going right,
    start chain=F going right]
    \foreach \sStyle/\tText in {above right=of A/1, /2, /1}
      \node[on chain=T, style/.expand once=\sStyle] {T\\\tText};
    \begin{scope}[nodes={on chain=F}]
      \node [below right=of A] {F\\1};
      \node                    {F\\2};
      \path[every join/.append style=dashed] node {F\\3};
    \end{scope}
  \end{scope}
  \path[->] (A) edge (T-1) edge (F-1);
  \path[->, dashed] (F-1) edge (T-2)
                    (T-2) edge (F-3);

  \node[below=.5cm of F-3] (3) {3};
  \foreach \cnt in {0,1,2}
    \node at (F-\cnt |- 3) {\cnt};
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.