.png)
Bezogen auf diese Diskussion:Weitere titlesec-etoc-Anpassung, ich habe noch eine weitere Frage. Betrachten Sie den gut funktionierenden Code, den mir Gonzalo Medina zur Verfügung gestellt hat:
\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}
Wenn ich die Kapitelnummern nicht eingeben muss, weil die Kapitel alle mit dem jeweiligen Abschnitt 1 beginnen, kann ich sie mit einer sehr kleinen Änderung im Originalcode entfernen, d. h.
\etocsetstyle{chapter}
{}
{\addvspace{2ex}\leavevmode\leftskip 0cm\relax}
{\llap{\makebox[1.5cm][r]{\mdseries\phantom\etocpage}\hspace{.5cm}}%
\normalsize\makebox[1cm][r]{\etocnumber\phantom{.}}\hspace{10pt}%
\parbox[t]{\dimexpr\linewidth-1cm-27pt\relax}{\etocname\par}\hfill\par
}
{}
Auf diese Weise verliere ich jedoch die Seitenzahl der Bibliografie (und, glaube ich, des Index, falls vorhanden), da es sich um markierte Kapitel handelt. Gibt es also eine Möglichkeit, diese Seitenzahl beizubehalten? (Ich habe dieses Problem in einem anderen Fall mit gelöst titletoc/titlesec
, aber für den vorliegenden Code mit ist dies nicht der Fall etoc
.) Danke
NACHTRAG OKTOBER 2018
Derselbe mit Xelates kompilierte Code erzeugt im ersten Titelkapitel einen anomalen Vorsprung. Ich verstehe nicht, warum:
\documentclass[a4paper,twoside,11pt]{report}
\usepackage{fontspec}
\setmainfont{EB Garamond}
\usepackage{polyglossia}
\setmainlanguage[babelshorthands=true]{italian}
\PolyglossiaSetup{italian}{indentfirst=false}
\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}
{\ifShowPage % conditional deciding the display or not of the page number
\llap{\makebox[1.5cm][r]{\mdseries\etocpage}\hspace{.5cm}}%
\fi
\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
}
{}
\newif\ifShowPage
\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}
\end{document}
Antwort1
Ich bin mir über Ihre konkrete Situation nicht sicher und kann daher nur allgemeine Ratschläge geben.
Sie erwähnen, \chapter*
dass daher nichts in die Datei geschrieben wird .toc
. Normalerweise verwenden die Leute einen \addcontentsline{toc}{chapter}{<Chapter title>}
Befehl nach dem \chapter*
anderen, um einen Eintrag im Inhaltsverzeichnis zu erhalten.
Um den gewünschten Effekt zu erzielen, kann man mit einem Boolean-Wert vorgehen \ifShowPage
(ich verwende hier die Boolean-Werte von Standard-TeX, Sie können aber auch die von Paketen wieAbonnieren.) Weisen Sie dann den chapter
Stil an, den aktuellen Status dieses Boolean-Werts zu prüfen und entsprechend zu reagieren
Also, bevor \addcontentsline{toc}{chapter}{<bibliography name>}
Sie auch tun
\addtocontents{toc}{\protect\ShowPagetrue}
und etoc
werden entsprechend handeln.
Beispielcode (aktualisieren, um ihn zu verwenden \bibname
und das Hinzufügen eines zusätzlichen Kapitels zu vermeiden):
\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}
{\ifShowPage % conditional deciding the display or not of the page number
\llap{\makebox[1.5cm][r]{\mdseries\etocpage}\hspace{.5cm}}%
\fi
\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
}
{}
\newif\ifShowPage
\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}
\cleardoublepage
\setcounter{page}{139}% just for the example
\begin{thebibliography}{99}
\addtocontents{toc}{\protect\ShowPagetrue}
\addcontentsline{toc}{chapter}{\bibname}
\bibitem{me2015} user41603, \emph{The Key to the Universe}, Cosmos Press, to appear.
\end{thebibliography}
\end{document}
Antwort auf aktualisierte Frage (Oktober 2018)
Was die Folgefrage betrifft, ist die Erklärung einfach: Das Inhaltsverzeichnis wird über Absätze gesetzt, die der Einrückung folgen. Mit Ausnahme des allerersten Kapiteleintrags im Inhaltsverzeichnis, da das Dokument die indentfirst=false
Option verwendet, die bedeutet, der Standardgewohnheit von LaTeX für angelsächsische Dokumente zu folgen, nämlich den ersten Absatz nach einer Abschnittsüberschrift nicht einzurücken. Hier ist die Überschrift „Index“ des Inhaltsverzeichnisses dafür verantwortlich.
Daher wird das Einrückungsfeld in alle Zeilen außer der allerersten eingefügt.
Um dies zu beheben gibt es viele Möglichkeiten, zB
\makeatletter
\etocsetstyle{chapter}
{\@afterindenttrue}
{..}
{..}
{..}
\makeatother
Die etoc-Makros zum Formatieren der Kapitel- und Abschnittsüberschriften im Inhaltsverzeichnis im MWE hätten (sollten?) Vorkehrungen zum Festlegen des Werts „ \parindent
to“ treffen können 0pt
, um solche Probleme zu vermeiden. Man hätte auch einige verwenden können, um Leerzeichen der Breite \etociffirst{...}{...}
wiederherzustellen .\parindent