Personalización de titlesec-etoc (pregunta adicional)

Personalización de titlesec-etoc (pregunta adicional)

Refiriéndose a esta discusión:Mayor personalización de titlesec-etoc, tengo una pregunta adicional. Considere el excelente código de trabajo que me proporcionó Gonzalo Medina:

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

Si no necesito poner los números de los capítulos, ya que todos los capítulos comienzan con la sección 1 respectiva, puedo eliminarlos con un cambio muy pequeño en el código original, es decir

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

Sin embargo, así pierdo el número de página de la Bibliografía (y, creo, del Índice, si lo hay), pues son capítulos destacados. Entonces, ¿hay alguna manera de conservar esos números de página? (Resuelvo este problema en otro caso, usando titletoc/titlesec, pero no es el caso del código actual con etoc). Gracias

ADENDA OCTUBRE 2018

el mismo código compilado con xelates produce una protuberancia anómala en el primer capítulo del título, no entiendo por qué:

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

No puedo eliminarlo... gracias. ingrese la descripción de la imagen aquí

Respuesta1

No estoy seguro de su situación específica, por lo que sólo puedo dar consejos generales.

Usted menciona \chapter*que, por lo tanto, no se escribe nada en el .tocarchivo. La gente suele utilizar un \addcontentsline{toc}{chapter}{<Chapter title>}comando después de \chapter*otro para obtener una entrada en el TOC.

Para obtener el efecto deseado, una forma de proceder es con un booleano \ifShowPage(yo uso aquí los booleanos estándar de TeX; es posible que prefiera los proporcionados por paquetes comocaja de herramientas.) Luego indique al chapterestilo que examine el estado actual de este booleano y actúe apropiadamente.

Así, antes de que \addcontentsline{toc}{chapter}{<bibliography name>}tú también lo hagas

\addtocontents{toc}{\protect\ShowPagetrue}

y etocactuará apropiadamente.

Código de ejemplo (actualice para usarlo \bibnamey también evite agregar un capítulo adicional):

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

tabla de contenidos usando etoc

respuesta a la pregunta actualizada (octubre de 2018)

En cuanto a la pregunta de seguimiento, la explicación es simple: el TOC se compone mediante párrafos que obedecen a la sangría. Excepto por la primera entrada del capítulo en el TOC, porque el documento utiliza la indentfirst=falseopción que significa obedecer el hábito estándar de LaTeX para los documentos anglosajones que es no sangrar el primer párrafo después de un encabezado de sección. Aquí el título “Índice” del TOC es el encargado de actuar como tal.

Por lo tanto, el cuadro de sangría se inserta en todas las líneas excepto en la primera.

Para solucionar este problema hay muchas maneras, por ejemplo

\makeatletter
\etocsetstyle{chapter}
    {\@afterindenttrue}
    {..}
    {..}
    {..}
\makeatother

Las macros etoc para diseñar los títulos de capítulos y secciones en el TOC en el MWE podrían (¿deberían?) haber previsto establecer el \parindentpara 0ptevitar tales problemas. También se podrían haber usado algunos \etociffirst{...}{...}para reinsertar espacios en blanco de \parindentancho.

información relacionada