请考虑以下代码:
\documentclass[a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}
\usepackage{titlesec}
\renewcommand{\thechapter}{\scshape\roman{chapter}}
\titleformat{\chapter}[display]
{\normalfont\fontsize{11pt}{12pt}\selectfont}{\thechapter}{0pt}{}
%%{\normalfont\fontsize{11pt}{12pt}\selectfont}{\chaptertitlename\space \thechapter}{11pt}{}
\renewcommand\thesection{\arabic{section}}
\titleformat{\section}
{\normalfont\fontsize{11pt}{12pt}\selectfont}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\fontsize{11pt}{12pt}\selectfont\itshape}{}{1em}{}
\titlespacing{\chapter}{0pt}{0pt}{3cm}
\usepackage{titletoc}
\titlecontents{chapter}
[1.5em] % ie, 1.5em (chapter) + 2.3em
{}
{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{}
%{\titlerule*[1pc]{.}\contentspage}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% codice Pignalberi
\contentsmargin{0pt}
\titlecontents{chapter}[4pc]
{\contentsmargin{0pt}\makebox[0pt][r]{\thecontentspage\quad\makebox[30pt][l]%
{\textsc{\romannumeral\thecontentslabel\ quad}}}}
{}
{}
{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\tableofcontents
\chapter{Chapter 1 title}
Some text some text some text some text some text
\section{Section a title}
Some text some text some text some text some text
\section{Section b title}
Some text some text some text some text some text
\chapter{Chapter 2 title}
Some text some text some text some text some text
\section{Section c title}
Some text some text some text some text some text
\section{Section d title}
Some text some text some text some text some text
\chapter{Chapter 3 title}
Some text some text some text some text some text
\section{Section e title}
Some text some text some text some text some text
\section{Section f title}
Some text some text some text some text some text
\end{document}
我尝试根据自己的需要进行更改,索引格式没问题。第二步,我想在左侧的目录中放置页码。但我找到的代码(在我的 MWE“codice Pignalberi”中)与前一个代码相冲突。由于我无法理解,按照 titlesec/titletoc 手册,在哪里以及如何协调此代码的两侧,我希望对您有所帮助。
===================================================
更新
现在一切都运行良好,这要感谢 Gonzalo 的代码。我改进了两个方面(在章节标题前添加更多空格并删除章节编号,只留下章节编号:现在它看起来对读者更有用)。代码如下:
<pre>\usepackage{titlesec}
\usepackage[rightlabels,dotinlabels]{titletoc}
\renewcommand{\thechapter}{\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}
\titlecontents{chapter}[-3pc]
{\addvspace{0.8pc}}
{\makebox[3pc][r]{\hfill}%
\textsc{\thecontentslabel}\quad%
}
{}
{}
{}
\titlecontents{section}[-3pc]
{\makebox[4pc][r]{\thecontentspage\hfill}%
\textsc{\thecontentslabel}\quad%
}
{}
{}
{}</pre>
最后,我想让所有数字(页面和部分)都右对齐,而不是左对齐,因为实际上使用比例字体时,部分的标题对齐得不是很好。考虑一下,这些titletoc
选项rightlabels,dotinlabels
在我看来似乎不起作用。非常感谢!您可以在此处看到问题:
==========================================================
更新2
我尝试使用 etoc 将您的代码复制到我的 .tex 文件中,但结果非常奇怪:
==========================================================
更新 3
上述问题是由于bidi
软件包引起的,因为在那个文件中我也使用了希伯来语和腓尼基语。在“普通”文件中,etoc
代码运行良好。最后一个问题:我必须仔细阅读etoc
文档,文档相当大。但如何才能对齐正确的页码呢?谢谢!!
答案1
这只是Gonzalo Medina 的回答它使用etoc
。我不知道它与 的交互行为如何bidi
。
etoc
一旦有了例子,事情就会变得容易起来。
这里我添加了一些图形帮助来理解布局,特别是垂直对齐。章节页码位于左边距。章节和章节号右对齐,与1em
实际标题有水平分隔。章节名称1cm
从左边距开始,章节名称从开始。长名称在距离文本右边2cm
距 处换行。1cm
这更新(添加在最后)是为了回应关于处理未编号章节和显示某些选定章节的页码的评论。(两者都在这里的一个未编号的额外章节中说明)。
\documentclass[a4paper]{report}
\usepackage[margin=2cm,paperwidth=14cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}
\usepackage{titlesec}
\usepackage{etoc}
\usepackage{color}
\renewcommand{\thechapter}{\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}
% FOR VISUALIZING LAYOUT:
% {\fboxsep-\fboxrule\noindent\normalsize
% \fbox{\makebox[1cm][r]{\strut
% \smash{\color{blue}\vrule depth12cm}\hspace{1em}%
% \smash{\color{green}\vrule depth12cm}}}%
% \fbox{\makebox[1cm][r]{\color{blue}\strut
% \smash{\color{blue}\vrule depth12cm}\hspace{1em}%
% \smash{\color{green}\vrule depth12cm}}}%
% \fbox{\makebox[1cm]{\strut}}(debugging layout)\hfill
% \fbox{\makebox[1cm][l]{\strut\smash{\color{red}\vrule
% depth12cm}}}%
% \hrule}
{}% <- uncomment the above and suppress this line if debugging layout
{\pagebreak[3]\vskip25pt\leftskip 1cm\relax
\rightskip 1cm\relax
\parindent 0pt\relax
}
{\Large\leavevmode
\llap{\makebox[1cm][r]{\normalsize\etocnumber.\hspace{1em}}}%
\etocname\par\nopagebreak\medskip }
{\bigskip}
\etocsetstyle{section}
{}
{\leftskip 2cm\relax}
{\normalsize\leavevmode
\llap{\makebox[1cm][r]{\mdseries\etocpage}%
\hspace{1cm}%
\makebox[1cm][r]{\etocnumber.\hspace{1em}}}%
\etocname\par\pagebreak[1]\smallskip }
{}
\begin{document}
\tableofcontents
\chapter{Vita e Opere}
\setcounter{page}{98}% just for the example
Some text some text some text some text some text
\section{Infanzia, studi a Lipsia e soggiorno a Parigi}
Some text some text some text some text some text
\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text
\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text
\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text
\section{La concezione delle idee}
Some text some text some text some text some text
\chapter{Seggni (``caratteri'') e idee}
Some text some text some text some text some text
\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text
\section{La concezione delle idee}
Some text some text some text some text some text
\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text
\clearpage
\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text
\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text
\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text
\end{document}
\documentclass[a4paper]{report}
\usepackage[margin=2cm,paperwidth=14cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}
\usepackage{titlesec}
\usepackage{etoc}
\usepackage{color}
\renewcommand{\thechapter}{\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}
%% ETOC SPECIFICATIONS
% conditional to display chapter page number
% a priori set to false
\newif\ifDisplayInTocChapterPageNumber
\etocsetstyle{chapter}
{}
{\pagebreak[3]\vskip25pt\leftskip 1cm\relax
\rightskip 1cm\relax
\parindent 0pt\relax
}
{\Large\leavevmode
\llap{\ifDisplayInTocChapterPageNumber
\makebox[1cm][r]{\mdseries\normalsize\etocpage}%
\fi
\makebox[1cm][r]{\normalsize\etocifnumbered{\etocnumber.}{}%
\hspace{1em}}}%
\etocname\par\nopagebreak\medskip }
{\bigskip}
\etocsetstyle{section}
{}
{\leftskip 2cm\relax}
{\normalsize\leavevmode
\llap{\makebox[1cm][r]{\mdseries\etocpage}%
\hspace{1cm}%
\makebox[1cm][r]{\etocnumber.\hspace{1em}}}%
\etocname\par\pagebreak[1]%\smallskip
}
{}
\begin{document}
\tableofcontents
\chapter{Vita e Opere}
\setcounter{page}{98}% just for the example
Some text some text some text some text some text
\section{Infanzia, studi a Lipsia e soggiorno a Parigi}
Some text some text some text some text some text
\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text
\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text
\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text
\section{La concezione delle idee}
Some text some text some text some text some text
\chapter{Seggni (``caratteri'') e idee}
Some text some text some text some text some text
\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text
\section{La concezione delle idee}
Some text some text some text some text some text
\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text
\clearpage
\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text
\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text
\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text
\addtocontents{toc}{\protect\DisplayInTocChapterPageNumbertrue}
\chapter*{Un capitolo non numerato e col numero di pagina nel margine dell'indice}
\addcontentsline{toc}{chapter}{Un capitolo non numerato e col numero di
pagina nel margine dell'indice}
\setcounter{section}{0}
\section{Ultimi anni}
Some text some text some text some text some text
\end{document}
答案2
下面我展示了两个选项;第一个选项使用etoc
,第二个选项使用titletoc
。最终所需的格式对我来说仍然不完全清楚。问题要求将章节的页码放在左侧,然后在评论中提供一张图片,其中章节条目的左侧没有页码?无论如何,下面的示例代码允许轻松自定义以实现所需的任何格式。
一种可能是利用强大的etoc
包裹:
\documentclass[a4paper]{report}
\usepackage[margin=2cm,paperwidth=14cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}
\usepackage{titlesec}
\usepackage{etoc}
\renewcommand{\thechapter}{\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}
{}
{\vskip25pt\leavevmode\leftskip 0cm\relax}
{\parbox[t]{.5cm}{\etocnumber.\hfill}%
\parbox[t]{\dimexpr\linewidth-1cm-15pt\relax}{\Large\etocname}\hfill\par\medskip
}
{}
\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{Vita e Opere}
\setcounter{page}{98}% just for the example
Some text some text some text some text some text
\section{Infanzia, studi a Lipsia e soggiorno a Parigi}
Some text some text some text some text some text
\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text
\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text
\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text
\section{La concezione delle idee}
Some text some text some text some text some text
\chapter{Seggni (``caratteri'') e idee}
Some text some text some text some text some text
\section{Della \textit{Dissertazione preliminare} al \textit{Dialogo}}
Some text some text some text some text some text
\section{La concezione delle idee}
Some text some text some text some text some text
\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text
\clearpage
\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text
\section{A Honovver, al servizio del ducchi Johann Friedrich ed Ernst August}
Some text some text some text some text some text
\section{Viaggio in Italia, morte dell'elettore Erns August ed successione del nuovo elettore, Georg Ludwig}
Some text some text some text some text some text
\end{document}
这是使用另一种可能性titletoc
:
\documentclass[a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{cfr-lm}
\usepackage{titlesec}
\usepackage{titletoc}
\renewcommand{\thechapter}{\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}
\titlecontents{chapter}[-4pc]
{\makebox[2pc][l]{\hfill\thecontentspage}\hspace{2pc}%
\textsc{\thecontentslabel}\quad%
}
{}
{}
{}
\titlecontents{section}[-4pc]
{\makebox[2pc][l]{\hfill\thecontentspage}\hspace{3pc}%
\textsc{\thecontentslabel}\quad%
}
{}
{}
{}
\begin{document}
\tableofcontents
\chapter{Chapter 1 title}
\setcounter{page}{98}% just for the example
Some text some text some text some text some text
\section{Section a title}
Some text some text some text some text some text
\section{Section b title}
Some text some text some text some text some text
\chapter{Chapter 2 title}
Some text some text some text some text some text
\section{Section c title}
Some text some text some text some text some text
\section{Section d title}
Some text some text some text some text some text
\chapter{Chapter 3 title}
Some text some text some text some text some text
\section{Section e title}
Some text some text some text some text some text
\section{Section f title}
Some text some text some text some text some text
\end{document}
答案3
如果我正确理解了您的布局,那么这里有一个基于的基本解决方案titletoc
:
\newcommand\boxedpage{\makebox[3pc][r]{\thecontentspage}}
\newcommand\boxedtocnum{\makebox[3pc][r]{\thecontentslabel.\quad}}
\titlecontents{chapter}[0pc]
{\addvspace{0.8pc}}
{\contentslabel[\boxedpage\boxedtocnum]{6pc}}
{}{}{}
\titlecontents{section}[3pc]
{}
{\contentslabel[\boxedpage\hspace*{3pc}\boxedtocnum]{9pc}}
{}{}{}
只需玩 dimens 即可。
编辑。以下是一个完整的示例titletoc
。请记住,您可以使用 来控制编号secnumdepth
,并使用 来控制目录中包含的条目tocdepth
。请记住,titletoc
您还可以使用 来更改目录中条目的格式中间文档(用于后续章节),如果出于某种原因您需要它。和以前一样,只需使用 dimens 即可。
\documentclass{book}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{titletoc}
\newcommand\boxedpage{\makebox[3pc][r]{\thecontentspage}}
\newcommand\boxedtocnum{\makebox[3pc][r]{\thecontentslabel.\quad}}
\titlecontents{chapter}[3pc]
{\addvspace{0.8pc}}
{\contentslabel[\boxedpage\boxedtocnum]{6pc}}
{\contentslabel[\boxedpage\hspace*{3pc}]{6pc}}
{}{}
\titlecontents{section}[6pc]
{}
{\contentslabel[\boxedpage\hspace*{3pc}\boxedtocnum]{9pc}}
{\contentslabel[\boxedpage\hspace*{6pc}]{9pc}}
{}{}
\newcommand*\asection{
\section{A Honovver, text text al servizio del ducchi Johann
Friedrich ed Ernst August.}
Some text some text some text some text some text\par}
\begin{document}
\tableofcontents
\chapter{Vita e Opere}
\setcounter{page}{98}% just for the example
\asection\asection
\chapter{Seggni (``caratteri'') e idee}
\asection\asection\asection\asection\asection
\asection\asection\asection\asection\asection
% From now on, unnumbered headers, but still in the toc
% down to section
\setcounter{secnumdepth}{-1}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}\ignorespaces}
\chapter{Seggni (``caratteri'') e idee}
\asection\asection
\end{document}