使用以下代码
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{titletoc}
\titlecontents{chapter}
[0em]
{\vspace*{\baselineskip}}
{\mdseries \contentslabel[\thecontentspage] {0mm} \hspace*{1.4em} \chaptername
\,\,\thecontentslabel \\
\hspace*{2em} \itshape \vspace*{0.3\baselineskip}}
{\mdseries \thecontentspage \hspace*{1.2em} \itshape}
{}
[]
\titlecontents*{section}
[0em]
{}
{\footnotesize \thecontentslabel~}
{}
{\footnotesize,~\thecontentspage}
[~--\ ]
[]
\begin{document}
\tableofcontents
\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}
\setcounter{page}{277}
\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}
\end{document}
我怎样才能将章节标题的左边距与章节标题对齐?我可以用眼睛对齐,但显然这不是一个好主意……谢谢
附言
现在我意识到另一个问题。标有星号的章节与其他标题不一致。为什么?
PS2
我添加了一张我想获得的图片
PS3 游戏 有了这个完整的代码
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{newpxtext,newpxmath}
\useosf
\usepackage{microtype}
\usepackage{titletoc}
\usepackage[margin=3cm,heightrounded]{geometry}
\usepackage{showframe}
% book -- titletoc patch: https://tex.stackexchange.com/a/454553/134574
\usepackage{etoolbox}
\makeatletter
\patchcmd\@part
{\thepart}
{\protect\numberline{\thepart}}
{}{\FAIL}
\makeatother
\makeatletter
\titlecontents{part}
[0em]
{\addvspace{1.5pc}\filcenter}
{\large\partname~\thecontentslabel\endgraf\bfseries}
{\large}
{} % without page number
[\addvspace{.5pc}]
\titlecontents{chapter}
[0em]
{\vspace*{\baselineskip}}
{\mdseries
\llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}\chaptername~\thecontentslabel\\
\vspace*{0.3\baselineskip}%
\itshape
}
{\mdseries
\llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}%
\itshape
}
{}
[]
\titlecontents*{section}
[0em]
{}
{\footnotesize \thecontentslabel~}
{}
{\footnotesize,~\thecontentspage}
[~--~]
[]
\begin{document}
\renewcommand*\contentsname{\hfill\mdseries\huge Indice}
\tableofcontents
\part{Setting up of a Business}
\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}
\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}
\clearpage
\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}
\setcounter{page}{277}
\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}
\end{document}
答案1
您的\titlecontents
定义中有一些虚假空格,例如:
\hspace*{1.4em} \chaptername
产生的空间比
\hspace*{1.4em}\chaptername
你也用\contentslabel
错了。这个宏在边缘左侧为标签保留了一些空间。但从你的图片来看,我以为你不想要它,所以我删除了它并使用了普通的\hbox
。\llap
我还添加了\part
格式你的其它问题:
更新的代码:
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{titletoc}
% book -- titletoc patch: https://tex.stackexchange.com/a/454553/134574
\usepackage{etoolbox}
\makeatletter
\patchcmd\@part
{\thepart}
{\protect\numberline{\thepart}}
{}{\FAIL}
\makeatother
\usepackage{tikz}
\makeatletter
\contentsmargin[-1.55em]{1.55em}
\titlecontents{part}
[0em]
{\addvspace{1.5pc}\filcenter}
{\large\partname~\thecontentslabel\endgraf\bfseries}
{\large}
{} % without page number
[\addvspace{.5pc}]
\titlecontents{chapter}
[0em]
{\vspace*{\baselineskip}}
{\mdseries
\llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}\chaptername~\thecontentslabel\\
\vspace*{0.3\baselineskip}%
\itshape
}
{\mdseries
\llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}%
\itshape
}
{}
[]
\titlecontents*{section}
[0em]
{}
{\footnotesize \thecontentslabel~}
{}
{\footnotesize,~\thecontentspage}
[~--~]
[]
\begin{document}
\tableofcontents
\part{Setting up of a Business}
\addcontentsline{toc}{chapter}{\protect\tikz[remember picture, overlay]\protect\draw[red,ultra thick] (0,0) -- (0,-7);}
\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}
\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}
\clearpage
\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}
\setcounter{page}{277}
\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}
\end{document}