附录列表中长节级条目的悬挂缩进

附录列表中长节级条目的悬挂缩进
\documentclass[a4paper,oneside,11pt]{book}
\usepackage[left=4 cm,right=3cm,top=4cm,bottom=3cm]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage{titlesec}

\usepackage{tocloft}
% code for List of Appendices
\newcommand{\listappendicesname}{List of Appendices}
\newlistof{appendix}{app}{\listappendicesname}
% new command for appendix sections
\newcommand{\appsection}[1]{\section{#1}%
    \addcontentsline{app}{appendix}{Appendix \protect\numberline{\thesection}#1}\par}

\titleformat{\chapter}
[display]
{\center\bfseries}
{\large\MakeUppercase{\chaptertitlename} \thechapter}{1pt}{\large}
\titlespacing{\chapter}{0cm}{-1.2cm}{0.7cm}

\titleformat{\section}
[hang]
{\bfseries}
{\bfseries\thesection}{1ex}{\bfseries}

\usepackage{tocbasic}
\DeclareTOCStyleEntry[
linefill=\bfseries\TOCLineLeaderFill,
beforeskip=2pt,
entrynumberformat=\chapterprefixintoc,
dynnumwidth
]{tocline}{chapter}

\newcommand*\chapterprefixintoc[1]
{\MakeUppercase{\chaptername}~#1\enskip}

\begin{document}
    \frontmatter
    \tableofcontents
    
    \newpage
    % print list of appendices and add title to the ToC
    \listofappendix \addcontentsline{toc}{chapter}{\listappendicesname}
    
    \mainmatter
    \chapter{ABC}
    \section{First Section First Section First Section First Section First Section First Section First Section First Section}
    \lipsum[1-2]
    \section{Second Section Second Section Second Section Second Section Second Section Second Section Second Section Second Section }
    \lipsum[3-4]
    
    \chapter*{APPENDIX}
    \setcounter{section}{0}
    \renewcommand{\thesection}{\arabic{section}}
    \titleformat{\section}
    {\normalfont\Large\bfseries}{Appendix~\thesection.}{1em}{}
    %%%%%    \addcontentsline{toc}{chapter}{APPENDICES} % don't add to ToC
    \addtocontents{toc}{\protect\setcounter{tocdepth}{0}} % No sections in ToC
    \appsection{First Appendix First Appendix First Appendix First Appendix First Appendix }
    \lipsum[4-4]
    
    \appsection{Second Appendix Second Appendix Second Appendix Second Appendix Second Appendix }
    \lipsum[3-3]
\end{document}

我制作了附录列表,并希望附录的长标题如下图所示对齐。该怎么做?

在此处输入图片描述

答案1

既然您使用该tocloft包来获取其\newlistof宏,我相信使用该包来解决与目录和附录列表格式相关的问题也很有用。

以下代码就是这样做的;如果您认为我错过或误解了您的格式化目标,请告诉我。


在此处输入图片描述


在此处输入图片描述

\documentclass[a4paper,oneside,11pt]{book}
\usepackage[left=4cm,right=3cm,top=4cm,bottom=3cm]{geometry}
\usepackage{amssymb,amsmath}
\usepackage{microtype} % <-- nice to have
\usepackage{lipsum}

%% Formatting of chapter-level and section-level headers
\usepackage{titlesec}
\titlespacing{\chapter}{0cm}{-1.2cm}{0.7cm}
\titleformat{\chapter}[display]%
    {\centering\bfseries}%
    {\large\MakeUppercase{\chaptertitlename} \thechapter}{1pt}{\large}
\titleformat{\section}[hang]%
    {\bfseries}%
    {\bfseries\thesection}{1ex}{\bfseries}

% New command '\appsection'
\newcommand{\appsection}[1]{\section{#1}%
    \addcontentsline{app}{appendix}{\protect\numberline{\thesection}#1}}

\usepackage{tocloft}
% Code for chapter-level entries in TOC: use dot leaders, 
%   use "chapter" prefix for numbered chapters
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftchappresnum}{\MakeUppercase{\chaptername}\space}
\setlength{\cftchapnumwidth}{8em}
\renewcommand{\cftchappagefont}{\mdseries}
% Code for List of Appendices
\newcommand{\listappendicesname}{List of Appendices}
\newlistof{appendix}{app}{\listappendicesname}
\renewcommand{\cftappendixpresnum}{\appendixname\space}
\setlength{\cftappendixnumwidth}{6em}


\begin{document}

\frontmatter

\tableofcontents  
\newpage
\listofappendix 
\addcontentsline{toc}{chapter}{\listappendicesname}
    
    
\mainmatter

\chapter{ABC}
    \section{First Section First Section First Section First Section First Section 
             First Section First Section First Section}
    \lipsum[1-2]
    \section{Second Section Second Section Second Section Second Section Second 
             Section Second Section Second Section Second Section }
    \lipsum[3-4]
    
\chapter*{\MakeUppercase{\appendixname}}
    \setcounter{section}{0}
    \renewcommand{\thesection}{\arabic{section}}
    % Don't show appendix sections separately in the ToC:
    \addtocontents{toc}{\protect\setcounter{tocdepth}{0}} 
    \titleformat{\section}%
        {\normalfont\large\bfseries}%
        {\appendixname~\thesection.}{1em}{}
    
    \appsection{First Appendix First Appendix First Appendix First Appendix First Appendix }
    \lipsum[4]
    
    \appsection{Second Appendix Second Appendix Second Appendix Second Appendix Second Appendix }
    \lipsum[3]
    
\end{document}

相关内容