请考虑以下代码:
\documentclass[a4paper,twoside,11pt]{report}
\usepackage{fontspec}
\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}
\section{Section Four}
\chapter{Chapter Three}
\section{Section One}
\section{Section Two}
\section{Section Three}
\section{Section Four}
\end{document}
我不明白为什么第一章标题上有一个不想要的缩进,如图所示。如何才能将此标题与其他标题对齐?谢谢!
PS 使用 pdflatex 一切正常,但使用 xelatex 时我遇到了一点小麻烦......
答案1
以下结果对我来说是正确的。我将\parindent
本地设置为 0pt。请注意,这并不是真正解决您问题的方法,而是一种变通方法,因为我仍然不知道问题到底是什么。
\documentclass[a4paper,twoside,11pt]{report}
\usepackage{fontspec}
\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}
\begingroup
\parindent0pt
\tableofcontents
\endgroup
\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}
\chapter{Chapter Three}
\section{Section One}
\section{Section Two}
\section{Section Three}
\section{Section Four}
\end{document}