General ⇒ Both parts and chapters in a document?
Both parts and chapters in a document?
I've been trying to find a way to divide the body of my book class document into parts, but to have the introduction and conclusion chapters separate.
Currently, the introduction is separate because it's before I declare the first part, but the conclusion is considered to belong to the final part. This is a problem for the table of contents and the pdf linking structure for the document.
Is there any way to specify that conclusion chapter is at the same level as the introduction and the parts? I've been looking for a way to end the parts without starting a new one, so far unsuccessfully, but there may be other approaches I haven't thought of.
Thanks!
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
-
- Posts: 66
- Joined: Tue Oct 07, 2008 9:39 am
Both parts and chapters in a document?
I cannot understand this post.ashtah wrote:Hi,
I've been trying to find a way to divide the body of my book class document into parts, but to have the introduction and conclusion chapters separate.
Currently, the introduction is separate because it's before I declare the first part, but the conclusion is considered to belong to the final part. This is a problem for the table of contents and the pdf linking structure for the document.
Is there any way to specify that conclusion chapter is at the same level as the introduction and the parts? I've been looking for a way to end the parts without starting a new one, so far unsuccessfully, but there may be other approaches I haven't thought of.
Thanks!
Re: Both parts and chapters in a document?
I have a document I want to structure as follows:
Chapter 1 : Intro
-------------
PART I
Chapter 2: Background
Chapter 3: Approach
-------------
PART II
Chapter 4: Background
Chapter 5: Approach
-------------
Chapter 6: Conclusion
(I have left out the sections etc for clarity and brevity, as they are functioning fine)
I have been using \part to indicate the beginnings of the parts, and \chapter for the chapters. The first part is declared after the introduction chapter. When I turn it into a pdf, I end up with this:
Chapter 1 : Intro
-------------
PART I
Chapter 2: Background
Chapter 3: Approach
-------------
PART II
Chapter 4: Background
Chapter 5: Approach
Chapter 6: Conclusion
-------------
That is, the conclusion chapter is listed as an element of Part II, when it is meant to be the overall conclusion of the document, in the manner of the introduction.
I have now managed to hack the temporary files using regular expressions to separate out the conclusion so that it is structured like the initial example, but it is a hack. I would like to be able to do this neatly in the tex file, if possible. Some sort of way to indicate the end of the current part, without needing to include an additional one. (I don't want to have to have a Part III that contains the conclusion and using a /part* leaves the conclusion a member of Part II).
Hope that clears things up a little!
-
- Posts: 55
- Joined: Thu Oct 30, 2008 4:12 pm
Both parts and chapters in a document?
I am trying to do exactly the same thing as ashtah, but to no avail. I've looked into defining an environment, which would result in a scoped part, so you would use this code to produce the desired effect:
Code: Select all
\chapter{Intro}
\begin{part}{part 1 title}
\chapter{Background}
\chapter{Approach}
\end{part}
\begin{part}{part 2 title}
\chapter{Background}
\chapter{Approach}
\end{part}
\chapter{Conclusion}
Code: Select all
%% Make a new scoped part.
\let\@oldpart\part
\let\@inpart=false
\renewenvironment{part}[1]
{
\let\@inpart=true
oldpart{#1}
}
{
\let\@inpart=false
}
Anyway, my thinking here is that the chapter must somehow know that it follows a part, otherwise it wouldn't appear to belong to the part. If I could find an appropriate part in the chapter definition, I could \renewcommand the chapter code such that it would have current (default) behaviour if inpart==true and be a separate entity if inpart==false. Is this a) clear, b) possible? If yes to both, how can I do it?
I appreciate any time you spend on this problem.
Re: Both parts and chapters in a document?
So, going to the problem here, if one wants the conclusions chapter to be independent of the last part, what should be the typographical elements to be inserted right before the conclusions? How can the reader be aware of the end of that part? A blank page in between? Something is needed to visually disrupt the flow of the chapters in the last part. But what exactly? Once this is clear, we can think about LaTeX programming.
-
- Posts: 55
- Joined: Thu Oct 30, 2008 4:12 pm
Both parts and chapters in a document?
In the table of contents, I'd like a vertical space between the last chapter in the last part the same size as that between the last chapter and the following part, so:
In the main text, I would like it to appear exactly as it would if there were a part there, but without the text of part number and title. This effect appears to be achieved by putting \part*{ } before chapter 7 (in the above example), but this doesn't do anything else I'd like it to do.1 Introduction
2 A second chapter
I Title of first part
3 The first chapter in part I
4 The second chapter in part I
II Title of second part
5 The first chapter in part II
6 The second chapter in part II
7 An independent chapter
8 Conclusion
A Appendix a
B Appendix b
Bibliography
Finally, I'm creating PDF files and including the hyperref package; I'd like the bookmarks to be set so that it doesn't have chapters 7 and 8 and the appendices and bibliography as subcomponents of part II, so not like this:
but like this:+ Introduction
+ A second chapter
+ Title of first part
- The first chapter in part I
- The second chapter in part I
+ Title of second part
- The first chapter in part II
- The second chapter in part II
- An independent chapter
- Conclusion
- Appendix a
- Appendix b
- Bibliography
+ Introduction
+ A second chapter
+ Title of first part
- The first chapter in part I
- The second chapter in part I
+ Title of second part
- The first chapter in part II
- The second chapter in part II
+ An independent chapter
+ Conclusion
+ Appendix a
+ Appendix b
+ Bibliography
Both parts and chapters in a document?
I can propose a semi-automatic way to get your goals. Consider the following code:
Code: Select all
\documentclass[a4paper,11pt]{book}
\usepackage[colorlinks]{hyperref}
% Loading lipsum to write blind text
\usepackage{lipsum}
% Redefinition of \cleardoublepage. Even pages are left completely blank.
\let\origdoublepage\cleardoublepage
\renewcommand{\cleardoublepage}{%
\clearpage{\pagestyle{empty}\origdoublepage}}
\begin{document}
% ----------
\pdfbookmark[-1]{\contentsname}{toc}
\tableofcontents
% ----------
\cleardoublepage\pdfbookmark[-1]{Introduction}{introduction}
\chapter{Introduction}
\lipsum[1]
% ----------
\part{Title of the first part}
\chapter{The first chapter in the first part}
\section{First section (first part, first chapter)}
\lipsum[1-5]
\section{Second section (first part, first chapter)}
\lipsum[1-5]
\chapter{The second chapter in the first part}
\lipsum[1-5]
% ----------
\part{Title of the second part}
\chapter{The first chapter in the second part}
\lipsum[1-5]
\chapter{The second chapter in the second part}
\section{First section (second part, second chapter)}
\lipsum[1-5]
\section{Second section (second part, second chapter)}
\lipsum[1-5]
% ----------
\cleardoublepage\pagestyle{empty}\mbox{}\cleardoublepage
\addtocontents{toc}{\protect\addvspace{2.25em}}
\cleardoublepage\pdfbookmark[-1]{An independent chapter}{indchp}
\chapter{An independent chapter}
\lipsum[1-5]
\cleardoublepage\pdfbookmark[-1]{Conclusions}{conclusions}
\chapter{Conclusions}
\lipsum[1-5]
% ----------
\appendix
\cleardoublepage\pdfbookmark[-1]{The first appendix}{firstapp}
\chapter{The first appendix}
\lipsum[1-5]
\cleardoublepage\pdfbookmark[-1]{The second appendix}{secondapp}
\chapter{The second appendix}
\lipsum[1-5]
% ----------
\cleardoublepage\pdfbookmark[-1]{\bibname}{bibliography}
\phantomsection\addcontentsline{toc}{chapter}{\bibname}
% \bibliographystyle{....}
% \bibliography{....}
\begin{thebibliography}{9}
\bibitem{misc} This is just to simulate a bibliography.
\end{thebibliography}
\end{document}
Code: Select all
\BOOKMARK [-1][-]{toc.-1}{Contents}{}
\BOOKMARK [-1][-]{introduction.-1}{Introduction}{}
\BOOKMARK [0][-]{chapter.1}{Introduction}{introduction.-1}
\BOOKMARK [-1][-]{part.1}{I Title of the first part}{}
\BOOKMARK [0][-]{chapter.2}{The first chapter in the first part}{part.1}
\BOOKMARK [1][-]{section.2.1}{First section \(first part, first chapter\)}{chapter.2}
\BOOKMARK [1][-]{section.2.2}{Second section \(first part, first chapter\)}{chapter.2}
\BOOKMARK [0][-]{chapter.3}{The second chapter in the first part}{part.1}
\BOOKMARK [-1][-]{part.2}{II Title of the second part}{}
\BOOKMARK [0][-]{chapter.4}{The first chapter in the second part}{part.2}
\BOOKMARK [0][-]{chapter.5}{The second chapter in the second part}{part.2}
\BOOKMARK [1][-]{section.5.1}{First section \(second part, second chapter\)}{chapter.5}
\BOOKMARK [1][-]{section.5.2}{Second section \(second part, second chapter\)}{chapter.5}
\BOOKMARK [-1][-]{indchp.-1}{An independent chapter}{}
\BOOKMARK [0][-]{chapter.6}{An independent chapter}{indchp.-1}
\BOOKMARK [-1][-]{conclusions.-1}{Conclusions}{}
\BOOKMARK [0][-]{chapter.7}{Conclusions}{conclusions.-1}
\BOOKMARK [-1][-]{firstapp.-1}{The first appendix}{}
\BOOKMARK [0][-]{appendix.A}{The first appendix}{firstapp.-1}
\BOOKMARK [-1][-]{secondapp.-1}{The second appendix}{}
\BOOKMARK [0][-]{appendix.B}{The second appendix}{secondapp.-1}
\BOOKMARK [-1][-]{bibliography.-1}{Bibliography}{}
\BOOKMARK [0][-]{section*.2}{Bibliography}{bibliography.-1}
Edit this file. Comment out or remove lines corresponding to duplicated bookmarks having level 0 (that of chapters). Add the line \let\WriteBookmarks\relax. You should now have:
Code: Select all
\BOOKMARK [-1][-]{toc.-1}{Contents}{}
\BOOKMARK [-1][-]{introduction.-1}{Introduction}{}
%\BOOKMARK [0][-]{chapter.1}{Introduction}{introduction.-1}
\BOOKMARK [-1][-]{part.1}{I Title of the first part}{}
\BOOKMARK [0][-]{chapter.2}{The first chapter in the first part}{part.1}
\BOOKMARK [1][-]{section.2.1}{First section \(first part, first chapter\)}{chapter.2}
\BOOKMARK [1][-]{section.2.2}{Second section \(first part, first chapter\)}{chapter.2}
\BOOKMARK [0][-]{chapter.3}{The second chapter in the first part}{part.1}
\BOOKMARK [-1][-]{part.2}{II Title of the second part}{}
\BOOKMARK [0][-]{chapter.4}{The first chapter in the second part}{part.2}
\BOOKMARK [0][-]{chapter.5}{The second chapter in the second part}{part.2}
\BOOKMARK [1][-]{section.5.1}{First section \(second part, second chapter\)}{chapter.5}
\BOOKMARK [1][-]{section.5.2}{Second section \(second part, second chapter\)}{chapter.5}
\BOOKMARK [-1][-]{indchp.-1}{An independent chapter}{}
%\BOOKMARK [0][-]{chapter.6}{An independent chapter}{indchp.-1}
\BOOKMARK [-1][-]{conclusions.-1}{Conclusions}{}
%\BOOKMARK [0][-]{chapter.7}{Conclusions}{conclusions.-1}
\BOOKMARK [-1][-]{firstapp.-1}{The first appendix}{}
%\BOOKMARK [0][-]{appendix.A}{The first appendix}{firstapp.-1}
\BOOKMARK [-1][-]{secondapp.-1}{The second appendix}{}
%\BOOKMARK [0][-]{appendix.B}{The second appendix}{secondapp.-1}
\BOOKMARK [-1][-]{bibliography.-1}{Bibliography}{}
%\BOOKMARK [0][-]{section*.2}{Bibliography}{bibliography.-1}
\let\WriteBookmarks\relax
It would be nice if someone could suggest how to avoid the last manual step or any other improvement.
P.S. Off topic: Why not adding a link to LaTeX Community in pandammonium LaTeX links?
- Attachments
-
- pru.pdf
- (92.71 KiB) Downloaded 810 times
-
- Posts: 55
- Joined: Thu Oct 30, 2008 4:12 pm
Both parts and chapters in a document?
Re off-topic suggestion: yes, why didn't I do that? It is a useful resource, after all! Consider it done, and I've also added it to my links page on my academic site.
Also, to carry on the off-topic theme, I didn't know about the lipsum package - so I've been further educated!
-
- Posts: 55
- Joined: Thu Oct 30, 2008 4:12 pm
Both parts and chapters in a document?
Code: Select all
\pdfbookmark[0]{Section heading in independent chapter}{independentsection}
\section{Section heading in independent chapter}
I second what you say about the manual step at the end - it's more than a little confusing. I will look into it myself, if I have time.
Thanks again!

Both parts and chapters in a document?
Code: Select all
\documentclass[a4paper,11pt]{book}
\usepackage[colorlinks]{hyperref}
% Loading lipsum to write blind text
\usepackage{lipsum}
% Redefinition of \cleardoublepage. Even pages are left completely blank.
\let\origdoublepage\cleardoublepage
\renewcommand{\cleardoublepage}{%
\clearpage{\pagestyle{empty}\origdoublepage}}
% \ChapterOutsidePart and \ChapterInsidePart: control the bookmark level of each
% sectioning command
\makeatletter
\newcommand{\ChapterOutsidePart}{%
\def\toclevel@chapter{-1}\def\toclevel@section{0}\def\toclevel@subsection{1}}
\newcommand{\ChapterInsidePart}{%
\def\toclevel@chapter{0}\def\toclevel@section{1}\def\toclevel@subsection{2}}
\makeatother
\begin{document}
% ----------
\ChapterOutsidePart
\pdfbookmark{\contentsname}{toc}
\tableofcontents
% ----------
\chapter{Introduction}
\lipsum[1]
% ----------
\ChapterInsidePart
\part{Title of the first part}
\chapter{The first chapter in the first part}
\section{First section (first part, first chapter)}
\lipsum[1-5]
\section{Second section (first part, first chapter)}
\lipsum[1-5]
\chapter{The second chapter in the first part}
\lipsum[1-5]
% ----------
\part{Title of the second part}
\chapter{The first chapter in the second part}
\lipsum[1-5]
\chapter{The second chapter in the second part}
\section{First section (second part, second chapter)}
\lipsum[1-5]
\section{Second section (second part, second chapter)}
\lipsum[1-5]
% ----------
\ChapterOutsidePart
\cleardoublepage\pagestyle{empty}\mbox{}\cleardoublepage
\addtocontents{toc}{\protect\addvspace{2.25em}}
\chapter{An independent chapter}
\section{First section (independent chapter)}
\lipsum[1-5]
\section{Second section (independent chapter)}
\lipsum[1-5]
\chapter{Conclusions}
\lipsum[1-5]
% ----------
\appendix
\chapter{The first appendix}
\lipsum[1-5]
\chapter{The second appendix}
\lipsum[1-5]
% ----------
\cleardoublepage\phantomsection\addcontentsline{toc}{chapter}{\bibname}
% \bibliographystyle{....}
% \bibliography{....}
\begin{thebibliography}{9}
\bibitem{misc} This is just to simulate a bibliography.
\end{thebibliography}
\end{document}