TeX - LaTeX Asked by gwg on May 14, 2021
I am using subappendices or an appendix after each chapter, following this post. This is the Latex I am using
usepackage[toc,page]{appendix}
AtBeginEnvironment{subappendices}{%
chapter*{Appendix}
addcontentsline{toc}{chapter}{Appendices}
counterwithin{figure}{section}
counterwithin{table}{section}
}
which produces, for example, this:
However, the subappendices’ titles do not have numbers. Ideally, they would and their sections would have numbers based on that number. What I had in mind would be like this:
3. Chapter Three
3.1 Intro
3.2 Some details
3.3 Experiments
3A. Appendix
3A.1 First subappendix of chapter 3
3A.2 More details etc
Is there a way to achieve this?
You can modify the code from the early post so that:
This is done with:
AtBeginEnvironment{subappendices}{%
chapter*{thechapter Aquadappendixname}
% add numberline{<num-chap>A} to toc
addcontentsline{toc}{chapter}{%
protectnumberline{thechapter A}appendixname}
counterwithin{figure}{section}
counterwithin{table}{section}
}
% make section display <num-chap>A.<num-sec>
apptocmd{subappendices}{%
renewcommand{thesection}{thechapter A.arabic{section}}}{}{}
However, one sees that new appendix numberings (like 1A.2) are longer than previous (like 1.B) and toc lines have numbers too close to titles as you can see below:
So you may increase these gaps. Look for the code of l@chapter and l@section in your class file (book.cls
here) and change spacing, like below:
makeatletter
% in l@chapter change 1.5em by 2em
patchcmd{l@chapter}{1.5em}{2em}{}{}
% in l@section change {1.5em}{2.3em} by {2em}{2.8em}
renewcommand*l@section{@dottedtocline{1}{2em}{3em}}
makeatother
The full code:
documentclass{book}
usepackage{appendix}
usepackage{chngcntr}
usepackage{etoolbox}
usepackage{lipsum}
AtBeginEnvironment{subappendices}{%
chapter*{thechapter Aquadappendixname}
% add numberline{<num-chap>A} to toc
addcontentsline{toc}{chapter}{%
protectnumberline{thechapter A}appendixname}
counterwithin{figure}{section}
counterwithin{table}{section}
}
% make section display <num-chap>A.<num-sec>
apptocmd{subappendices}{%
renewcommand{thesection}{thechapter A.arabic{section}}}{}{}
makeatletter
% in l@chapter change 1.5em by 2em
patchcmd{l@chapter}{1.5em}{2em}{}{}
% in l@section change {1.5em}{2.3em} by {2em}{2.8em}
renewcommand*l@section{@dottedtocline{1}{2em}{3em}}
makeatother
begin{document}
tableofcontents
chapter{Test Chapter One}
section{A regular section}
section{Another regular section}
begin{subappendices}
section{Some title for an appendix}
lipsum[4]
section{Some title for an appendix}
lipsum[4]
end{subappendices}
chapter{Test Chapter Two}
section{A regular section}
section{Another regular section}
begin{subappendices}
section{Some title for an appendix}
lipsum[4]
section{Some title for an appendix}
lipsum[4]
section{Some title for an appendix}
lipsum[4]
end{subappendices}
end{document}
Correct answer by Miguel V. S. Frasson on May 14, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP