小节标题(不止于此)与 titletoc 对齐

小节标题(不止于此)与 titletoc 对齐

参考此帖子章节标题与 titletoc 对齐 我还有一个问题(我希望也是最后一个问题)。我无法将此代码应用于子部分以获得此结果: 在此处输入图片描述 我的(错误)代码只是一次粗略而错误的尝试,试图改变已经向我建议的精细代码:

\documentclass[a4paper]{report}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\setmainfont[Ligatures=TeX,Numbers=OldStyle]{EB Garamond}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% TABLE OF CONTENTS SETTINGS
\usepackage{titletoc}

% book -- titletoc patch for \part:
% https://tex.stackexchange.com/a/454553/134574
\usepackage{etoolbox}
\makeatletter
\patchcmd\@part
  {\thepart}
  {\protect\numberline{\thepart}}
  {}{\FAIL}
\makeatother

\makeatletter
\contentsmargin[-1.55em]{1.55em}

\titlecontents{chapter}
  [0em]
  {\vspace*{\baselineskip}}
  {\mdseries
   \llap{\hb@xt@\@pnumwidth{\hfil}\quad}\thecontentslabel
   \vspace*{0.1\baselineskip}%
   \upshape
  }
  {\mdseries
   \llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}
  }
  {}
  []

\titlecontents{section}
  [0em]
  {\vspace*{\baselineskip}}
  {\mdseries
   \llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}\thecontentslabel}
  {\mdseries
   \llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}
  }
  {}
  []

\titlecontents*{subsection}
  [0em]
  {}
  {\footnotesize}
  {}
  {\footnotesize,~\thecontentspage}
  [~--~]
  []

\makeatletter\@addtoreset{chapter}{part}\makeatother
% make chapter begin from 1 every part

\renewcommand{\thechapter}{\scshape\roman{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\renewcommand*\contentsname{\hfill\mdseries\huge Contents}
% put ToC title in the right side of the page

\tableofcontents

\chapter{A Very Short History of Rethorics}
\section{The Greek World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}

\chapter{A Very Short History of Rethorics}
\section{The Greek World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}

\end{document}

我无法生成正确对齐的章节和节号。

最后,我不明白为什么

\renewcommand*\contentsname{\hfill\mdseries\huge Contents}

仅当我将其放在 \begin{document} 之后,而不是放在序言中时才有效

谢谢!

11 月 4 日补充

我对无编号章节还有一点小问题。请考虑以下代码:

\begin{filecontents*}{\jobname.bib}
@book{ bottero:1992,
  author       = "Vickers, Brian.",
  title        = "In Defence of Rhetorics",
  publisher    = "Clarendon Press",
  location     = "Oxford",
  year         = "1989",
}
\end{filecontents*}

\documentclass[a4paper]{report}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\setmainfont[Ligatures=TeX,Numbers=OldStyle]{EB Garamond}

\usepackage{titletoc}

\titlecontents{chapter}
[3em]
{\vspace*{\baselineskip}\mdseries}
{\contentslabel[\hfill\thecontentslabel\phantom{.}]{3em}\enspace}
{}
{\hfill\llap{\makebox[\dimexpr\linewidth-1.3pc][l]{\thecontentspage}}}
[]

\titlecontents{section}
  [3em]
  {\vspace*{\baselineskip}\mdseries}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {}
{\hfill\llap{\makebox[\dimexpr\linewidth-1.3pc][l]{\thecontentspage}}}
  []

\titlecontents*{subsection}
  [3.525em]
  {\footnotesize}
  {}
  {}
  {,~\thecontentspage}
  [~--~]
  []

\makeatletter\@addtoreset{chapter}{part}\makeatother
% make chapter begin from 1 every part

\renewcommand{\thechapter}{\scshape\roman{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}

\usepackage[backend=biber,style=philosophy-verbose,scauthors=all,%
lowscauthors=true,giveninits,classical=true,volnumformat=strings,%
volumeformat=romansc,sorting=nyt,commacit=true,citepages=omit,%
editionformat=superscript,indexing]{biblatex}

\usepackage{filecontents}
\addbibresource{\jobname.bib}
\nocite{*}

\begin{document}
\renewcommand{\thesection}{\arabic{section}.}
\renewcommand*\contentsname{\hfill\mdseries\huge Contents\hspace*{1.2em}}

\tableofcontents

\chapter{A Very Short History of Rhetoric}
\section{The Greek World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}

\chapter{A Very Short History of Rhetoric}
\section{The Greek World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}

\addcontentsline{toc}{chapter}{\bibname}
\printbibliography

\end{document}

你会意识到章节标题参考书目突出尊重其他标题,如附图所示:

在此处输入图片描述

如何才能正确对齐?谢谢

答案1

这是你想要的吗?

\begin{filecontents*}{\jobname.bib}
@book{ bottero:1992,
  author = "Vickers, Brian.",
  title = "In Defence of Rhetorics",
  publisher = "Clarendon Press",
  location = "Oxford",
  year = "1989",
}
\end{filecontents*}

\documentclass[a4paper]{report}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\setmainfont[Ligatures=TeX,Numbers=OldStyle]{EB Garamond}

\usepackage{titletoc}

\titlecontents{chapter}
[3em]
{\vspace*{\baselineskip}\mdseries}
{\contentslabel[\hfill\thecontentslabel\phantom{.}]{3em}\enspace}
{\hspace*{0.5em}}
{\hfill\llap{\makebox[\dimexpr\linewidth-1.3pc][l]{\thecontentspage}}}
[]

\titlecontents{section}
  [3em]
  {\vspace*{\baselineskip}\mdseries}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {}
{\hfill\llap{\makebox[\dimexpr\linewidth-1.3pc][l]{\thecontentspage}}}
  []

\titlecontents*{subsection}
  [3.525em]
  {\footnotesize}
  {}
  {}
  {,~\thecontentspage}
  [~--~]
  []

\makeatletter\@addtoreset{chapter}{part}\makeatother
% make chapter begin from 1 every part

\renewcommand{\thechapter}{\scshape\roman{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}

\usepackage[backend=biber,style=philosophy-verbose,scauthors=all,%
lowscauthors=true,giveninits,classical=true,volnumformat=strings,%
volumeformat=romansc,sorting=nyt,commacit=true,citepages=omit,%
editionformat=superscript,indexing]{biblatex}

\usepackage{filecontents}
\addbibresource{\jobname.bib}
\nocite{*}

\begin{document}

\renewcommand{\thesection}{\arabic{section}.}
\renewcommand*\contentsname{\hfill\mdseries\huge Contents\hspace*{1.2em}}

\tableofcontents

\chapter{A Very Short History of Rhetoric}
\section{The Greek World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}

\chapter{A Very Short History of Rhetoric}
\section{The Greek World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}
\subsection{Aristoteles}
\subsection{The hellenistic Age}
\subsection{The Latin World}

\addcontentsline{toc}{chapter}{\bibname}
\printbibliography

\end{document}

在此处输入图片描述

相关内容