TransWikia.com

Hanging indentation of long section-level entries in the List of Appendices

TeX - LaTeX Asked on July 17, 2021

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 protectnumberline{thesection}#1}par}

titleformat{chapter}
[display]
{centerbfseries}
{largeMakeUppercase{chaptertitlename} thechapter}{1pt}{large}
titlespacing{chapter}{0cm}{-1.2cm}{0.7cm}

titleformat{section}
[hang]
{bfseries}
{bfseriesthesection}{1ex}{bfseries}

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

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

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}
    {normalfontLargebfseries}{Appendix~thesection.}{1em}{}
    %%%%%    addcontentsline{toc}{chapter}{APPENDICES} % don't add to ToC
    addtocontents{toc}{protectsetcounter{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}

I have make list of appendices and I want the long title of appendices is align as picture below. How to do that?

enter image description here

One Answer

Since you employ the tocloft package for its newlistof macro, I believe it's useful to employ the package for issues related to the formatting of the table of contents and the list of appendices as well.

The following code does so; please let me know if you believe I missed or misunderstood your formatting objectives.


enter image description here


enter image description here

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]%
    {centeringbfseries}%
    {largeMakeUppercase{chaptertitlename} thechapter}{1pt}{large}
titleformat{section}[hang]%
    {bfseries}%
    {bfseriesthesection}{1ex}{bfseries}

% New command 'appsection'
newcommand{appsection}[1]{section{#1}%
    addcontentsline{app}{appendix}{protectnumberline{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}{appendixnamespace}
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}{protectsetcounter{tocdepth}{0}} 
    titleformat{section}%
        {normalfontlargebfseries}%
        {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}

Correct answer by Mico on July 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP