TransWikia.com

How to rename appendices according to the chapter number

TeX - LaTeX Asked by AYBRXQD on January 17, 2021

I’m writing a book that includes some chapters. In some chapters, it’s needed to prepare one or more appendices. Preparing a code for this style is simple as follows

documentclass{book}
usepackage{appendix}
usepackage{lipsum}


begin{document}
tableofcontents

chapter{one}  

lipsum[4-10]

chapter{two}  
lipsum[4-10]

begin{appendices}

chapter{app2.1}
lipsum[4-10]

chapter{app2.2}
lipsum[4-10]

end{appendices}


chapter{three}  

begin{appendices}

chapter{app3.1}
lipsum[4-10]

end{appendices}



chapter{four}  
lipsum[4-10]

chapter{five}  
lipsum[4-10]

begin{appendices}

chapter{app5.1}
lipsum[4-10]

chapter{app5.2}
lipsum[4-10]

end{appendices}

end{document}

As is clear, the appendices are Appendix A, Appendix B, and so on, regardless of the chapter number. But I want to rename them according to the chapter number such as Appendix 2.A, Appendix 2.B, Appendix 3.A, and so on. How shall I change the code?

One Answer

To make appendices behave that way, you should be using subappendices and sections.

documentclass{book}
usepackage{appendix}
usepackage{lipsum}

begin{document}
tableofcontents

chapter{one}  

lipsum[4-10]

chapter{two}label{test}
lipsum[4-10]

begin{subappendices}

section{app2.1}
lipsum[4-10]

section{app2.2}
lipsum[4-10]

end{subappendices}

chapter{three}  

begin{subappendices}

section{app3.1}
lipsum[4-10]

end{subappendices}

chapter{four}  
lipsum[4-10]

chapter{five}  
lipsum[4-10]

begin{subappendices}

section{app5.1}
lipsum[4-10]

section{app5.2}
lipsum[4-10]

end{subappendices}

end{document}

This version uses etoolbox to modify the appendices package.

documentclass{book}
usepackage{appendix}
usepackage{etoolbox}
usepackage{lipsum}

makeatletter
patchcmd{l@chapter}{setlength@tempdima{1.5em}}{setlength@tempdima{2.3em}}{}{1}
pretocmd{appendices}{edefcurrentchapter{thechapter}setcounter{@ppsaveapp}{0}}{}{2}
apptocmd{appendices}{renewcommand{thechapter}{currentchapter.Alph{chapter}}}{}{3}
makeatother

begin{document}
tableofcontents

chapter{one}  

lipsum[4-10]

chapter{two}label{test}
lipsum[4-10]

begin{appendices}

chapter{app2.1}
lipsum[4-10]

chapter{app2.2}
lipsum[4-10]

end{appendices}

chapter{three}  

begin{appendices}

chapter{app3.1}
lipsum[4-10]

end{appendices}

chapter{four}  
lipsum[4-10]

chapter{five}  
lipsum[4-10]

begin{appendices}

chapter{app5.1}
lipsum[4-10]

chapter{app5.2}
lipsum[4-10]

end{appendices}

end{document}

Correct answer by John Kormylo on January 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