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!
LaTeX forum ⇒ General ⇒ Both parts and chapters in a document?
-
- Posts: 66
- Joined: Tue Oct 07, 2008 9:39 am
Both parts and chapters in a document?
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!
I cannot understand this post.
Re: Both parts and chapters in a document?
Sorry, will try to clarify. What didn't you understand?
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!
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?
Hi,
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:
I haven't the faintest idea how to do this, though. I thought maybe a new environment that simply rehashed the current part code, but with the added flag of whether or not you're inside the scoped part or not, but I'm not sure how to implement this. This is what I have:
but this doesn't compile as it stands; I haven't yet got to grips with assigning variables let alone how to do if statements. I haven't found anything helpful from a search on Google on how to do this, either.
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.
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:
\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}
I haven't the faintest idea how to do this, though. I thought maybe a new environment that simply rehashed the current part code, but with the added flag of whether or not you're inside the scoped part or not, but I'm not sure how to implement this. This is what I have:
%% Make a new scoped part. \let\@oldpart\part \let\@inpart=false \renewenvironment{part}[1] { \let\@inpart=true oldpart{#1} } { \let\@inpart=false }
but this doesn't compile as it stands; I haven't yet got to grips with assigning variables let alone how to do if statements. I haven't found anything helpful from a search on Google on how to do this, either.
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?
Before going to program LaTeX code, you should think first about the visual aspect of the document. The reader knows that a chapter starts because he/she finds many typographical elements in the document indicating that: a big title in a new page, many counters are reset, headings,... The reader knows that the chapter ends when he/she finds a new chapter, the start of a higher level unit (part) or... the end of the document. There is no specific mark that indicates "chapter end". The same quotation can be done for parts. In the standard book class, one sees the start of a part when one finds the isolated page issued by the \part command.
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.
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.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
-
- Posts: 55
- Joined: Thu Oct 30, 2008 4:12 pm
Both parts and chapters in a document?
Thanks for your reply, Juanjo. You raise some good points.
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.
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:
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:
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
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.
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:
+ 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
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
Both parts and chapters in a document?
EDITED: Skip this post. See below a right approach
I can propose a semi-automatic way to get your goals. Consider the following code:
After two LaTeX runs, you get a complete document where the second part and the independent chapter are separated by a vertical space, in the table of contents, and a blank sheet, in the main text. However, bookmarks of chapters outside parts are duplicated: there are the bookmark generated by \pdfbookmark (at the part level) and the default bookmark generated by chapter (I don't know how to deactivate it). Once you have finished writing your document (or at least its scheleton), open the "out" file (from foo.tex, one gets an auxiliary file foo.out). You'll see something like
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:
The last line prevents LaTeX from rewriting the out file. A new LaTeX run yields the correct bookmarks. I attach the pdf file I get.
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?
I can propose a semi-automatic way to get your goals. Consider the following code:
\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}
After two LaTeX runs, you get a complete document where the second part and the independent chapter are separated by a vertical space, in the table of contents, and a blank sheet, in the main text. However, bookmarks of chapters outside parts are duplicated: there are the bookmark generated by \pdfbookmark (at the part level) and the default bookmark generated by chapter (I don't know how to deactivate it). Once you have finished writing your document (or at least its scheleton), open the "out" file (from foo.tex, one gets an auxiliary file foo.out). You'll see something like
\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:
\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
The last line prevents LaTeX from rewriting the out file. A new LaTeX run yields the correct bookmarks. I attach the pdf file I get.
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 686 times
Last edited by Juanjo on Sat Nov 01, 2008 2:04 am, edited 1 time in total.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
-
- Posts: 55
- Joined: Thu Oct 30, 2008 4:12 pm
Both parts and chapters in a document?
Juanjo, that's brilliant! Thank you so much - it must have taken you quite some time to work that out. I appreciate every second of it! I'll let you know how I get on.
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!
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?
Ok, I've given it a whirl. An unexpected side effect is that sections in the independent chapters aren't bookmarked properly in the PDF (it seems I missed out sections here in the original specification). The solution to this is to precede the \section command with something similar to what precedes the \chapter command:
I guess I'll have to do this for every subsection, too; I think a macro or two might be in order.
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!
\pdfbookmark[0]{Section heading in independent chapter}{independentsection} \section{Section heading in independent chapter}
I guess I'll have to do this for every subsection, too; I think a macro or two might be in order.
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?
Good news. I think I got it. Fully automatic. Try this:
\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}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Who is online
Users browsing this forum: No registered users and 4 guests