How to modify the table of contents to appear similar to this.Alignments are temporary but it should be similar.How do I do it?
Asked
Active
Viewed 333 times
3
subham soni
- 9,673
-
Related: http://tex.stackexchange.com/questions/35825/pretty-table-of-contents – Henri Menke Jan 28 '14 at 16:16
1 Answers
6
One option using TikZ:
\documentclass{article}
\usepackage{tikz}
\definecolor{myblue}{RGB}{0,162,232}
\setcounter{secnumdepth}{0}
\renewcommand\contentsname{\textcolor{myblue}{\itshape\large Whats inside...}}\makeatletter
\makeatletter
\renewcommand\tableofcontents{%
{\centering\contentsname\par\bigskip}
\@mkboth{%
\MakeUppercase\contentsname}{\MakeUppercase\contentsname}%
\@starttoc{toc}%
}
\renewcommand*\l@section[2]{%
\ifnum \c@tocdepth >\z@
\addpenalty\@secpenalty
\addvspace{1.0em \@plus\p@}%
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip\hfill
\begin{tikzpicture}
\node[
fill=myblue,
text width=\dimexpr.65\linewidth-8pt\relax,
rounded corners=3pt,
text height=3ex,
text depth=1.8ex
] (secen)
{\parbox{2.6em}{\mbox{}}%
\parbox{\dimexpr\linewidth-8pt-2.6em\relax}{%
\raggedright\normalfont\itshape\textcolor{white}{#1}}%
};
\node[circle,fill=white,inner sep=5pt] at ([xshift=18pt]secen.west) {};
\end{tikzpicture}\hfill\null\par
\endgroup
\fi}
\makeatother
\begin{document}
\tableofcontents
\section{A title for the first section}
\section{A title for the second section}
\section{A title for the third section; it will span several lines}
\end{document}

Using packages such as titlesec and/or titletoc, the number of lines of code can be reduced.
Gonzalo Medina
- 505,128