Titlesec & Titletoc: gefährliche Beziehungen

Titlesec & Titletoc: gefährliche Beziehungen

Bitte beachten Sie den folgenden Code:

\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}

Ich habe versucht, es meinen Bedürfnissen entsprechend zu ändern, und das Indexformat ist in Ordnung. Als zweiten Schritt möchte ich die Seitenzahlen im Inhaltsverzeichnis auf der linken Seite einfügen. Aber der Code, den ich gefunden habe (in meinem MWE „codice Pignalberi“), steht im Widerspruch zum vorherigen. Da ich anhand des Handbuchs titlesec/titletoc nicht verstehe, wo und wie ich die beiden Seiten dieses Codes koordinieren soll, hoffe ich auf Ihre Hilfe.

===================================================

AKTUALISIEREN

Dank Gonzalos Code funktioniert jetzt alles sehr gut. Ich habe zwei Aspekte verbessert (mehr Platz vor den Kapitelüberschriften hinzugefügt und Kapitelnummern entfernt, sodass nur die der Abschnitte übrig bleiben: jetzt erscheint es dem Leser nützlicher). Der Code ist der folgende:

<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>

Zuletzt möchte ich alle Zahlen (Seiten und Abschnitte) rechtsbündig und nicht linksbündig ausrichten, da die Überschriften der Abschnitte bei Verwendung einer proportionalen Schriftart nicht richtig ausgerichtet sind. Bedenken Sie, dass die titletocOptionen rightlabels,dotinlabelsbei mir nicht zu funktionieren scheinen. Vielen Dank! Sie können das Problem hier sehen: schlechte Ausrichtung

==========================================================

AKTUALISIERUNG 2

Ich habe versucht, Ihren Code mit etoc in meine .tex-Datei zu kopieren, aber das Ergebnis ist sehr merkwürdig: Etoc seltsame Wirkungen

==========================================================

AKTUALISIERUNG 3

Die oben genannten Probleme sind auf bididas Paket zurückzuführen, da ich in dieser Datei auch Hebräisch und Phönizisch verwende. In einer „normalen“ Datei etocfunktioniert der Code einwandfrei. Nur eine letzte Frage: Ich muss etocdie Dokumentation sehr gründlich lesen, die ziemlich umfangreich ist. Aber wie ist es möglich, auch die Seitenzahlen richtig auszurichten? Danke!!

Antwort1

Dies ist nur eine leichte Variante dieses Teils vonGonzalo Medinas Antwortwelches verwendetetoc. Wie es sich im Zusammenspiel mit verhält, weiß ich nicht bidi.

etocWenn man über einen Vorrat an Beispielen verfügt, wird alles einfacher .

Hier habe ich einige grafische Hilfen hinzugefügt, um das Layout zu verstehen, insbesondere für die vertikale Ausrichtung. Abschnittsseitenzahlen stehen am linken Rand. Kapitel- und Abschnittsnummern sind rechtsbündig ausgerichtet und es besteht eine 1em horizontale Trennung von der eigentlichen Überschrift. Die Kapitelnamen beginnen 1cmam linken Rand bei und die Abschnittsnamen bei 2cm. Lange Namen werden in einem Abstand von 1cmvom rechten Textrand umbrochen.

Deraktualisieren(am Ende hinzugefügt) ist eine Antwort auf Kommentare zur Behandlung nicht nummerierter Kapitel und zur Anzeige von Seitenzahlen auch für einige ausgewählte Kapitel. (beides wird hier in einem nicht nummerierten zusätzlichen Kapitel veranschaulicht).

etoc Inhaltsverzeichnis

\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}

etoc Inhaltsverzeichnis 2

\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}

Antwort2

Unten zeige ich zwei Optionen; die erste verwendet etocund die zweite titletoc. Die endgültige gewünschte Formatierung ist mir noch nicht ganz klar. In der Frage wird darum gebeten, Seitenzahlen für Kapitel links zu platzieren, und dann wird in den Kommentaren ein Bild bereitgestellt, in dem Kapiteleinträge keine Seitenzahlen links haben? Wie auch immer, der Beispielcode unten ermöglicht einfache Anpassungen, um jedes gewünschte Format zu erreichen.

Eine Möglichkeit mit Hilfe der leistungsstarkenetocPaket:

\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}

Bildbeschreibung hier eingeben

Hier ist eine weitere Möglichkeit mit 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}

Bildbeschreibung hier eingeben

Antwort3

Wenn ich Ihr Layout richtig verstanden habe, ist hier eine grundlegende Lösung, die auf Folgendem basiert 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}}
  {}{}{}

Spielen Sie einfach mit den Abmessungen.

BEARBEITEN.Hier ist ein vollständiges Beispiel mit . Denken Sie daran, dass Sie die Nummerierung mit und die enthaltenen Einträge im Inhaltsverzeichnis mit titletocsteuern können . Denken Sie auch daran, dass Sie mit das Format der Inhaltsverzeichniseinträge im ändern können.secnumdepthtocdepthtitletocMittedes Dokuments (für nachfolgende Abschnitte), falls Sie es aus irgendeinem Grund benötigen. Spielen Sie wie zuvor einfach mit den Abmessungen.

\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}

verwandte Informationen