目录中的页码未右对齐

目录中的页码未右对齐

我的目录有问题。如果章节标题与目录的宽度一样长,则页码会被强制放到下一行。但是,页码不是在右侧对齐,而是在左侧对齐。我希望页码在所有情况下都位于右侧。也许有办法设置它。我正在使用 titletoc 包。

在此处输入图片描述

这是我的代码

\documentclass[twoside,openany,10pt]{book}  
\usepackage[paperwidth=5in, paperheight=8in, bindingoffset=0.375in, top=0.7in, bottom=0.7in, left=0.5in, right=0.5in]{geometry}
\renewcommand{\baselinestretch}{1.3}
\usepackage{titlesec}
\usepackage {setspace}
\usepackage{librebaskerville}
\usepackage[T1]{fontenc}
\usepackage{anyfontsize}
\usepackage{letterspace}
\usepackage{fancyhdr}
\usepackage{titletoc}%
\usepackage{graphicx}
\usepackage{float}
\usepackage[overload]{textcase}
\usepackage{microtype}
\usepackage[symbol]{footmisc}
\usepackage{enumerate}


\renewcommand{\thefootnote}{\fnsymbol{footnote}}




\titlecontents{chapter}% <section-type>
  [2.3em]% <left>
  {\small}% <above-code>
  {\hspace*{-2.3em}\makebox[2.3em][l]{\thecontentslabel. }}% <numbered-entry-format>
  {}% <numberless-entry-format>
  {\hfill\contentspage}% <filler-page-format>




%Begin Document
\begin{document} 

\pagestyle{empty}
\tableofcontents                        % Print table of contents
\thispagestyle{empty}

%\newcommand{\chaptertolists}{}


%HERE BEGINS TEXT EDITING


\mainmatter                             % only in book class (arabic page #s)    
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{
\markboth{Thought Vibration} {#1}}
\fancyhead[CO]{\small \itshape \rightmark}
\fancyhead[CE]{\small \itshape \leftmark}
\fancyhead[RE,LO]{}
\fancyhead[LE,RO]{}
\fancyfoot[CO, CE]{\small \thepage}



\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}{\lsstyle\MakeUppercase{\chaptertitlename} \thechapter}{20pt}{\normalfont\LARGE\itshape}
  \titlespacing*{\chapter}{0pt}{30pt}{20pt}

\pagenumbering{arabic}

%ONLY FOR COLLECTIONS
%\addtocontents{toc}{\protect\thispagestyle{empty}}
%\addcontentsline{toc}{part}{The Science of Getting Rich}
%\part*{The Science of Getting Rich}

\addtocontents{toc}{\protect\thispagestyle{empty}}
\addcontentsline{toc}{chapter}{Preface}
\markboth{Thought Vibration} {Preface}
\chapter*{Preface}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco

\addtocontents{toc}{\protect\thispagestyle{empty}}
\addcontentsline{toc}{chapter}{Foreword}
\markboth{Thought Vibration} {Foreword}
\chapter*{Foreword}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco

\addtocontents{toc}{\protect\thispagestyle{empty}}
\addcontentsline{toc}{chapter}{My Working Creed}
\markboth{Thought Vibration} {My Working Creed}
\chapter*{My Working Creed}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco

\chapter{The Law Of Attraction In The Thought World} 

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco

\chapter{Thought‐Waves And Their Process Of Reproduction} 

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco

\end{document}

提前致谢。 :)

答案1

您应该使用\hangindent上面的代码。我已对您的代码进行了更改\titlecontents(请记住删除旧目录并双击运行它):

\titlecontents{chapter}
  [3.3em]
  {\small\hangindent2.3em}% <- Change made here
  {\makebox[2.3em][l]{\thecontentslabel.}}
  {}% 
  {\hfill\contentspage}

编译结果如下:

改变的内容

如果可能的话,您还可以使用\chapter以下语法使用该命令缩短目录中显示的文本:

\chapter{short version}{long version}

以便\chapter{The Laws Of Attraction}{The Law Of Attraction In The Thought World}

编译结果如下:

使用章节

希望这可以帮助。

相关内容