Document Classes"Changing document class" in the middle of a document

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
phsopher
Posts: 6
Joined: Mon Nov 08, 2010 6:09 pm

"Changing document class" in the middle of a document

Post by phsopher »

Hi. I'm writing a document using the 'report' class and I'm very happy with it. However I would like to add an appendix which is not very long so it looks silly to have the huge chapter headings for each part of the appendix. In short, I would like the appendix to be formatted as 'article' with sections being designated 1, 2 etc. instead of .1, .2 etc. when the chapter is not specified. Is there a way to do it?

Also, while I'm at it, how do I link to chapters, sections and appendices with hyperref?

Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

"Changing document class" in the middle of a document

Post by Stefan Kottwitz »

Hi,

perhaps let the appendix be one chapter consisting of sections.
Or modify the headings.

Mixing of classes is not so straightforward, but a simple way would be to create 2 separate documents with different classes and merge the pdf files afterwards.

Concerning hyperref - just load it by

Code: Select all

\usepackage{hyperref}
and the chapters and sections will be linked from the toc and by bookmarks.

Stefan
LaTeX.org admin
phsopher
Posts: 6
Joined: Mon Nov 08, 2010 6:09 pm

Re: "Changing document class" in the middle of a document

Post by phsopher »

Thanks for your reply. The problem with doing it as one chapter is that then it says 'Appendix A' which carries the implication that there is a 'B' which at least to me is aesthetically unappealing. Making a separate document for the appendix is an option, but I would like to have links to previous equations (it's a physics report), bibliography etc. and I would like to link to the appendix itself from the main text. I don't mean to be picky, it's not a big deal. I was just wondering if there was an easy way of doing it.

In regards to hyperref, I already have it loaded and I use it to reference equations (with eqref) and for the table of contents. In addition I would like to link to chapters or sections in the text. Like putting "see Chapter 2" and it would take you to Chapter 2, or "see Appendix B" and it takes you to the Appendix B. It's not very clear to me how to do that. Perhaps that can be accomplished with the bookmarks you mentioned, could you be more specific?

Anyway, these are just minor cosmetic changes so it doesn't matter that much even if it can't be done. I just thought I'd ask.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

"Changing document class" in the middle of a document

Post by Stefan Kottwitz »

Hi,

regarding switching from chapter to section - did you ever see this in a book? I guess it's very uncommon for a book or report, which uses chapters and sections, to continue just with sections hanging around without a chapter above. Logically, they would belong to the chapter before the appendix. A structure is more than cosmetic - the structure would be damaged in my opionon.

I've seen two ways:
  • appendix consisting of chapters, especially if they are not short
  • or an appendix chapter, consisting of sections.
But of course it's not hard to implement also inconsistent behaviour. But first think about it ... even if it results in a \chapter*{Appendix} with following sections and adjusted numbering.

Concerning hyperref: the package offers an extensive manual where this linking is described. You can open it by typing

Code: Select all

texdoc hyperref/manual
or just

Code: Select all

texdoc hyperref
at the command prompt on your computer or here on CTAN.

Stefan
LaTeX.org admin
phsopher
Posts: 6
Joined: Mon Nov 08, 2010 6:09 pm

"Changing document class" in the middle of a document

Post by phsopher »

The code

Code: Select all

\appendix

\chapter{This is the title}
produces a new chapter saying:

"Appendix A

This is the title."

The code

Code: Select all

\appendix

\section{This is the title}
produces something that looks like a section saying:

".1 This is the title."

I would like to have the layout of the second example but with proper numbering so that it would be "A. This is the title" or something like that. Alternatively, I could have the whole appendix as a single chapter with sections but in that case I would like it to just say "Appendix" instead of "Appendix A". Come to think of it, the second way would probably be more consistent as you say.

Also, by cosmetic changes I meant that the exact layout of the document is not that big of a deal to me and I can make due with the default structure.

Thanks for the hyperref manual, I'll have a look at it when I have time.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

"Changing document class" in the middle of a document

Post by Stefan Kottwitz »

Here's an example:

Code: Select all

\documentclass{report}
\begin{document}
\tableofcontents
\chapter{First chapter}
\chapter{Second chapter}
\section{A section}
\appendix
\chapter*{Appendix}
\addcontentsline{toc}{chapter}{Appendix}
\renewcommand*{\thesection}{\Alph{section}}
\section{First title}
\section{Second title}
\end{document}
The appendix is an unnumbered chapter. The structure, seen in the TOC:
appendix.png
appendix.png (8.35 KiB) Viewed 10446 times
Stefan
LaTeX.org admin
phsopher
Posts: 6
Joined: Mon Nov 08, 2010 6:09 pm

Re: "Changing document class" in the middle of a document

Post by phsopher »

That's perfect, thanks a lot.
phsopher
Posts: 6
Joined: Mon Nov 08, 2010 6:09 pm

Re: "Changing document class" in the middle of a document

Post by phsopher »

Actually, one more thing. Now the labeling of equations has gone from (A1), (A2), (B1), (B2) etc. to (1), (2), (3), (4). Is there any way to change them back?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

"Changing document class" in the middle of a document

Post by Stefan Kottwitz »

How did you produce the numbering before? Do you really mean (A1) or perhaps (A.1)?
The latter can be done by

Code: Select all

\numberwithin{equation}{section}
if you use amsmath, or by \counterwithin of the chngcntr package. Otherwise additionally redefine \theequation.
Since the numbering is originally per chapter, you have to change it to be per section. That would be necessary for tables, figures etc. as well - that's a result of diverging from the class' chapter style.

Stefan
LaTeX.org admin
phsopher
Posts: 6
Joined: Mon Nov 08, 2010 6:09 pm

Re: "Changing document class" in the middle of a document

Post by phsopher »

Yeah, I meant (A.1) etc. and that works. Thanks again for your help.
Post Reply