
我有以下程式碼:
\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)頁碼和章/節號右對齊,而不是從目前代碼左對齊
vspace
2)目錄中每章行之前的一點。
怎麼可能產生這些結果?總是在 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
}
{}
基本上,我將\parbox
es 更改為\makebox
es with 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}
結果: