.png)
Referindo-se a esta discussão:Personalização adicional do titlesec-etoc, tenho mais uma pergunta. Considere o excelente código de funcionamento fornecido por 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}
Se eu não precisar colocar os números dos capítulos, pois os capítulos começam todos com a respectiva seção 1, posso removê-los com uma pequena alteração no código original, ou seja
\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
}
{}
Porém, desta forma perco o número da página da Bibliografia (e, creio, do Índice, se houver), pois são capítulos marcados com estrela. Então, existe uma maneira de preservar esse número de página? (Resolvo esse problema em outro caso, usando titletoc/titlesec
, mas não é o caso do código atual com etoc
). Obrigado
ADENDO OUTUBRO DE 2018
o mesmo código compilado com xelates produz uma saliência anômala no primeiro capítulo do título, não percebo o porquê:
\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}
Responder1
Não tenho certeza sobre sua situação específica, portanto, só posso dar conselhos gerais.
Você mencionou \chapter*
, portanto, nada foi gravado no .toc
arquivo. As pessoas geralmente usam um \addcontentsline{toc}{chapter}{<Chapter title>}
comando após um \chapter*
comando para obter uma entrada no sumário.
Para obter o efeito desejado, uma maneira de proceder é com um booleano \ifShowPage
(eu uso aqui os booleanos padrão do TeX, você pode preferir aqueles fornecidos por pacotes comoetoolbox.) Em seguida, instrua o chapter
estilo para examinar o status atual deste booleano e agir adequadamente
Assim, antes de \addcontentsline{toc}{chapter}{<bibliography name>}
você também fazer
\addtocontents{toc}{\protect\ShowPagetrue}
e etoc
agirá adequadamente.
Código de exemplo (atualize para usar \bibname
e também evite adicionar um capítulo extra):
\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}
resposta à pergunta atualizada (outubro de 2018)
Quanto à pergunta de acompanhamento, a explicação é simples: o sumário é composto por parágrafos que obedecem ao recuo. Exceto para a entrada do primeiro capítulo no TOC, porque o documento utiliza a indentfirst=false
opção que significa obedecer ao hábito padrão do LaTeX para documentos anglo-saxões, que é não recuar o primeiro parágrafo após um título de seção. Aqui o título “Índice” do TOC é responsável por atuar como tal.
Assim, a caixa de recuo é inserida em todas as linhas, exceto na primeira.
Para corrigir isso, há muitas maneiras, por exemplo
\makeatletter
\etocsetstyle{chapter}
{\@afterindenttrue}
{..}
{..}
{..}
\makeatother
As macros etoc para estilizar os títulos dos capítulos e seções no sumário do MWE poderiam (deveriam?) ter previsto a definição do \parindent
to 0pt
para evitar tais problemas. Também se poderia ter usado some \etociffirst{...}{...}
para reinserir espaços em branco de \parindent
largura.