LaTeX forum ⇒ Text FormattingTOC entries and formatting in scrbook

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
ck2018
Posts: 11
Joined: Wed Oct 17, 2018 12:21 pm

TOC entries and formatting in scrbook

Postby ck2018 » Thu Oct 10, 2019 9:32 pm

My main problem is getting the table of contents (TOC) to look right in scrbook. I can change the font of the chapter-entries, but not the section-entries. The work is divided into four major "divisions", in which there are chapters. I've altered scrbook's chapters to provide my "divisions", and altered the sections to provide the chapters.

The chapter-entry font is resized correctly in the TOC, but the section-entries are in too big a font. You would think that a call to \addtokomafont{sectionentry} would be the answer, but it doesn't work in scrbook, and I want this to be a book. Perhaps it's possible to make scrartcl act like a book, but I don't know how to do it.

MWE (I've included the calls to \RedeclareSectionCommand in case they affect the other aspects of the document.):

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. % !TEX TS-program = XeLaTeX
  2.  
  3. \documentclass[12pt,twoside,openany,cleardoublepage=plain]{scrbook}
  4.  
  5. \usepackage[
  6. paperwidth=6in,
  7. paperheight=9in,
  8. inner=0.6in,
  9. outer=0.6in,
  10. bindingoffset=0.15in,
  11. top=0.5in,
  12. bottom=0.5in,
  13. headsep=0.1in,
  14. footskip=0in,
  15. %showframe,
  16. twoside]{geometry}
  17.  
  18. \pagestyle{empty}
  19.  
  20. \usepackage{fontspec}
  21. \setmainfont{Junicode}
  22.  
  23. \usepackage[automark]{scrlayer-scrpage}
  24.  
  25. \addtokomafont{disposition}{\normalfont\small\rmfamily}
  26. \BeforeStartingTOC[toc]{\addtokomafont{disposition}{\small\rmfamily}}
  27. \addtokomafont{chapter}{\normalfont\normalsize\rmfamily\bfseries}
  28. \addtokomafont{section}{\normalfont\normalsize\rmfamily\bfseries}
  29.  
  30.  
  31. \clearpairofpagestyles
  32. \ihead*{\pagemark}
  33.  
  34. \RedeclareSectionCommand[beforeskip=0pt,afterskip=\baselineskip,innerskip=0pt,afterindent=false]{chapter}
  35.  
  36. \RedeclareSectionCommand[beforeskip=\baselineskip,afterskip=\baselineskip,afterindent=false]{section}
  37.  
  38. \RedeclareSectionCommand[beforeskip=\baselineskip,afterskip=\baselineskip,afterindent=false]{subsection}
  39.  
  40.  
  41. \def\thechapter{\Roman{chapter}}
  42.  
  43. \def\thesection{\Roman{section}}
  44.  
  45.  
  46. \begin{document}
  47.  
  48. \tableofcontents
  49. \newpage
  50.  
  51. \addchap{bla1}
  52.  
  53. some writing
  54. more writing
  55. more writing
  56. more writing
  57. more writing
  58. more writing
  59. more writing
  60. more writing
  61. more writing
  62. more writing
  63.  
  64. \section*{this shouldn't show up in the TOC}
  65.  
  66. \addchap{somechap1}
  67.  
  68. some more writing
  69. some more writing
  70. some more writing
  71. some more writing
  72. some more writing
  73. some more writing
  74. some more writing
  75. some more writing
  76. some more writing
  77.  
  78. \section{some section1}
  79.  
  80. foo
  81.  
  82. some more writing
  83. some more writing
  84. some more writing
  85. some more writing
  86. some more writing
  87.  
  88. \section{A REALLY REALLY REALLY REALLY LONG SECTION HEADING}
  89.  
  90. bar
  91.  
  92. \end{document}

User avatar
Ijon Tichy
Posts: 120
Joined: Mon Dec 24, 2018 10:12 am

Postby Ijon Tichy » Fri Oct 11, 2019 7:47 am

You can change the format of the section entries using either \DeclareTOCStyleEntry or simply prefix the \DeclareTOCStyleEntry attribute entryformat with toc to build the \RedeclareSectionCommand attribute tocentryformat. In the following example, I've also simplified some other font settings:
Code: [Select all] [Expand/Collapse] [Download] (changetocentryformats.tex)
  1. \documentclass[12pt,twoside,openany,cleardoublepage=plain]{scrbook}
  2.  
  3. \usepackage[
  4. paperwidth=6in,
  5. paperheight=9in,
  6. inner=0.6in,
  7. outer=0.6in,
  8. bindingoffset=0.15in,
  9. top=0.5in,
  10. bottom=0.5in,
  11. headsep=0.1in,
  12. footskip=0in,
  13. %showframe,
  14. twoside]{geometry}
  15.  
  16. \pagestyle{empty}
  17.  
  18. \usepackage{fontspec}
  19. \setmainfont{Junicode}
  20.  
  21. \usepackage[automark]{scrlayer-scrpage}
  22.  
  23. \setkomafont{disposition}{\normalfont\bfseries\small}% \normalfont usually
  24. % sets to \rmfamily
  25. \setkomafont{chapter}{}% Don't overwrite the font setting (i.e. size) of disposition.
  26. \setkomafont{section}{}% Don't overwrite the font setting (i.e. size) of disposition.
  27. \addtokomafont{chapterentry}{\mdseries}% Don't make chapter entries bold.
  28. % Alternative: \setkomafont{chapterentry}{\small}% Make chapter entries small.
  29. \newcommand*{\smalltocentry}[1]{\small #1}% To setup the small ToC entries
  30. % (see \RedeclareSectionCommand[…]{section})
  31.  
  32. \clearpairofpagestyles
  33. \ihead*{\pagemark}
  34.  
  35. \RedeclareSectionCommand[beforeskip=0pt,afterskip=\baselineskip,innerskip=0pt,afterindent=false]{chapter}
  36.  
  37. \RedeclareSectionCommand[beforeskip=\baselineskip,afterskip=\baselineskip,afterindent=false,tocentryformat=\smalltocentry]{section}
  38.  
  39. \RedeclareSectionCommand[beforeskip=\baselineskip,afterskip=\baselineskip,afterindent=false]{subsection}
  40.  
  41.  
  42. \def\thechapter{\Roman{chapter}}
  43.  
  44. \def\thesection{\Roman{section}}
  45.  
  46.  
  47. \begin{document}
  48.  
  49. \tableofcontents
  50. %\newpage Useless
  51.  
  52. \addchap{bla1}
  53.  
  54. some writing
  55. more writing
  56. more writing
  57. more writing
  58. more writing
  59. more writing
  60. more writing
  61. more writing
  62. more writing
  63. more writing
  64.  
  65. \section*{this shouldn't show up in the TOC}
  66.  
  67. \addchap{somechap1}
  68.  
  69. some more writing
  70. some more writing
  71. some more writing
  72. some more writing
  73. some more writing
  74. some more writing
  75. some more writing
  76. some more writing
  77. some more writing
  78.  
  79. \section{some section1}
  80.  
  81. foo
  82.  
  83. some more writing
  84. some more writing
  85. some more writing
  86. some more writing
  87. some more writing
  88.  
  89. \section{A REALLY REALLY REALLY REALLY LONG SECTION HEADING}
  90.  
  91. bar
  92.  
  93. \addchap{One more chapter}
  94.  
  95. \section{ALSO A SECTION}
  96.  
  97. \end{document}

I've also added one more section to illustrate, that your changes may result in duplicates for the section numbers. Maybe it would be a better idea to change the style of [t]\chapter[/t] and [t]\part[/t] and use [t]\part[/t] for the divisions. But I cannot decide this, because I do not know enough about the wanted result.

ck2018
Posts: 11
Joined: Wed Oct 17, 2018 12:21 pm

Postby ck2018 » Fri Oct 11, 2019 9:37 pm

Thank you very much for your help! :D The TOC is now looking much better, but the page-numbers for the section entries are still noticeably bigger than those for the chapters. Is there a way to change this?

Ijon Tichy wrote:I've also added one more section to illustrate, that your changes may result in duplicates for the section numbers.

Yes, that's exactly what I want. The divisions could theoretically be published separately, so the section numbers should start from scratch for each one.

Maybe it would be a better idea to change the style of [t]\chapter[/t] and [t]\part[/t] and use [t]\part[/t] for the divisions. But I cannot decide this, because I do not know enough about the wanted result.

You might be right. I have changed the MWE (below) and added notes to help you to get some idea of the desired result when compiled.

  • Divisions without sections need a number in the TOC.
  • Divisions with sections don't really a need a number in the TOC (although this not a big deal). The division "name" is present in the TOC almost like a heading for the sections listed beneath it.
  • You can see that the divisions do not need numbers, but they need to go in the TOC, so \addchap is perfect for this.
  • Sections need to be numbered in the TOC and indented slightly, which they are, so \section works well for this.

I have added numbers=noenddot to get rid of the dots before the numbers in the TOC, but now I need the numbers to be right aligned and to have an extra white space between the numbers and the entries (because some of the numbers go up high, e.g., XXVIII). Actually, it would be good to get the dot after the numbers back for the sections in the body text (not the TOC).

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass[numbers=noenddot,12pt,twoside,openany,cleardoublepage=plain]{scrbook}
  2.  
  3. \usepackage[
  4. paperwidth=6in,
  5. paperheight=9in,
  6. inner=0.6in,
  7. outer=0.6in,
  8. bindingoffset=0.15in,
  9. top=0.5in,
  10. bottom=0.5in,
  11. headsep=0.1in,
  12. footskip=0in,
  13. %showframe,
  14. twoside]{geometry}
  15.  
  16. \pagestyle{empty}
  17.  
  18. \usepackage{fontspec}
  19. \setmainfont{Junicode}
  20.  
  21. \usepackage[automark]{scrlayer-scrpage}
  22.  
  23. \setkomafont{disposition}{\normalfont\bfseries\small}% \normalfont usually
  24. % sets to \rmfamily
  25. \setkomafont{chapter}{}% Don't overwrite the font setting (i.e. size) of disposition.
  26. \setkomafont{section}{}% Don't overwrite the font setting (i.e. size) of disposition.
  27. \addtokomafont{chapterentry}{\mdseries}% Don't make chapter entries bold.
  28. % Alternative: \setkomafont{chapterentry}{\small}% Make chapter entries small.
  29. \newcommand*{\smalltocentry}[1]{\small #1}% To setup the small ToC entries
  30. % (see \RedeclareSectionCommand[…]{section})
  31.  
  32. \clearpairofpagestyles
  33. \ihead*{\pagemark}
  34.  
  35. \RedeclareSectionCommand[beforeskip=0pt,afterskip=\baselineskip,innerskip=0pt,afterindent=false]{chapter}
  36.  
  37. \RedeclareSectionCommand[beforeskip=\baselineskip,afterskip=\baselineskip,afterindent=false,tocentryformat=\smalltocentry]{section}
  38.  
  39. \RedeclareSectionCommand[beforeskip=\baselineskip,afterskip=\baselineskip,afterindent=false]{subsection}
  40.  
  41.  
  42. \def\thechapter{\Roman{chapter}}
  43.  
  44. \def\thesection{\Roman{section}}
  45.  
  46.  
  47. \begin{document}
  48.  
  49. \tableofcontents
  50. %\newpage Useless
  51.  
  52. \addchap{First Division: I have no subdivisions, so I do need the number here in the TOC -->}
  53.  
  54. some writing
  55. more writing
  56. more writing
  57. more writing
  58. more writing
  59. more writing
  60. more writing
  61. more writing
  62. more writing
  63. more writing
  64.  
  65. \section*{this shouldn't show up in the TOC}
  66.  
  67. \addchap{Second Division: I have subdivisions, so I don't really need the number here in the TOC -->}
  68.  
  69. some more writing
  70. some more writing
  71. some more writing
  72. some more writing
  73. some more writing
  74. some more writing
  75. some more writing
  76. some more writing
  77. some more writing
  78.  
  79. \section{some section1}
  80.  
  81. foo
  82.  
  83. some more writing
  84. some more writing
  85. some more writing
  86. some more writing
  87. some more writing
  88.  
  89. \section{A REALLY REALLY REALLY REALLY LONG SECTION HEADING}
  90.  
  91. \section{<-- Numbers should be right-aligned.}
  92.  
  93. bar
  94.  
  95. \addchap{Third Division}
  96.  
  97. \section{ALSO A SECTION, ONE THAT IS HAPPY THAT ITS NUMBERS HAVE RESTARTED FROM SCRATCH}
  98.  
  99. \end{document}
Last edited by ck2018 on Fri Oct 11, 2019 11:01 pm, edited 1 time in total.

User avatar
Ijon Tichy
Posts: 120
Joined: Mon Dec 24, 2018 10:12 am

Postby Ijon Tichy » Fri Oct 11, 2019 10:37 pm

ck2018 wrote:Thank you very much for your help! :D The TOC is now looking much better, but the numbers for the section entries are still noticeably bigger than those for the chapters.

Your example does not have any chapter number in the table of contents. And the numbers of the section entries in my example have the same size as the text of the section entries:

Image

ck2018 wrote:I have added numbers=noenddot to get rid of the dots before the numbers in the TOC, but now I need the numbers to be right aligned and to have an extra white space between the numbers and the entries (because some of the numbers go up high, e.g., XXVIII). Actually, it would be good to get the dot after the numbers back for the sections in the body text (not the TOC).

Actually it is too late to try to understand all this. But please have a look into the description of \DeclareTOCEntryStyle and all the options for style tocline. All these options also can be uses with \RedeclareSectionCommand, if you prefix them with toc as I've already told.
Attachments
test_20191011_223042.png
the table of contents
test_20191011_223042.png (38.91 KiB) Viewed 100 times

ck2018
Posts: 11
Joined: Wed Oct 17, 2018 12:21 pm

Postby ck2018 » Fri Oct 11, 2019 11:00 pm

Ijon Tichy wrote:Your example does not have any chapter number in the table of contents.


Sorry. I meant the page-numbers. But maybe it's an optical illusion.

It is indeed late. I'll have a look at the entries that you mentioned, and try to work it out. Thanks again!


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 9 guests