6

I want to create a tufte-book style ToC, very similar to how Gonzalo Medina made something in this request: Pretty Table of Contents

So far this is what I got:

\documentclass[letterpaper]{article}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage[some]{background}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{shadows}

\definecolor{col2}{HTML}{80B2FF}

\DeclareFixedFont{\bigsf}{T1}{phv}{b}{n}{1.5cm}

\backgroundsetup{
scale=1,
angle=0,
opacity=1,
contents={\begin{tikzpicture}[remember picture,overlay]
 \path [fill=col2] (-0.5\paperwidth,5) rectangle (0.5\paperwidth,10);  
\end{tikzpicture}}
}
\begin{document}
\begin{titlepage}
\BgThispage
\newgeometry{left=1cm,right=4cm}
\vspace*{2cm}
\noindent
\textcolor{white}{\bigsf Reader analyse}   \begin{tikzpicture}[overlay]
    \def\nodeshadowed[#1]#2;{\node[scale=6,above,#1]{#2};\node[scale=6,
        above,#1,yscale=-1,scope fading=south,opacity=0.3]{#2};}
    \nodeshadowed [at={(4.5,-.5  )},yslant=-.08]
        {\Huge \textcolor{blue}{R}};
  \end{tikzpicture}
\vspace*{2.5cm}\par
\noindent
\begin{minipage}{0.35\linewidth}
    \begin{flushright}
I wish the chapter numbers were here
    \end{flushright}
\end{minipage} \hspace{15pt}
%
\begin{minipage}{0.02\linewidth}
    \textcolor{col2}{\rule{1pt}{300pt}}
\end{minipage} \hspace{-10pt}
%
\begin{minipage}{0.6\linewidth}
\vspace{5pt}
I wish the chapter titles were here
\end{minipage}
\end{titlepage}
\restoregeometry
\lipsum[1-2]
\end{document}

Any way of achieving the same effect as the example below, but instead in article class:

\documentclass{tufte-book}
\usepackage{lmodern}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}

\newcounter{chapmark}
\setcounter{tocdepth}{1}

\colorlet{mycolor}{BrickRed}

\titlecontents{chapter}%
  [0em]
  {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape}
  {\hspace*{0em}\thecontentslabel}
  {\hspace*{0em}\llap{%
    \parbox[b]{40pt}{%
      \fontsize{25}{30}\sffamily\bfseries\color{mycolor}%
      \hfill\thecontentspage%
      }\hspace{20pt}%
    }%
  }
  {\rmfamily\upshape\qquad}
  [\end{fullwidth}]

\titlecontents{section}
  [0em]
  {\vspace{0\baselineskip}\begin{fullwidth}\Large\rmfamily\itshape}
  {\hspace*{0em}\contentslabel{2em}}
  {\llap{\parbox[b]{40pt}{\hfill\thecontentspage}\hspace{20pt}}\hspace*{0em}}
  {\rmfamily\upshape\qquad}
  [\end{fullwidth}]

\titlecontents{subsection}
  [0em]
  {\vspace{-.15\baselineskip}\begin{fullwidth}\large\rmfamily\itshape}
  {\hspace*{0em}\contentslabel{4em}}
  {\llap{\parbox[b]{40pt}{\hfill\small\thecontentspage}\hspace{20pt}}\hspace*{0em}}
  {\rmfamily\upshape}
  [\end{fullwidth}] 

\newcommand\StartMark{%
\addtocontents{toc}{\protect\label{st\thechapmark}%
\par\protect\begin{tikzpicture}[overlay,remember picture,baseline]   
  \protect\node [anchor=base] (s\thechapmark) {};%
  \ifnum\getpagerefnumber{st\thechapmark}=\getpagerefnumber{en\thechapmark}   
  \else
    \protect\draw[mycolor,line width=3pt] 
      let \protect\p3= (s\thechapmark),%
            \protect\p4 = (current page text area.south) in %
      ( $ (0em,\protect\y3) + (-20pt,-5ex) $ ) -- 
      ( $ (0em,\protect\y4) + (-20pt,-5pt) $ );
  \fi
\protect\end{tikzpicture}\par}%
}

\newcommand\EndMark{%
\addtocontents{toc}{\protect\label{en\thechapmark}%
\par\protect\begin{tikzpicture}[overlay,remember picture,baseline]   
  \protect\node [anchor=base] (e\thechapmark) {};
  \ifnum\getpagerefnumber{st\thechapmark}=\getpagerefnumber{en\thechapmark} 
    \protect\draw[mycolor,line width=3pt] 
    let \protect\p1= (s\thechapmark), 
          \protect\p2=(e\thechapmark) in %
    ( $ (0em,\protect\y1) + (-20pt,-5ex) $ ) -- 
    ( $ (0em,\protect\y2) + (-20pt,2ex) $ );
  \else%
  \protect\draw[mycolor,line width=3pt] 
  let \protect\p1= (e\thechapmark), 
        \protect\p2=(current page text area.north) in 
  ( $ (0em,\protect\y2) + (-20pt,5pt) $ ) -- 
  ( $ (0em,\protect\y1) + (-20pt,2ex) $ );
  \fi
\protect\end{tikzpicture}\par}%
\stepcounter{chapmark}%
}

\setcounter{page}{123}% just for the example

\begin{document}

\tableofcontents

\StartMark
\chapter{Beginning to learn design with \LaTeX}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\EndMark

\StartMark
\chapter{Beginning to learn design with HTML}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\EndMark

\StartMark
\chapter{Beginning to learn design with \LaTeX\ again}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\EndMark

\StartMark
\chapter{Beginning to learn design with \LaTeX\ again}
\section{This is a test section}
\section{This is a test section}
\section{This is a test section}
\EndMark

\end{document}
  • I am confused. You mention that you want to design a ToC, but I don't see any sectional units in your first example code. Exactly what info should be written when you say "chapter number" and "chapter title"? (notice that article doesn't provide a \chapter command). – Gonzalo Medina Jul 4 '14 at 16:36
  • @GonzaloMedina You made some cool Tufte-style ToC for the tufte-book class. I'm looking to mimic the exact same thing, but for class article instead. I tried handling the \section command the same as how you recoded \chapter in conjunction with your chapter Marks, but I can't even come close to the same result. :-( – 1010011010 Jul 4 '14 at 17:05
  • I provided an answer using article. Is it something like that waht you are trying to achieve? – Gonzalo Medina Jul 4 '14 at 17:27
9
+100

Here's one possibility:

\documentclass[dvipsnames,svgnames,x11names]{article}
\usepackage{refcount}
\usepackage{titletoc}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}

\newcounter{chapmark}
%\setcounter{tocdepth}{1}

\colorlet{mycolor}{BrickRed}

\titlecontents{section}%
  [0em]
  {\vspace{1.5\baselineskip}\LARGE\rmfamily\itshape}
  {\hspace*{0em}\llap{\parbox[t]{40pt}{\hfill\color{mycolor}\thecontentspage}\hspace*{10pt}}}
  {\thecontentspage}
  {\rmfamily\upshape\qquad}

\titlecontents{subsection}%
  [0em]
  {\vspace{.3\baselineskip}\large\rmfamily\itshape}
  {\hspace*{0em}\llap{\parbox[t]{40pt}{\hfill\color{mycolor}\thecontentspage}\hspace*{10pt}}}
  {\thecontentspage}
  {\rmfamily\upshape\qquad}

\titlecontents{subsubsection}%
  [0em]
  {\vspace{.3\baselineskip}\normalsize\rmfamily\itshape}
  {\hspace*{0em}\llap{\parbox[t]{40pt}{\hfill\color{mycolor}\thecontentspage}\hspace*{10pt}}}
  {\thecontentspage}
  {\rmfamily\upshape\qquad}

\newcommand\StartMark{%
\addtocontents{toc}{\protect\label{st\thechapmark}%
\par\protect\begin{tikzpicture}[overlay,remember picture,baseline]   
  \protect\node [anchor=base] (s\thechapmark) {};%
  \ifnum\getpagerefnumber{st\thechapmark}=\getpagerefnumber{en\thechapmark}   
  \else
    \protect\draw[mycolor,line width=3pt] 
      let \protect\p3= (s\thechapmark),%
            \protect\p4 = (current page text area.south) in %
      ( $ (0em,\protect\y3) + (-20pt,-5ex) $ ) -- 
      ( $ (0em,\protect\y4) + (-20pt,5pt) $ );
  \fi
\protect\end{tikzpicture}\par}%
}

\newcommand\EndMark{%
\addtocontents{toc}{\protect\label{en\thechapmark}%
\par\protect\begin{tikzpicture}[overlay,remember picture,baseline]   
  \protect\node [anchor=base] (e\thechapmark) {};
  \ifnum\getpagerefnumber{st\thechapmark}=\getpagerefnumber{en\thechapmark} 
    \protect\draw[mycolor,line width=3pt] 
    let \protect\p1= (s\thechapmark), 
          \protect\p2=(e\thechapmark) in %
    ( $ (0em,\protect\y1) + (-20pt,-5ex) $ ) -- 
    ( $ (0em,\protect\y2) + (-20pt,2ex) $ );
  \else%
  \protect\draw[mycolor,line width=3pt] 
  let \protect\p1= (e\thechapmark), 
        \protect\p2=(current page text area.north) in 
  ( $ (0em,\protect\y2) + (-20pt,5pt) $ ) -- 
  ( $ (0em,\protect\y1) + (-20pt,2ex) $ );
  \fi
\protect\end{tikzpicture}\par}%
\stepcounter{chapmark}%
}

\setcounter{page}{123}% just for the example

\begin{document}

\tableofcontents

\StartMark
\section{A test section}
\subsection{This is a test subsection}
\subsubsection{This is a test subsubsection}
\subsubsection{This is another test subsubsection}
\subsection{This is a test subsection}
\subsection{This is a test subsection}
\subsection{This is a test subsection}
\EndMark


\StartMark
\section{Another test section}
\subsection{This is a test subsection}
\subsection{This is a test subsection}
\subsubsection{This is a test subsubsection}
\subsubsection{This is another test subsubsection}
\EndMark

\StartMark
\section{Yet another test section}
\subsection{This is a test subsection}
\subsection{This is a test subsection}
\subsubsection{This is a test subsubsection}
\subsubsection{This is another test subsubsection}
\subsection{This is a test subsection}
\subsubsection{This is a test subsubsection}
\subsubsection{This is another test subsubsection}
\subsection{This is a test subsection}
\subsubsection{This is a test subsubsection}
\subsubsection{This is another test subsubsection}
\subsection{This is a test subsection}
\subsubsection{This is a test subsubsection}
\subsubsection{This is another test subsubsection}
\EndMark

\end{document}

enter image description here

  • I had to do some debugging last night with the crew; under some circumstances your definition of \EndMark produces an infinite recursion (see tex.stackexchange.com/questions/219019/…). It may be a good idea to update the answer here accordingly, by replacing \par with \protect\par (for future visitors). – 1010011010 Dec 22 '14 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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