如何使用 titletoc 包制作如下所示的部分目录?

如何使用 titletoc 包制作如下所示的部分目录?
\documentclass[openany]{book}
\raggedbottom       %reduce underfull \vbox

\usepackage{titlesec, titletoc}
\titlelabel{\thetitle\quad}
%change the part format in book 
\titleformat{\part}[frame]{\normalfont\huge\bfseries}{\partname\ \thepart }{20pt}{\Huge\centering}
%change the part format in table of contents
\titlecontents{part}%
[0pt]{\sffamily\bfseries\huge\protect\addvspace{25pt}\titlerule\addvspace{1.5ex}}%remove rule if you like
{}{\partname~}
{\hfill\contentspage}%replaced with {} if don't want page number for parts
[\addvspace{0.7ex}\titlerule\addvspace{10pt}]%remove rule if you like

%change the chapter format in table of contents
\titlecontents{chapter}%
[0pt]{\sffamily\bfseries\large\protect\addvspace{10pt}}%
{\chaptertitlename\ \thecontentslabel~}{}
{\hfill\contentspage}%
[\addvspace{1.5ex}]%

%change the appendix name from chapter to appendix
\makeatletter
\g@addto@macro{\appendix}{%
  \renewcommand\chaptername{Appendix}%
  \addtocontents{toc}{\protect\renewcommand*{\protect\chaptername}{\protect\appendixname}}%
}
\makeatother
%force paragraph newline
\titleformat{\paragraph}[hang]{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}


%insert figures
\usepackage{graphicx}

%improve the interface for defining floating objects such as figures and tables
\usepackage{float}

%customize page layout
\usepackage[a4paper, left=3cm, right=3cm]{geometry}

%color
\usepackage[dvipsnames]{xcolor}

%page headers and footers   left,right,odd,even
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{\normalfont\small\rmfamily\nouppercase{\leftmark}}
\fancyhead[LO]{\normalfont\small\rmfamily\nouppercase{\rightmark}}
\fancyhead[LE,RO]{\thepage}

%booktitle
\title{\Huge C++ \\\qquad\textcolor{RedOrange}{Primer}}
\author{\textbf{Stanley B.Lippman} \and \textbf{Jos\'ee Lajoie} \and \textbf{Barbara E.Moo}}
\date{}


%revise\@endpart macro
\makeatletter
\def\@endpart{\bigbreak} 
\makeatother

% add mini-ta­bles-of-con­tents (mini­tocs) at the be­gin­ning of ev­ery chap­ter, part or sec­tion.
\usepackage{minitoc}
\setcounter{minitocdepth}{1} 
\renewcommand\tightmtcfalse

\begin{document}
%initialize minitoc
\dominitoc 

\frontmatter
\maketitle
\tableofcontents



\mainmatter
\chapter{Getting Started}
\minitoc 
%\startcontents[mainsections]
%\printcontents[mainsections]{l}{1}{\section*{Main Sections}\setcounter{todepth}{1}}

This chapter introduces most of the basic elements of C++: types, variables,
expressions, statements, and functions. Along the way, we’ll briefly explain how to
compile and execute a program.

After having read this chapter and worked through the exercises, you should be able
to write, compile, and execute simple programs. Later chapters will assume that you
can use the features introduced in this chapter, and will explain these features in more
detail.
\newpage
    \section{Writing a Simple C++ Program}

    \section{A First Look at Input/Output}\label{a first look at input/output}

    \section{A Word about Comments}
    %\stopcontents[mainsections]

\backmatter
\chapter{Index}

\end{document}

    \section{A First Look at Input/Output}\label{a first look at input/output}

    \section{A Word about Comments}
    %\stopcontents[mainsections]

\backmatter
\chapter{Index}

\end{document}

在此处输入图片描述

由于“titletoc”和“minitoc”不兼容,我想删除“minitoc”包,并使用“titletoc”制作部分toc。

答案1

也许你想要这样的东西。

罗伯特·蒂特洛

\documentclass[openany]{book}
\raggedbottom       %reduce underfull \vbox

\usepackage{titlesec, titletoc}
\usepackage{indentfirst}% indents first paragraph after a section/chapter heading
\titlelabel{\thetitle\quad}
%change the part format in book 
\titleformat{\part}[frame]{\normalfont\huge\bfseries}{\partname\ \thepart }{20pt}{\Huge\centering}
%change the part format in table of contents
\titlecontents{part}%
[0pt]{\sffamily\bfseries\huge\protect\addvspace{25pt}\titlerule\addvspace{1.5ex}}%remove rule if you like
{}{\partname~}
{\hfill\contentspage}%replaced with {} if don't want page number for parts
[\addvspace{0.7ex}\titlerule\addvspace{10pt}]%remove rule if you like

%change the chapter format in table of contents
\titlecontents{chapter}%
[0pt]{\sffamily\bfseries\large\protect\addvspace{10pt}}%
{\chaptertitlename\ \thecontentslabel~}{}
{\hfill\contentspage}%
[\addvspace{1.5ex}]%

%change the appendix name from chapter to appendix
\makeatletter
\g@addto@macro{\appendix}{%
  \renewcommand\chaptername{Appendix}%
  \addtocontents{toc}{\protect\renewcommand*{\protect\chaptername}{\protect\appendixname}}%
}
\makeatother
%force paragraph newline
\titleformat{\paragraph}[hang]{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}

\titleformat{\chapter}[display]{\normalfont\bfseries\huge}{\chaptertitlename\ \thechapter}{20pt}{\Huge}[%
\vspace*{4pc}
\startcontents
{\normalsize\bfseries\contentsname\endgraf\vspace{5pt}}
\contentsmargin{1em}
\titlerule\vspace{5pt}
\printcontents{l}{1}{}
\vspace{5pt}\titlerule
]
\titlecontents*{lsection}[10pt]{\small}{}{}{\titlerule*[1pc]{.} \contentspage}[\endgraf]

%insert figures
\usepackage{graphicx}

%improve the interface for defining floating objects such as figures and tables
\usepackage{float}

%customize page layout
\usepackage[a4paper, left=3cm, right=3cm]{geometry}

%color
\usepackage[dvipsnames]{xcolor}

\usepackage{blindtext}
%page headers and footers   left,right,odd,even
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{\normalfont\small\rmfamily\nouppercase{\leftmark}}
\fancyhead[LO]{\normalfont\small\rmfamily\nouppercase{\rightmark}}
\fancyhead[LE,RO]{\thepage}

%booktitle
\title{\Huge C++ \\\qquad\textcolor{RedOrange}{Primer}}
\author{\textbf{Stanley B.Lippman} \and \textbf{Jos\'ee Lajoie} \and \textbf{Barbara E.Moo}}
\date{}


%revise\@endpart macro
\makeatletter
\def\@endpart{\bigbreak} 
\makeatother


\begin{document}

\startcontents[chapters]
\tableofcontents


\chapter{Getting Started}

This chapter introduces most of the basic elements of C++: types, variables,
expressions, statements, and functions. Along the way, we’ll briefly explain how to
compile and execute a program.

After having read this chapter and worked through the exercises, you should be able
to write, compile, and execute simple programs. Later chapters will assume that you
can use the features introduced in this chapter, and will explain these features in more
detail.
\blindtext
\newpage
    \section{Writing a Simple C++ Program}

    \section{A First Look at Input/Output}\label{a first look at input/output}

    \section{A Word about Comments}


\end{document}

相关内容