TransWikia.com

How to do this amsart Table of Contents excluding dots on bold section rows

TeX - LaTeX Asked by user50654 on June 15, 2021

I am having difficulty combining all the attributes for this kind of Table of Contents in my amsart document. I hope if someone can show me the complete template, it will be useful for many people. Every time I search and find one of the attributes, it does not work with the rest of the attributes. Hope someone can help.

The whole row for sections should be bold, including the section number and section page number.

Specifications:

  1. No line of dots before section page numbers.

  2. Line of dots before subsections and subsubsection numbers.

  3. Indented subsections aligned with section name, as below.

  4. Adjustable vspace between a subsection and the major section that follows. If it is a subsubsection followed by the major section, there should be adjustable vspace for that.

  5. No vspace between subsections in a given section. No vspace between subsubsections

  6. Adjustable hspace between section number and title of section.

  7. Adjustable hspace between subsection number and title of subsection, etc.

  8. Adjustable font size and font for “Contents”.

  9. Bold section names and pages, regular text for subsections.

  10. (Optional) Choose where the ToC page breaks when continuing to next page.

  11. (Optional) Move the ToC up from its default lower position.

Contents (Larger adjustable size and font)

1  No dot after section number, bold name, then white space, bold page number

   1.1  Subsection not bold . . . . . . . . . . . . . . . . . . . .  1

   1.2  Subsection  . . . . . . . . . . . . . . . . . . . . . . . .  3

        1.2.1  Subsubsection  . . . . . . . . . . . . . . . . . . .  7

        1.2.2  Subsubsection  . . . . . . . . . . . . . . . . . . .  9


2  No dot after number, bold name, then white space, bold page number

   2.1  Subsection not bold . . . . . . . . . . . . . . . . . . . . 11

   2.2  Subsection  . . . . . . . . . . . . . . . . . . . . . . . . 13

        2.2.1  Subsubsection   . . . . . . . . . . . . . . . .  . . 17

        2.2.2  Subsubsection    . . . . . . . . . . . . . . . . . . 19


Appendix A  --also bold with bold page number to the right -->

   A.1  First Section of Appendix A . . . . . . . . . . . . . . . . 21

   A.2  Second Section of Appendix A  . . . . . . . . . . . . . . . 23

        A.2.1  Subsection of second section of Appendix A . . . . . 27

        A.2.2  another Subsection   . . . . . . . . . . . . . . . . 29  

Appendix B  --also bold with bold page number to the right -->

   B.1  First Section of Appendix B . . . . . . . . . . . . . . . . 31

   B.2  Second Section of Appendix B  . . . . . . . . . . . . . . . 33

References  . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

The following is a minimal tex shell, added at the request of the commenter

    documentclass[onecolumn,10.5pt,reqno,a4paper]{amsart} 
usepackage{amsmath}
usepackage{amsthm}
usepackage{amssymb}
usepackage{mathrsfs}
usepackage[margin=1.55in]{geometry}
usepackage{geometry}
usepackage{graphicx}

title{Title with adjustable size, font}    
author{Name with adjustable size, font}

begin{document}

pagenumbering{roman}

maketitle
tableofcontents
clearpage
pagenumbering{arabic}
setcounter{page}{1}
pagestyle{myheadings}

section{section 1, No point after section #, followed by name, whitespace, bold page} Text
subsection{subsection 1.1 (not subsection 1.1.), followed by dots, regular page #} Text
subsection{subsection 1.2 (not subsection 1.2.), followed by dots, regular page #} Text
subsubsection{subsubsection} Text

section{section 2, No point after section #, followed by name, whitespace, bold page} Text
subsection{subsection 2.1 (not subsection 1.1.), followed by dots, regular page #} Text
subsubsection{subsubsection} Text
subsection{subsection 2.2 (not subsection 1.2.), followed by dots, regular page #} Text

section{section 3} Text

appendix
section{first section of appendix} Text
subsection{subsection} Text
subsubsection{subsubsection} Text
subsection{subsection} Text

section{second section of appendix} Text

thebibliography{99}

end{document}

One Answer

The amsart document class has a very strict way in which it sets things up, specifically because it is meant for publication submissions. As such, there's not much in terms of user-interface variation available. This is a good thing. However, it requires a complete revamp of the ToC-generation and interaction in order for it to be flexible.

Here is something that seems to satisfy all your requirements without using any additional packages (except etoolbox):

enter image description here

documentclass{amsart}
usepackage[showframe,paper=a5paper]{geometry}% Just for this example
usepackage{etoolbox}

% Modifications to amsart ToC-related macros...
makeatletter
letold@tocline@tocline
letsection@tocline@tocline
% Insert a dotted ToC-line for subsection and subsubsection only
newcommand{subsection@dotsep}{4.5}
newcommand{subsubsection@dotsep}{4.5}
patchcmd{@tocline}
  {hfil}
  {nobreak
     leadershbox{$m@th
        mkern subsection@dotsep muhbox{.}mkern subsection@dotsep mu$}hfill
     nobreak}{}{}
letsubsection@tocline@tocline
let@toclineold@tocline

patchcmd{@tocline}
  {hfil}
  {nobreak
     leadershbox{$m@th
        mkern subsubsection@dotsep muhbox{.}mkern subsubsection@dotsep mu$}hfill
     nobreak}{}{}
letsubsubsection@tocline@tocline
let@toclineold@tocline

letold@l@subsectionl@subsection
letold@l@subsubsectionl@subsubsection

def@tocwriteb#1#2#3{%
  begingroup
    @xpdefcsname #2@toclineendcsname##1##2##3##4##5##6{%
      ifnum##1>c@tocdepth
      else sboxz@{##5letindentlabel@tochangmeasure##6}fi}%
    csname l@#2endcsname{#1{csname#2nameendcsname}{@secnumber}{}}%
  endgroup
  addcontentsline{toc}{#2}%
    {protect#1{csname#2nameendcsname}{@secnumber}{#3}}}%

% Handle section-specific indentation and number width of ToC-related entries
newlength{@tocsectionindent}
newlength{@tocsubsectionindent}
newlength{@tocsubsubsectionindent}
newlength{@tocsectionnumwidth}
newlength{@tocsubsectionnumwidth}
newlength{@tocsubsubsectionnumwidth}
newcommand{settocsectionnumwidth}[1]{setlength{@tocsectionnumwidth}{#1}}
newcommand{settocsubsectionnumwidth}[1]{setlength{@tocsubsectionnumwidth}{#1}}
newcommand{settocsubsubsectionnumwidth}[1]{setlength{@tocsubsubsectionnumwidth}{#1}}
newcommand{settocsectionindent}[1]{setlength{@tocsectionindent}{#1}}
newcommand{settocsubsectionindent}[1]{setlength{@tocsubsectionindent}{#1}}
newcommand{settocsubsubsectionindent}[1]{setlength{@tocsubsubsectionindent}{#1}}

% Handle section-specific formatting and vertical skip of ToC-related entries
% @tocline{<level>}{<vspace>}{<indent>}{<numberwidth>}{<extra>}{<text>}{<pagenum>}
renewcommand{l@section}{section@tocline{1}{@tocsectionvskip}{@tocsectionindent}{}{@tocsectionformat}}%
renewcommand{l@subsection}{subsection@tocline{2}{@tocsubsectionvskip}{@tocsubsectionindent}{}{@tocsubsectionformat}}%
renewcommand{l@subsubsection}{subsubsection@tocline{3}{@tocsubsubsectionvskip}{@tocsubsubsectionindent}{}{@tocsubsubsectionformat}}%
newcommand{@tocsectionformat}{}
newcommand{@tocsubsectionformat}{}
newcommand{@tocsubsubsectionformat}{}
expandafterdefcsname toc@1formatendcsname{@tocsectionformat}
expandafterdefcsname toc@2formatendcsname{@tocsubsectionformat}
expandafterdefcsname toc@3formatendcsname{@tocsubsubsectionformat}
newcommand{settocsectionformat}[1]{renewcommand{@tocsectionformat}{#1}}
newcommand{settocsubsectionformat}[1]{renewcommand{@tocsubsectionformat}{#1}}
newcommand{settocsubsubsectionformat}[1]{renewcommand{@tocsubsubsectionformat}{#1}}
newlength{@tocsectionvskip}
newcommand{settocsectionvskip}[1]{setlength{@tocsectionvskip}{#1}}
newlength{@tocsubsectionvskip}
newcommand{settocsubsectionvskip}[1]{setlength{@tocsubsectionvskip}{#1}}
newlength{@tocsubsubsectionvskip}
newcommand{settocsubsubsectionvskip}[1]{setlength{@tocsubsubsectionvskip}{#1}}

% Adjust section-specific ToC-related macros to have a fixed-width numbering framework
patchcmd{tocsection}{indentlabel}{makebox[@tocsectionnumwidth][l]}{}{}
patchcmd{tocsubsection}{indentlabel}{makebox[@tocsubsectionnumwidth][l]}{}{}
patchcmd{tocsubsubsection}{indentlabel}{makebox[@tocsubsubsectionnumwidth][l]}{}{}

% Allow for section-specific page numbering format of ToC-related entries
newcommand{@sectypepnumformat}{}
renewcommand{contentsline}[1]{%
  expandafterletexpandafter@sectypepnumformatcsname @toc#1pnumformatendcsname%
  csname l@#1endcsname}
newcommand{@tocsectionpnumformat}{}
newcommand{@tocsubsectionpnumformat}{}
newcommand{@tocsubsubsectionpnumformat}{}
newcommand{setsectionpnumformat}[1]{renewcommand{@tocsectionpnumformat}{#1}}
newcommand{setsubsectionpnumformat}[1]{renewcommand{@tocsubsectionpnumformat}{#1}}
newcommand{setsubsubsectionpnumformat}[1]{renewcommand{@tocsubsubsectionpnumformat}{#1}}
renewcommand{@tocpagenum}[1]{%
  hfill {mdseries@sectypepnumformat #1}}

% Small correction to Appendix, since it's still a section which should be handled differently
letoldappendixappendix
renewcommand{appendix}{%
  leavevmodeoldappendix%
  addtocontents{toc}{%
    protectsettowidth{protect@tocsectionnumwidth}{protect@tocsectionformatsectionnamespace}%
    protectaddtolength{protect@tocsectionnumwidth}{2em}}%
}
makeatother

% #1 (default is as required)

% #2

% #3
makeatletter
settocsectionnumwidth{2em}
settocsubsectionnumwidth{2.5em}
settocsubsubsectionnumwidth{3em}
settocsectionindent{1pc}%
settocsubsectionindent{dimexpr@tocsectionindent+@tocsectionnumwidth}%
settocsubsubsectionindent{dimexpr@tocsubsectionindent+@tocsubsectionnumwidth}%
makeatother

% #4 & #5
settocsectionvskip{10pt}
settocsubsectionvskip{0pt}
settocsubsubsectionvskip{0pt}
    
% #6 & #7
% See #3

% #8
renewcommand{contentsnamefont}{bfseriesLarge}

% #9
settocsectionformat{bfseries}
settocsubsectionformat{mdseries}
settocsubsubsectionformat{mdseries}
setsectionpnumformat{bfseries}
setsubsectionpnumformat{mdseries}
setsubsubsectionpnumformat{mdseries}

% #10
% Insert the following command inside your text where you want the ToC to have a page break
newcommand{tocpagebreak}{leavevmodeaddtocontents{toc}{protectclearpage}}

% #11
letoldtableofcontentstableofcontents
renewcommand{tableofcontents}{%
  vspace*{-linespacing}% Default gap to top of CONTENTS is linespacing.
  oldtableofcontents}

setcounter{tocdepth}{3}
begin{document}

tableofcontents
section{First section}
subsection{First subsection}
subsection{Second subsection}
subsubsection{First subsubsection}
subsubsection{Second subsubsection}
section{Second section}
subsection{First subsection}
tocpagebreak
subsection{Second subsection}
subsubsection{First subsubsection}
subsubsection{Second subsubsection}

appendix
section{An appendix section}
subsection{First appendix subsection}
subsection{Second appendix subsection}
subsubsection{First appendix subsubsection}
subsubsection{Second appendix subsubsection}
end{document}

Specific to the requirements:

  1. This is the default setting under amsart, so there's nothing to be done in this regard.

  2. Only the subsection and subsubsection ToC entries have been adjusted to include a dotted line. This was taken from latex.ltx's @dottedtocline that uses leaders.

Adjustments to the spacing between the dots can be achieved using (for example)

    makeatletter
    renewcommand{subsection@dotsep}{5}% Adjust subsection dot gap
    renewcommand{subsubsection@dotsep}{5}% Adjust subsubsection dot gap
    makeatother

The default values for both are 4.5.

  1. The indentation can be set for each of the section levels section, subsection and subsubsection, in addition to the width of the numbers in the ToC. The following self-explanatory macros set the defaults:

     makeatletter
     settocsectionnumwidth{2em}
     settocsubsectionnumwidth{2.5em}
     settocsubsubsectionnumwidth{3em}
     settocsectionindent{1pc}%
     settocsubsectionindent{dimexpr@tocsectionindent+@tocsectionnumwidth}%
     settocsubsubsectionindent{dimexpr@tocsubsectionindent+@tocsubsectionnumwidth}%
     makeatother
    

The subsection and subsubsection indents are set relative to the sections and subsections, making them line up within the ToC as required.

  1. The default @tocline macro of amsart provides a vertical skip before every sectional unit. This has been customized and can be set with a number of user-interface macros. The defaults are:

     settocsectionvskip{10pt}
     settocsubsectionvskip{0pt}
     settocsubsubsectionvskip{0pt}
    

This leaves a gap of at least 10pt above a section heading, but no gap (0pt) above a subsection or subsubsection.

  1. See (4) above.

  2. This can be adjusted using the number widths as refined in (3) above.

  3. See (6).

  4. contentsnamefont holds the formatting of the ToC heading. A simple renewcommand suffices to changes this. For example,

     renewcommand{contentsnamefont}{bfseriesLarge}
    
  5. Each sectional heading in the ToC can be formatted at the "number+title" and "page number" level via the following self-explanatory macros:

     settocsectionformat{bfseries}
     settocsubsectionformat{mdseries}
     settocsubsubsectionformat{mdseries}
     setsectionpnumformat{bfseries}
     setsubsectionpnumformat{mdseries}
     setsubsubsectionpnumformat{mdseries}
    
  6. (Optional) Insert tocpagebreak within your document at the appropriate place between sectional units where you want the equivalent location to be broken in the ToC.

  7. (Optional) tableofcontents can be adjusted to insert a negative vspace where appropriate.

This adaptation is not compatible with hyperref, unfortunately. If that is required, one may be better off by recreating the ToC and sectional unit layout using packages that support this in a more consistent/uniform way, and using a different class like article.

Answered by Werner on June 15, 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