漂亮的目录:标题内容格式

漂亮的目录:标题内容格式

我正在尝试格式化目录中的 \chapter 和 \section 标题以达到这个目的:

在此处输入图片描述

我正在尝试使用 titlecontents 来实现这一点。这是我的代码和结果:

\documentclass[10pt,twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage[T1]{fontenc}
\usepackage{librecaslon}


\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titlesec}

\usepackage{titletoc}

\titlecontents{chapter}
              [0em]
              {\fontsize{14}{12} \selectfont \filcenter \addvspace{30pt}}%
              {PARTIE \thecontentslabel \\\rule{\linewidth}{0.5pt}\\}%
              {1em}%
              {}%
\titlecontents{section}
              [0em]
              {\fontsize{14}{12} \selectfont \addvspace{30pt}}%
              {Chapitre \thecontentslabel \hspace{1cm}}%
              {}%
              {\enspace \contentspage}%

\begin{document}

\tableofcontents

\chapter{Introduction}
\section{Conditions d'application}

\end{document}

有人知道如何改善这个吗?

  • 如何在“第 1 部分”和该行之间以及该行和“简介”之间添加空格?

  • 如何使“第 1 章”和“申请条件”采用不同的格式?

  • 如何将“申请条件”放在两行上?

  • 如何将页码放到正确的位置?

感谢大家的帮助 !


编辑:感谢@Bernard 的回答。使用此代码,我将目录分为两列:

\usepackage{pgffor}

\makeatletter
\newcommand{\twocolumntoc}{%
  \chapter*{\contentsname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
  \@starttoc{toc}%
}
\makeatother

如您所见,\part 的 \titlecontents 效果不佳。而且在这种情况下,页码似乎位置不太好(查看 \subsubsection 级别,称为“第 1 节”和“第 2 节”)。这是我的代码(我尝试过使用 \sloppy,效果好得多,但并不完美):

\documentclass[10pt,twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage[T1]{fontenc}
\usepackage{librecaslon}


\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titlesec}
\usepackage{titletoc}

\usepackage{supertabular}

\renewcommand{\baselinestretch}{0.7}

% **************************
% **************************
% /part formatting
% **************************
% **************************

\setcounter{secnumdepth}{6}
\setcounter{tocdepth}{6}


% **************************
% Fonction pour faire les deux traits encadrant les pages Livre et Partie.
% **************************

\newcommand\framethispage[1][1cm]{%
    \tikz[overlay,remember picture,line width=0.2pt]
    \draw([xshift=(#1),yshift=(-#1)]current page.north west) -- ([xshift=(#1),yshift=(#1)+2mm]current page.south west);%
    \tikz[overlay,remember picture,line width=0.2pt]
    \draw([xshift=(#1),yshift=(-#1)]current page.north west) -- ([xshift=(-#1)-2mm,yshift=(-#1)]current page.north east);%
}

% **************************
% Introduction générale --> \intropart
% **************************

\usepackage{changepage}
\strictpagecheck

\newcommand{\intropart}[1]{
\pagebreak
\checkoddpage
\ifoddpage
    \thispagestyle{empty} \framethispage[2cm] \vspace{-12cm} \Huge \begin{center}
    \textbf{#1}
    \end{center} \pagebreak
  \addcontentsline{toc}{chapter}{Introduction générale} % table of contents line
  %\markboth{\MakeUppercase{Introduction générale}}{}
  \small

\else
\newpage
\thispagestyle{empty}
\pagebreak
~
\newpage
\cleardoublepage
  \newpage \thispagestyle{empty} \framethispage[2cm] \vspace{-12cm} \Huge \begin{center} \textbf{#1} \end{center} \pagebreak
  \addcontentsline{toc}{part}{Introduction générale} % table of contents line
  %\markboth{\MakeUppercase{Introduction générale}}{}
  \newpage
  \pagebreak
  \small
  ~
\fi
\thispagestyle{empty} \cleardoublepage
}

% **************************
% Introduction --> \introchap
% **************************

\newcommand{\introchapter}[1]{\begin{center}
    \textbf{\fontsize{16}{12} \selectfont #1} \vspace{3cm}
\end{center}
  \addcontentsline{toc}{chapter}{Introduction} % table of contents line

}


% **************************
% Livre 1 --> \part
% **************************

\renewcommand{\thepart}{\arabic{part}}

\makeatletter
\def\@part[#1]#2{%
\thispagestyle{empty}
\framethispage[2cm]
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
{\parindent \z@ 
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >\m@ne
\vspace{-9.5cm}
\begin{center}
\begin{tikzpicture}[my node/.style={anchor=base,inner sep=0pt}]
\node[my node] (center) {\fontsize{12}{12} \selectfont \frutL \text{Livre} \thepart};
\draw($(center.base)+(-1.9cm,-1ex)$)     -- ($(center.base)+(+1.9cm,-1ex)$);
\end{tikzpicture}
\end{center}
\par\nobreak
\fi
\begin{center}
\fontsize{18}{12} \selectfont \acasR #2
\end{center}
\markboth{}{}\par}
\newpage
\@afterheading}
\makeatother


% **************************
% Titre
% **************************

\renewcommand{\contentsname}{\begin{center}
    TABLE ANALYTIQUE
\end{center}

}

% **************************
% Deux colonnes
% **************************

\usepackage{pgffor}

\makeatletter
\newcommand{\twocolumntoc}{%
  \chapter*{\contentsname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
  \@starttoc{toc}%
}
\makeatother

% **************************
% Mise en forme
% **************************

\titlecontents{part}
              [0em]
              {\Large\bfseries\filcenter \addvspace{15pt}}%
              {\qquad\textsf{\textsc{Livre}\enspace\thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%
\titlecontents{chapter}
              [0em]
              {\Large\bfseries\filcenter \addvspace{15pt}}%
              {\qquad\textsf{\textsc{Partie}\enspace\thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%
\titlecontents{section}
              [0em]
              {\Large\bfseries\filcenter \addvspace{15pt}}%
              {\qquad\textsf{\textsc{Titre}\enspace\thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%
\titlecontents{subsection}
              [0em]
              {\large\bfseries \addvspace{8pt}}%
              {\contentspush{\sffamily \textsc{Chapitre} \thecontentslabel \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\titlecontents{subsubsection}
              [0em]
              {\large\bfseries \addvspace{8pt}}%
              {\contentspush{\sffamily \textsc{Section} \thecontentslabel \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\titlecontents{subsubsubsection}
              [5pt]
              {\large\bfseries \addvspace{8pt}}%
              {\contentspush{\thecontentslabel \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\titlecontents{paragraph}
              [10pt]
              {\large \addvspace{8pt}}%
              {\contentspush{\thecontentslabel\text{.} \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\titlecontents{subparagraph}
              [20pt]
              {\large \addvspace{3pt}}%
              {\contentspush{\thecontentslabel\text{°} \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\begin{document}
\sloppy

\part{Part level not working}

\chapter{Pretty long title}

\section{Title test}

\section{Title test}

\subsection{Title test}

\subsubsection{Title tesssssssst}

\subsubsubsection{Title test}

\subparagraph{Title test}

\subparagraph{Title test}

\paragraph{Title test}

\subsubsubsection{Title test}

\subsubsection{Title test Title test}

\section{Title test}

\chapter{Title test}
\part{Part again}

\twocolumn
\twocolumntoc

\end{document}

结果如下(看“第 1 部分”):

在此处输入图片描述

答案1

我建议这样做,尽管我不确定我是否理解了您的所有要求:您所说的“不同格式”是什么意思?我将其解释为使用“第 1 章”的小型大写无衬线字体,因此我不得不使用带有小型大写字母的无衬线字体(TeX-Gyre Heros)。至于两行标题,如果标题太长,则会自动进行。我使用了比您的标题更长的标题来展示如何使用内容边距来完成。添加了 \contentspush 命令以具有悬挂格式。

\documentclass[10pt ,twoside, french]{book}
\usepackage{geometry}
\usepackage{babel}
\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage[T1]{fontenc}
\usepackage{librecaslon}
\usepackage[scale = 1.02]{tgheros}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titlesec}

\usepackage{titletoc}
\contentsmargin[1em]{4em}
\titlecontents{chapter}
              [0em]
              {\Large\bfseries\filcenter \addvspace{30pt}}%
              {\qquad\textsf{\textsc{Partie}\enspace\thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%
\titlecontents{section}
              [0em]
              {\large\bfseries \addvspace{30pt}}%
              {\contentspush{\sffamily \textsc{Chapitre} \thecontentslabel \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%

\begin{document}

\tableofcontents

\chapter{Introduction}

\section{Conditions d'application, menues billevesées et autres fariboles}

\end{document}

在此处输入图片描述

编辑

\part以下是您可以用来获得符合您的需求的播放和两列表目代码:

 \titleformat{\part}[display]{%
 \AddToShipoutPictureBG*{\AtPageLowerLeft{%
\hskip20mm\rule[22mm]{0.5pt}{\dimexpr\paperheight-42mm}}%
\AtPageUpperLeft{\hskip20mm\rule[-20mm]{\dimexpr\paperwidth-42mm}{0.5pt}}}\filcenter}%
 {\fontsize{12}{12}\selectfont{\frutL Livre~\thepart}\\ \rule[2pt]{3.8cm}{0.5pt}}{20pt}{\fontsize{18}{12} \selectfont}

\titlecontents{part}
              [0em]
              {\Large\bfseries\filcenter \addvspace{15pt}}%
              {\qquad\textsf{\textsc{Livre}~thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%

在此处输入图片描述

相关内容