![自定义目录](https://linux22.com/image/366565/%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9B%AE%E5%BD%95.png)
我想从这个例子开始定制我的目录:如何使用 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
- 将点替换
\hfill
为\dotfill
要删除参考书目前面的灰色框,您可以使用语法
\titlecontents
并为未编号的章节定义单独的格式:\titlecontents{⟨section⟩}[⟨left⟩]{⟨above-code⟩} {⟨numbered-entry-format⟩}{⟨numberless-entry-format⟩}{⟨filler-page-format⟩}[⟨below-code⟩]
- 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}