How can I make a ToC
like the following?
MWE:
\documentclass[10pt,a4paper,openany]{book}
\usepackage{titletoc,xcolor}
\titlecontents{chapter}% <section-type>
[0pt]% <left>
{}% <above-code>
{\fcolorbox{blue}{blue}{\color{white}\bfseries\chaptername~ \thecontentslabel}}% <numbered-entry-format>
{}% <numberless-entry-format>
{\bfseries\hfill\contentspage}% <filler-page-format>
\begin{document}
\tableofcontents
\chapter{First Chapter}
\section{First Section}
\section{Second Section}
\chapter{Second Chapter}
\section{First Section}
\section{Second Section}
sample
\end{document}
Best Answer
A first trial version, requires some more setup for the chapter title line. (I used the traditional
\addcontentsline
way, nottitlesec
)Don't use too long lines for the chapter lines! I've added just one to show the negative effect of this.
Update with better spacing
Update for
vietnam
package