10

I need to create a diagram for a book, indicating the order in which chapters may be read. For example:

enter image description here

(Taken from http://www.proba.jussieu.fr/pageperso/giacomin/pub/RPM/Site/Contents_files/dep.jpg -- not mine.)

Further (due to publisher requirements) it needs to be done in TeX, rather than imported as a diagram. (I imagine TikZ might work well, but positioning all the nodes by hand would be tortuous.) What's the best way of producing an attractive diagram?

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Mohan
  • 15,906
  • Do publishers often require the making of all diagrams in TeX? Sounds like a PITA, why wouldn't they allow EPS/PDF diagrams imported? – levesque Oct 03 '12 at 15:13

1 Answers1

18

Here's something to get you started in tikz

screenshot

It's not identical to your picture, but I have to leave some of the work for you :) I've used the positioning library to specify each of the nodes in terms of relative positions to one another.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[>=stealth,every node/.style={shape=rectangle,draw,rounded corners},]
    % create the nodes
    \node (c1) {Chapter 1};
    \node (c4) [below right=of c1]{Chapter 4};
    \node (c5) [below left=of c4]{Chapter 5};
    \node (c6) [right =of c5]{Chapter 6};
    \node (c7) [right =of c6]{Chapter 7};
    \node (c8) [right =of c7]{Chapter 8};
    \node (c9) [right =of c8]{Chapter 9};
    \node (c2) [below =of c5]{Chapter 2};
    \node (c3) [below right =of c2]{Chapter 3};
    % connect the nodes
    \draw[->] (c1) to[out=0,in=135] (c4);
    \draw[->] (c1.west) to[out=180,in=180] (c2.west);
    \draw[->] (c4) to[out=180,in=75] (c5);
    \draw[->] (c4) -- (c6);
    \draw[->] (c4.south east) -- (c7);
    \draw[->] (c4.east) to[out=0,in=110] (c8);
    \draw[->] (c4.east) to[out=0,in=110] (c9);
    \draw[->,dashed] (c2) -- (c5);
    \draw[->,dashed] (c2) -- (c6);
    \draw[->,dashed] (c2) -- (c7.south);
    \draw[->,dashed] (c2) -- (c8.south);
    \draw[->] (c2) -- (c3);
\end{tikzpicture}

\end{document}

Here's something that is a little better

enter image description here

As detailed in Caramdir's answer to Add more anchors to standard TikZ nodes the standard nodes have anchors node.〈angle〉 where angle is between 0 (=east) and 360, which I have used as follows

\draw[->] (c1) to[out=0,in=135] (c4);
\draw[->] (c1.west) to[out=180,in=180] (c2.west);
\draw[->] (c4) to[out=180,in=75] (c5);
\draw[->] (c4) -- (c6);
\draw[->] (c4.south east) -- (c7);
\draw[->] (c4.-5) to[out=0,in=110] (c8);
\draw[->] (c4.5) to[out=0,in=110] (c9);
\draw[->,dashed] (c2) -- (c5);
\draw[->,dashed] (c2) -- (c6);
\draw[->,dashed] (c2.5) to[out=0,in=225] (c7.south);
\draw[->,dashed] (c2.east) to[out=0,in=225] (c8.south);
\draw[->] (c2.-5) to[out=0,in=135] (c3.west);

Of course, all of this could probably be tidied up into a \foreach loop, but I find the code a little easier to read without.

cmhughes
  • 100,947
  • That's nearly perfect -- thank you. The only thing I need is the facility to `nudge' one node slightly in one direction... is that possible? – Mohan Oct 03 '12 at 19:39
  • 1
    @Mohan you can nudge these nodes by using, for example, below=1cm of... – cmhughes Oct 03 '12 at 19:50