.png)
이 토론을 참조하면:추가 titlesec-etoc 사용자 정의, 추가 질문이 있습니다. 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}
챕터 번호를 넣을 필요가 없다면 챕터가 모두 해당 섹션 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년 10월 부록
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
. 사람들은 일반적으로 TOC에 항목을 가져오기 위해 명령 \addcontentsline{toc}{chapter}{<Chapter title>}
다음에 명령 을 사용합니다 .\chapter*
원하는 효과를 얻기 위해 진행하는 한 가지 방법은 부울을 사용하는 것입니다. \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}
업데이트된 질문에 대한 답변(2018년 10월)
후속 질문에 대한 설명은 간단합니다. TOC는 들여쓰기를 준수하는 단락을 통해 조판됩니다. TOC의 첫 번째 장 항목을 제외하고 문서는 indentfirst=false
섹션 제목 뒤 첫 번째 단락을 들여쓰지 않는 앵글로색슨 문서에 대한 표준 LaTeX 습관을 준수한다는 의미의 옵션을 사용하기 때문입니다. 여기서는 TOC의 "색인"이라는 제목이 그 역할을 담당합니다.
따라서 들여쓰기 상자는 첫 번째 줄을 제외한 모든 줄에 삽입됩니다.
이 문제를 해결하려면 다음과 같은 여러 가지 방법이 있습니다.
\makeatletter
\etocsetstyle{chapter}
{\@afterindenttrue}
{..}
{..}
{..}
\makeatother
MWE의 TOC에 있는 장 및 섹션 제목의 스타일을 지정하기 위한 etoc 매크로는 이러한 문제를 피하기 위해 \parindent
to를 설정하는 규정을 만들 수 있었습니다(해야 할까요?). 너비 의 공백을 다시 삽입하기 위해 0pt
some을 사용할 수도 있습니다 .\etociffirst{...}{...}
\parindent