自定义目录

自定义目录

我想从这个例子开始定制我的目录:如何使用 TikZ 自定义目录?

我已经做了一些改变,但我想要更多,这是我的代码:

\documentclass[12pt,a4paper]{report}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage[tmargin=2cm,rmargin=4cm,lmargin=4cm,bmargin=2cm]{geometry}
\usepackage{kpfonts}
\usepackage{tikz}
\definecolor{doc}{RGB}{0,60,110}
\usepackage{titletoc}
\contentsmargin{0cm}
\titlecontents{chapter}[0pc]
{\addvspace{30pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=doc!30,draw=doc!30] (-4,-.2) rectangle (-0.5,.5);%
\pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\Large\sc\bfseries chapitre\                                             
\thecontentslabel};%
\end{tikzpicture}\color{doc!40}\large\sc\bfseries}%
{}
{}
{\;\titlerule\;\large\sc\bfseries Page \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=doc!20] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%
\titlecontents{section}[2.4pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
[]
\titlecontents{subsection}[5pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
[]
\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{doc!30}\Huge\sc\bfseries    
\contentsname};%
\draw[fill=doc!30,draw=doc!30] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge\sc\bfseries 
\contentsname};%
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
\begin{document}
\tableofcontents
\chapter{Premier Chapitre}
\section{Titre Section 1}
\subsection{Titre sous Section 1}
\subsection{Titre sous Section 1}
\chapter{Deuxième Chapitre}
\section{Titre Section 1}
\subsection{Titre sous Section 1}
\section{Titre Section 1}
\subsection{Titre sous Section 2}
\chapter*{ Bibliographie}
\addcontentsline{toc}{chapter}{Bibliographie}
\end{document}  

以下是我得到的结果:

在此处输入图片描述

这是我想要做的改变: 在此处输入图片描述

答案1

  1. 将点替换\hfill\dotfill
  2. 要删除参考书目前面的灰色框,您可以使用语法\titlecontents并为未编号的章节定义单独的格式:

    \titlecontents{⟨section⟩}[⟨left⟩]{⟨above-code⟩} {⟨numbered-entry-format⟩}{⟨numberless-entry-format⟩}{⟨filler-page-format⟩}[⟨below-code⟩] 
    
  3. babel 选项francais已弃用,请french改用。

\documentclass[12pt,a4paper]{report}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[tmargin=2cm,rmargin=4cm,lmargin=4cm,bmargin=2cm]{geometry}
\usepackage{kpfonts}
\usepackage{tikz}
\definecolor{doc}{RGB}{0,60,110}
\usepackage{titletoc}
\contentsmargin{0cm}


\titlecontents{chapter}[0pc]
{\addvspace{30pt}}%
{\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=doc!30,draw=doc!30] (-4,-.2) rectangle (-0.5,.5);%
\pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\Large\sc\bfseries chapitre\                                             
\thecontentslabel};%
\end{tikzpicture}\color{doc!40}\large\sc\bfseries}
{\color{doc!40}\large\sc\bfseries}
{\color{doc!40}\;\titlerule\;\large\sc\bfseries Page \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=doc!20] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%

\titlecontents{section}[2.4pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\dotfill\small \thecontentspage}
[]
\titlecontents{subsection}[5pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\dotfill\small \thecontentspage}
[]
\makeatletter

\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{doc!30}\Huge\sc\bfseries    
\contentsname};%
\draw[fill=doc!30,draw=doc!30] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge\sc\bfseries 
\contentsname};%
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
\begin{document}
\tableofcontents
\chapter{Premier Chapitre}
\section{Titre Section 1}
\subsection{Titre sous Section 1}
\subsection{Titre sous Section 1}
\chapter{Deuxième Chapitre}
\section{Titre Section 1}
\subsection{Titre sous Section 1}
\section{Titre Section 1}
\subsection{Titre sous Section 2}
\chapter*{ Bibliographie}
\addcontentsline{toc}{chapter}{Bibliographie}
\end{document}  

在此处输入图片描述

相关内容