Update:
Most of the idea exposed in the initial version is now made automatically, adding support for unnumbered chapters:
\documentclass[openany]{book}
\usepackage{chappg}
\usepackage{pgfplots}
\usepackage{lipsum}
\usepackage{nameref}
\usepackage{showkeys}
\definecolor{ylgnbu1}{RGB}{255, 255, 204}
\definecolor{ylgnbu2}{RGB}{161, 218, 180}
\definecolor{ylgnbu3}{RGB}{65, 182, 196}
\definecolor{ylgnbu4}{RGB}{37, 52, 148}
\definecolor{ylgnbu5}{RGB}{44, 127, 184}
\definecolor{ylgnbu6}{RGB}{80, 40, 84}
\pgfplotsset{compat=1.9}
\pgfplotsset{
/pgfplots/bar cycle list/.style={/pgfplots/cycle list={%
{black,fill=ylgnbu1,mark=none},%
{black,fill=ylgnbu2,mark=none},%
{black,fill=ylgnbu3!70,mark=none},%
{black,fill=ylgnbu4!20,mark=none},%
{black,fill=ylgnbu5!70,mark=none},%
{black,fill=ylgnbu6!70,mark=none},%
}
},
}
\newcounter{tmp}
% definition of 100 auxialiary counters
\makeatletter
\loop
\stepcounter{tmp}
\ifnum\value{tmp}<101
\newcounter{nochappg\roman{tmp}}
\repeat
\newcounter{nochappg}
\usepackage{etoolbox}
\setcounter{tmp}{0}
\pretocmd{\chapter}{\setcounter{nochappg\roman{tmp}}{\value{page}}}{}{}
\def\@makechapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\huge\bfseries \@chapapp\space \thechapter
\par\nobreak
\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}%
\global\refstepcounter{tmp}%
\label{chap:\arabic{tmp}}%
}
\def\@makeschapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}%
\global\refstepcounter{tmp}%
\label{chap:\arabic{tmp}}%
}
\renewcommand\chapter{%
\setcounter{nochappg\roman{tmp}}{\value{page}}%
\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}
\makeatother
\begin{document}
\chapter*{Intro}
\lipsum[4]
\chapter*{Preface}
\pagenumbering{bychapter}
\lipsum
\chapter{Test chapter one}
\lipsum
\chapter{Test chapter two}
\lipsum[1-30]
\chapter{Test chapter three}
\lipsum[1-80]
\chapter{Test chapter four}
\lipsum[1-15]
\chapter{Test chapter five}
\lipsum[1-30]
\setcounter{nochappg\roman{tmp}}{\value{page}}
\thenochappgv
\begin{tikzpicture}
\begin{axis}[
height=\textwidth,
ybar stacked,
axis lines=none,
nodes near coords,
bar width=20pt,
xmin=0,
xmax=2,
legend style={
at={(0.75,0.55)},
anchor=west,
legend columns=2
}
]
\addplot+[ybar] coordinates {(1,\thenochappgi)};
\addplot+[ybar] coordinates {(1,\thenochappgii)};
\addplot+[ybar] coordinates {(1,\thenochappgiii)};
\addplot+[ybar] coordinates {(1,\thenochappgiv)};
\addplot+[ybar] coordinates {(1,\thenochappgv)};
\addplot+[ybar] coordinates {(1,\thenochappgvi)};
\addplot+[ybar] coordinates {(1,\thenochappgvii)};
\legend{\nameref{chap:1},\nameref{chap:2},\nameref{chap:3},\nameref{chap:4},\nameref{chap:5},\nameref{chap:6},\nameref{chap:7}}
\end{axis}
\end{tikzpicture}
\end{document}
To do:
Write the value for the counters in an auxiliary file..
Automate the plot at the end.
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/HPVmA.png)
A proof of concept:
\documentclass[openany]{book}
\usepackage{chappg}
\usepackage{pgfplots}
\usepackage{lipsum}
\usepackage{nameref}
\definecolor{ylgnbu1}{RGB}{255, 255, 204}
\definecolor{ylgnbu2}{RGB}{161, 218, 180}
\definecolor{ylgnbu3}{RGB}{65, 182, 196}
\definecolor{ylgnbu4}{RGB}{37, 52, 148}
\definecolor{ylgnbu5}{RGB}{44, 127, 184}
\pgfplotsset{compat=1.9}
\pgfplotsset{
/pgfplots/bar cycle list/.style={/pgfplots/cycle list={%
{black,fill=ylgnbu1,mark=none},%
{black,fill=ylgnbu2,mark=none},%
{black,fill=ylgnbu3!70,mark=none},%
{black,fill=ylgnbu4!20,mark=none},%
{black,fill=ylgnbu5!70,mark=none},%
}
},
}
\newcounter{nochappgi}
\newcounter{nochappgii}
\newcounter{nochappgiii}
\newcounter{nochappgiv}
\newcounter{nochappgv}
\begin{document}
\chapter{Test chapter one}
\label{chap:one}
\lipsum
\setcounter{nochappgi}{\value{page}}
\thenochappgi
\chapter{Test chapter two}
\label{chap:two}
\lipsum[1-30]
\setcounter{nochappgii}{\value{page}}
\thenochappgiii
\chapter{Test chapter three}
\label{chap:three}
\lipsum[1-80]
\setcounter{nochappgiii}{\value{page}}
\thenochappgiii
\chapter{Test chapter four}
\label{chap:four}
\lipsum[1-15]
\setcounter{nochappgiv}{\value{page}}
\thenochappgiv
\chapter{Test chapter five}
\label{chap:five}
\lipsum[1-30]
\setcounter{nochappgv}{\value{page}}
\thenochappgiv
\begin{tikzpicture}
\begin{axis}[
height=\textwidth,
ybar stacked,
axis lines=none,
nodes near coords,
bar width=20pt,
xmin=0,
xmax=2,
legend style={
at={(0.75,0.55)},
anchor=west,
legend columns=2
}
]
\addplot+[ybar] coordinates {(1,\thenochappgi)};
\addplot+[ybar] coordinates {(1,\thenochappgii)};
\addplot+[ybar] coordinates {(1,\thenochappgiii)};
\addplot+[ybar] coordinates {(1,\thenochappgiv)};
\addplot+[ybar] coordinates {(1,\thenochappgv)};
\legend{\nameref{chap:one},\nameref{chap:two},\nameref{chap:three},\nameref{chap:four},\nameref{chap:five}}
\end{axis}
\end{tikzpicture}
\end{document}
The plot obtained shows a stacked bar plot corresponding to the number of pages of each chapter; the legend also contains the names for the chapters:
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/uufEA.png)
Some remarks:
- The idea is to use a mechanism similar to the one used by the
chappg
package, to get the number of pages for each chapter.
- This values are stored at the end of each chapter (this info can be written, for example, to the
.aux
file).
- Using the stored values,
pgfplots
is used to easily produce the desired plot.
.aux
file) would contain the data needed to construct it..aux
file, an entry such as\@writefile{toc}{\contentsline {subsection}{\numberline {1.1}AA}{1}}
would indicate that subsection 1.1, entitled "AA", begins on page 1.