Настройка titlesec-etoc (еще один вопрос)

Настройка titlesec-etoc (еще один вопрос)

Ссылаясь на это обсуждение:Дальнейшая настройка titlesec-etoc, у меня есть еще один вопрос. Рассмотрим прекрасный рабочий код, предоставленный мне Гонсало Мединой:

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

Если мне не нужно указывать номера глав, поскольку все главы начинаются с соответствующего раздела 1, я могу удалить их, внеся совсем небольшое изменение в исходный код, т. е.

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

Однако, таким образом я теряю номер страницы Библиографии (и, я думаю, Индекса, если он есть), поскольку они являются помеченными главами. Так есть ли способ сохранить эти номера страниц? (Я решаю эту проблему в другом случае, используя titletoc/titlesec, но это не относится к текущему коду с etoc). Спасибо

ДОПОЛНЕНИЕ ОКТЯБРЬ 2018

тот же код, скомпилированный с помощью xelates, создает аномальный выступ в первой главе заголовка, я не понимаю, почему:

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

Я не могу его удалить... спасибо введите описание изображения здесь

решение1

Я не совсем уверен в вашей конкретной ситуации, поэтому могу дать только общие советы.

Вы упоминаете \chapter*, поэтому ничего не записывается в .tocфайл. Люди обычно используют \addcontentsline{toc}{chapter}{<Chapter title>}команду после \chapter*команды, чтобы получить запись в TOC.

Чтобы получить желаемый эффект, один из способов — использовать логические значения \ifShowPage(здесь я использую стандартные логические значения TeX, вы можете предпочесть те, которые предоставляются такими пакетами, какetoolbox.) Затем дайте указание chapterстилю проверить текущий статус этого логического значения и действовать соответствующим образом.

Таким образом, прежде чем \addcontentsline{toc}{chapter}{<bibliography name>}вы также сделаете

\addtocontents{toc}{\protect\ShowPagetrue}

и etocбудет действовать соответствующим образом.

Пример кода (обновите, чтобы использовать \bibnameи избежать добавления дополнительной главы):

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

оглавление с использованием etoc

ответ на обновленный вопрос (октябрь 2018 г.)

Что касается следующего вопроса, то объяснение простое: TOC набирается с помощью абзацев, которые подчиняются отступу. За исключением самой первой записи главы в TOC, поскольку документ использует опцию, indentfirst=falseкоторая означает подчинение стандартной привычке LaTeX для англосаксонских документов, которая заключается в том, чтобы не делать отступ для первого абзаца после заголовка раздела. Здесь заголовок "Indice" TOC отвечает за выполнение этой функции.

Таким образом, отступ вставляется во все строки, кроме самой первой.

Чтобы исправить это, есть много способов, например:

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

Макросы etoc для стилизации названий глав и разделов в TOC в MWE могли (должны были?) предусмотреть установку to, \parindentчтобы 0ptизбежать таких проблем. Можно было бы также использовать some \etociffirst{...}{...}для повторной вставки пробелов \parindentширины.

Связанный контент