3

I struggle creating a graphical representation of a books contents with TikZ. An example I've created in Powerpoint is attached. I am especially interested in relative positioning and no declaration of absolute lengths/positioning.

Example structure

I've played around with the following code:

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,calc}

\begin{document}
\begin{figure}
\begin{tikzpicture}[every node/.style=draw,scale=1.25] 
\tikzset{part/.style={fill=gray!20,minimum width=1em,minimum height=1.4em,align=left}}
\draw[fill=gray,minimum width=10em,minimum height=6em,align=left,anchor=south west]   (0,0) rectangle (8,4) coordinate[pos=.5](O);
\node [above=.5em,part,xshift=1em] (part1) at (O){Part I};
\node[on grid,part,below=2em of part1] (part2){Part II};
\node[on grid,part,below=2em of part2] (part2){Part III};   
\end{tikzpicture}
\end{figure}
\end{document}
pluton
  • 16,421
  • Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – AboAmmar Aug 02 '15 at 13:21
  • You can modify these http://tex.stackexchange.com/questions/232550/visual-table-of-contents-using-tikz-mindmap-or-similar and make a table instead of a mindmap – percusse Aug 02 '15 at 13:34
  • What is the meaning/significance behind some chapters being stacked and others listed next to each other? – Paul Gessler Aug 02 '15 at 13:48
  • There is no reason for stacking / listing...

    Sorry for not adding a MWE, but I thought this would do more harm than good...still I've added one now.

    – user3347232 Aug 02 '15 at 14:14

1 Answers1

2

A quick try (change the text and scale as you need by only changing \ut):

enter image description here

\documentclass[border=2pt,tikz]{standalone}
\usetikzlibrary{calc,positioning,backgrounds,fit}
\renewcommand{\rmdefault}{ptm}
\begin{document}

\newcommand{\ut}{4mm}
\begin{tikzpicture}[bk/.style args={#1}{draw,fill=gray!20,minimum height=2.7*\ut,minimum width=#1*\ut,align=center}, part/.style={inner sep=0pt,outer sep=0pt,font={\Large\bfseries}, white,align=left, xshift=-8*\ut}, node distance=.5*\ut]

\node[bk=30](c1){Chapter 1\\\textit{Chapter 1 Title}};
\node[bk=9.75,below=of c1.south west, anchor=north west](c2){Chapter 2\\\textit{Chapter 2 Title}};
\node[bk=19.75,below=of c1.south east, anchor=north east](c3){Chapter 3\\\textit{Chapter 3 Title}};

\node[part,left=of {$(c1.west)!.5!(c2.west)$},anchor=west](P1){Part I\\\textit{Part I Title}};

\begin{scope}[on background layer]
\node[rectangle,fill=gray!70,fit=(c1)(c2)(P1),inner sep=10pt] {};
\end{scope}

\node[bk=30,below=of c2.south west,anchor=north west,yshift=-2em](c1){Chapter 4\\\textit{Chapter 4 Title}};
\node[bk=30,below=of c1.south west, anchor=north west](c2){Chapter 5\\\textit{Chapter 5 Title}};
\node[bk=30,below=of c2.south east, anchor=north east](c3){Chapter 6\\\textit{Chapter 6 Title}};

\node[part,left=of {$(c1.west)!.5!(c3.west)$},anchor=west](P2){Part II\\\textit{Part II Title}};

\begin{scope}[shift={(0,-10*\ut)},on background layer]
\node[rectangle,fill=gray!70,fit=(c1)(c3)(P2),inner sep=10pt] {};
\end{scope}

\node[bk=30,below=of c3.south,anchor=north,yshift=-2em](c1){Chapter 7\\\textit{Chapter 7 Title}};
\node[bk=9.75,below=of c1.south west, anchor=north west](c2){Chapter 8\\\textit{Chapter 8 Title}};
\node[bk=9.75,below=of c1.south east, anchor=north east](c3){Chapter 10\\\textit{Chapter 10 Title}};
\node[bk=9.5,left=of c3.west, anchor=east](c4){Chapter 9\\ \textit{Chapter 9 Title}};

\node[part,left=of {$(c1.west)!.5!(c2.west)$},anchor=west](P3){Part III\\\textit{Part III Title}};

\begin{scope}[shift={(0,-24*\ut)},on background layer]
\node[rectangle,fill=gray!70,fit=(c1)(c2)(P3),inner sep=10pt] {};
\end{scope}

\end{tikzpicture}

\end{document}
AboAmmar
  • 46,352
  • 4
  • 58
  • 127
  • The TOC is not created automatically when using \chapter{}? – Sigur Aug 02 '15 at 14:30
  • This is not automatic as it should be. – pluton Aug 02 '15 at 15:50
  • @pluton And to what degree of automation that should be? – AboAmmar Aug 02 '15 at 16:36
  • A minor thing: How can the "Part Titles" be aligned on the left, instead of the center? – user3347232 Aug 03 '15 at 18:46
  • @user3347232 They are aligned on the left, do you mean they become closer to the background left edge? – AboAmmar Aug 03 '15 at 18:51
  • @user3347232 Hmmm yes, I think I got your point. They are now perfectly aligned, see my edit. I just made the anchor=west so they begin at the same vertical line and increased the xshift to the left to compensate. – AboAmmar Aug 03 '15 at 19:24
  • 1
    It should create the nodes from the table of contents entries. See the linked question in my comment. This assumes that we already know the entries. – percusse Aug 03 '15 at 19:41
  • see @percusse 's comments. The etoc package might be useful here: https://www.ctan.org/pkg/etoc – pluton Aug 05 '15 at 13:00