如何在我的文档中添加两个目录?

如何在我的文档中添加两个目录?

我需要两个目录:一个必须简短,它是一个概述;另一个必须详细,必须包含每个部分。后者将插入到我的文档末尾,紧接着我的参考部分。我在这里找不到任何可以帮助我找到如何做到这一点的主题。我认为我的序言非常复杂。它可以解释为什么我的目录设置对输出没有影响。这是我的 MWE:

\documentclass[hidelinks,12pt,twoside,openright,a4paper]{book}
\usepackage{setspace}

\usepackage{lipsum}

\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}

\usepackage{titlesec}
\usepackage{titling}
\titleformat*{\section}{\normalsize\itshape}
\titleformat*{\subsection}{\normalsize\itshape}
\titleformat*{\subsubsection}{\normalsize\itshape}

%%%%%%%points pour chapitres dans toc%%%%%%%%%%
\usepackage{tocloft}
\setlength{\cftbeforechapskip}{3pt}%espace entre chapitres
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % for chapters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{hyperref}
\usepackage[numberedbib,nosectionbib]{apacite}
\usepackage[makeindex]{imakeidx}
\makeindex[name=npr, title=Index des noms] 
\makeindex[name=mat, title=Index des matières]

\usepackage{fancyhdr}
\pagestyle{fancy}
% We don't want chapter and section numbers
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{} % sets both header and footer to nothing
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\textit{A name}} % even pages: chapter title
\fancyhead[CO]{\textit\leftmark} % odd pages: book title


%%%%%%%%%%%%Pas de N° de chapitres%%%%%%%%%%%%%%%%%%%%

\usepackage{titlesec}
\titleformat{\chapter}[display]%
    {\centering\Large\bfseries}% format of chapter
    {\large\normalfont\MakeUppercase{\chaptertitlename}\enskip\thechapter}% format of the label
    {.5\baselineskip}{} % space between the two
\titlespacing*{\chapter}{0pt}{25pt}{35pt} % spaces around \chapter{}, {left}{before}{after}
 
%\titleformat{\chapter}[display]
  %{\normalfont\bfseries}{}{0pt}{\Huge}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%épigraphe%%%%%%%%%%%%
\makeatletter
\renewcommand{\@chapapp}{}% Not necessary...
\newenvironment{chapquote}[2][2em]
  {\setlength{\@tempdima}{#1}%
   \def\chapquote@author{#2}%
   \parshape 1 \@tempdima \dimexpr\textwidth-2\@tempdima\relax%
   \itshape}
  {\par\normalfont\hfill---\ 
 \chapquote@author\hspace{\@tempdima}\par\bigskip\par\bigskip}
\makeatother

%%%%%%%%%%%%%Numérotation en chiffres arabes%%%%%%%%%%%%%%%%%%%
\makeatletter
\renewcommand\frontmatter{%
  \cleardoublepage
  \@mainmatterfalse
  %\pagenumbering{roman}% Don't reset
}
\renewcommand\mainmatter{%
  \cleardoublepage
  \@mainmattertrue
  %\pagenumbering{arabic}% Don't reset
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

\begin{document}
\title{A title}
\author{A name}
\date{}
\maketitle


\renewcommand{\contentsname}{Sommaire}
\tableofcontents
\frontmatter

\mainmatter
\part{A part}

\chapter{A chapter}
\lipsum
\section{A section}
\lipsum
\subsection{A subsection}

\subsubsection{A subsubsection}



\part{Another part}

\chapter{Another chapter}

\section{Another section}

\subsection{Another subsection}

\subsubsection{Another subsubsection}


\backmatter
\chapter{Conclusion}



\renewcommand{\contentsname}{Table des matières détaillée}
\tableofcontents

\end{document}

答案1

问题是,它\tableofcontents在内部使用了\@starttoc一个宏,它输入 .toc 文件,然后立即通过它销毁它,\newwrite...\immediate\openout以便在 LaTeX 运行结束时可以从 LaTeX 运行期间产生的 .aux 文件中重新写入它。因此,您不能多次调用,\tableofcontents因为第一次调用已经销毁了 .toc 文件。

您可以做的是修补\@starttoc-command 的副本,以便它不会破坏 .toc 文件,并确保除了\tableofcontents最后一个实例之外的所有实例都使用修补后的副本而不是原始\@starttoc-command。补丁的外观取决于您的 LaTeX 内核的更新程度。然后,每次调用时,\tableofcontents您都可以调整tocdepth

您可以将“摘要”放入“物料明细表”,反之亦然,例如,通过加载包托比宾 并通过

\begingroup\addtocontents{toc}{\string\if...}\..true\tableofcontents\addtocontents{toc}{\string\fi}\endgroup

将其放置\if... \fi在.toc 文件的相应条目周围。

在下面的例子中托比宾以在零件级别列出“摘要”和“详细信息表”的方式加载。

\documentclass[hidelinks,12pt,twoside,openright,a4paper]{book}
\setlength{\headheight}{14.49998pt}%
\addtolength{\topmargin}{-2.49998pt}%
\usepackage{etoolbox}
\makeatletter
\@ifdefinable\my@starttoc{\let\my@starttoc\@starttoc}%
\patchcmd{\my@starttoc}{%
  \if@filesw\expandafter\newwrite\csname tf@#1\endcsname
  \immediate\openout\csname tf@#1\endcsname\jobname.#1\relax
  \fi
}{}{}{%
  \@latex@error{\string\my@starttoc\space could not be patched to be 
                \MessageBreak a variant of \string\@starttoc\space that does not
                \MessageBreak destroy the file%
   }{%
     Via \string\show\space look at the definition of \string\@starttoc\space and
     \MessageBreak modify the patching-directive accordingly.%
   }%
}%
\makeatother

\usepackage{setspace}

\usepackage{lipsum}

\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}

\usepackage[other]{tocbibind}% Add table of contents etc to contents on part-level
\tocotherhead{part}
\newif\ifsommaireintoc\sommaireintocfalse
\newif\ifmatieresdetaileeintoc\matieresdetaileeintoctrue



\usepackage{titlesec}
\usepackage{titling}
\titleformat*{\section}{\normalsize\itshape}
\titleformat*{\subsection}{\normalsize\itshape}
\titleformat*{\subsubsection}{\normalsize\itshape}

%%%%%%%points pour chapitres dans toc%%%%%%%%%%
\usepackage{tocloft}
\setlength{\cftbeforechapskip}{3pt}%espace entre chapitres
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % for chapters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{hyperref}
\usepackage[numberedbib,nosectionbib]{apacite}
\usepackage[makeindex]{imakeidx}
\makeindex[name=npr, title=Index des noms] 
\makeindex[name=mat, title=Index des matières]

\usepackage{fancyhdr}
\pagestyle{fancy}
% We don't want chapter and section numbers
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{} % sets both header and footer to nothing
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\textit{A name}} % even pages: chapter title
\fancyhead[CO]{\textit\leftmark} % odd pages: book title


%%%%%%%%%%%%Pas de N° de chapitres%%%%%%%%%%%%%%%%%%%%

\usepackage{titlesec}
\titleformat{\chapter}[display]%
    {\centering\Large\bfseries}% format of chapter
    {\large\normalfont\MakeUppercase{\chaptertitlename}\enskip\thechapter}% format of the label
    {.5\baselineskip}{} % space between the two
\titlespacing*{\chapter}{0pt}{25pt}{35pt} % spaces around \chapter{}, {left}{before}{after}
 
%\titleformat{\chapter}[display]
  %{\normalfont\bfseries}{}{0pt}{\Huge}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%épigraphe%%%%%%%%%%%%
\makeatletter
\renewcommand{\@chapapp}{}% Not necessary...
\newenvironment{chapquote}[2][2em]
  {\setlength{\@tempdima}{#1}%
   \def\chapquote@author{#2}%
   \parshape 1 \@tempdima \dimexpr\textwidth-2\@tempdima\relax%
   \itshape}
  {\par\normalfont\hfill---\ 
 \chapquote@author\hspace{\@tempdima}\par\bigskip\par\bigskip}
\makeatother

%%%%%%%%%%%%%Numérotation en chiffres arabes%%%%%%%%%%%%%%%%%%%
\makeatletter
\renewcommand\frontmatter{%
  \cleardoublepage
  \@mainmatterfalse
  %\pagenumbering{roman}% Don't reset
}
\renewcommand\mainmatter{%
  \cleardoublepage
  \@mainmattertrue
  %\pagenumbering{arabic}% Don't reset
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setcounter{secnumdepth}{3}

\begin{document}
\title{A title}
\author{A name}
\date{}
\maketitle

% Only part, chapter and section:
\setcounter{tocdepth}{1}
\renewcommand{\contentsname}{Sommaire}
\begingroup
\makeatletter
\let\@starttoc=\my@starttoc
\addtocontents{toc}{\string\ifsommaireintoc}%
\sommaireintocfalse
\matieresdetaileeintoctrue
\tableofcontents
\addtocontents{toc}{\string\fi}%
\endgroup
\frontmatter

\mainmatter
\part{A part}

\chapter{A chapter}
\lipsum
\section{A section}
\lipsum
\subsection{A subsection}

\subsubsection{A subsubsection}



\part{Another part}

\chapter{Another chapter}

\section{Another section}

\subsection{Another subsection}

\subsubsection{Another subsubsection}


\backmatter
\chapter{Conclusion}

\cleardoublepage
% part, chapter, section, subsection and subsubsection:
\setcounter{tocdepth}{3}
\renewcommand{\contentsname}{Table des matières détaillée}
\begingroup
\matieresdetaileeintocfalse
\sommaireintoctrue
\addtocontents{toc}{\string\ifmatieresdetaileeintoc}%
\tableofcontents
\addtocontents{toc}{\string\fi}%
\endgroup

\end{document}

在此处输入图片描述

答案2

如果您使用了类(和memoir的超集),那么您可以拥有任意数量的 TOC(或 LOF 或 LOT)。用户手册 ( ) 显示了简短的 TOC 和常规的 TOC。bookreport> texdoc memoir

相关内容