进一步的 titlesec/etoc 定制

进一步的 titlesec/etoc 定制

我有以下代码:

\documentclass[a4paper,11pt]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{titlesec}
\usepackage{etoc}

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

\titleformat{\chapter}[display]
  {\normalfont\fontsize{11}{12}\selectfont}
  {\scshape\thechapter}
  {0pt}
  {}
\titleformat{\section}
  {\normalfont\fontsize{11}{12}\selectfont}
  {\thesection}
  {1em}
  {}
\titleformat{\subsection}
  {\normalfont\fontsize{11}{12}\selectfont\itshape}
  {}
  {1em}
  {}

\titlespacing{\chapter}
  {0pt}{0pt}{3cm}

\etocsetstyle{chapter}
{}
  {\leavevmode\leftskip 0cm\relax}
  {\llap{\parbox[t]{1.5cm}{\mdseries\hfill\etocpage}\hspace{.5cm}}%
    \normalsize\parbox[t]{1cm}{\quad\etocnumber\hfill}%
  \parbox[t]{\dimexpr\linewidth-1cm-15pt\relax}{\etocname\par}\hfill\par
  }
  {}
\etocsetstyle{section}
  {}
  {\leavevmode\leftskip 0cm\relax}
  {\llap{\parbox[t]{1.5cm}{\mdseries\hfill\etocpage}\hspace{.5cm}}%
    \normalsize\parbox[t]{1cm}{\quad\etocnumber.\hfill}%
  \parbox[t]{\dimexpr\linewidth-1cm-15pt\relax}{\etocname\par}\hfill\par
  }
  {}


\begin{document}

\tableofcontents

\chapter{Chapter One}
\section{Section One}
\section{Section Two}
\section{Section Three}
\section{Section Four}

\chapter{Chapter Two}
\section{Section One}
\section{Section Two}
\section{Section Three}
\section{Section Four}
\section{Section Five}

\chapter{Chapter Three}
\section{Section One}
\section{Section Two}
\section{Section Three}

\end{document}

然而,我想做两点改变:

1) 页码和章节/节号右对齐,而不是像现在的代码那样左对齐

vspace2)位于目录每章行之前的一点。

如何产生这些结果?总是在 etoc 代码中?谢谢

附录我想要的结果如下图所示:

在此处输入图片描述

答案1

修改

\etocsetstyle{chapter}
{}
  {\addvspace{2ex}\leavevmode\leftskip 0cm\relax}
  {\llap{\makebox[1.5cm][r]{\mdseries\etocpage}\hspace{.5cm}}%
    \normalsize\makebox[1cm][r]{\etocnumber\phantom{.}}\hspace{10pt}%
  \parbox[t]{\dimexpr\linewidth-1cm-27pt\relax}{\etocname\par}\hfill\par
  }
  {}
\etocsetstyle{section}
  {}
  {\leavevmode\leftskip 0cm\relax}
  {\llap{\makebox[1.5cm][r]{\mdseries\etocpage}\hspace{.5cm}}%
    \normalsize\makebox[1cm][r]{\etocnumber.}\hspace{10pt}%
  \parbox[t]{\dimexpr\linewidth-1cm-27pt\relax}{\etocname\par}\hfill\par
  }
  {}

基本上,我将\parboxes 更改为\makeboxes r(右对齐),并在章节2ex的第三个强制参数中添加了一个方便的垂直跳过( ,在我的示例中,但可以使用任何值来满足您的需要)\etocsetstyle

完整代码:

\documentclass[a4paper,11pt]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{titlesec}
\usepackage{etoc}

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

\titleformat{\chapter}[display]
  {\normalfont\fontsize{11}{12}\selectfont}
  {\scshape\thechapter}
  {0pt}
  {}
\titleformat{\section}
  {\normalfont\fontsize{11}{12}\selectfont}
  {\thesection}
  {1em}
  {}
\titleformat{\subsection}
  {\normalfont\fontsize{11}{12}\selectfont\itshape}
  {}
  {1em}
  {}

\titlespacing{\chapter}
  {0pt}{0pt}{3cm}

\etocsetstyle{chapter}
{}
  {\addvspace{2ex}\leavevmode\leftskip 0cm\relax}
  {\llap{\makebox[1.5cm][r]{\mdseries\etocpage}\hspace{.5cm}}%
    \normalsize\makebox[1cm][r]{\etocnumber\phantom{.}}\hspace{10pt}%
  \parbox[t]{\dimexpr\linewidth-1cm-27pt\relax}{\etocname\par}\hfill\par
  }
  {}
\etocsetstyle{section}
  {}
  {\leavevmode\leftskip 0cm\relax}
  {\llap{\makebox[1.5cm][r]{\mdseries\etocpage}\hspace{.5cm}}%
    \normalsize\makebox[1cm][r]{\etocnumber.}\hspace{10pt}%
  \parbox[t]{\dimexpr\linewidth-1cm-27pt\relax}{\etocname\par}\hfill\par
  }
  {}


\begin{document}

\tableofcontents

\chapter{Chapter One}
\section{Section One}
\section{Section Two}
\section{Section Three}
\section{Section Four}

\chapter{Chapter Two}
\section{Section One}
\section{Section Two}
\section{Section Three}
\section{Section Four}
\section{Section Five}

\setcounter{page}{99}% just for the example

\chapter{Chapter Three}
\section{Section One}
\section{Section Two}
\section{Section Three}

\end{document}

结果:

在此处输入图片描述

相关内容