I was using subfiles
to write a rather extensive portfolio consisting of eight chapters, an appendix with additional literature and a dossier containing lots of external PDF's. All of these were created as subfiles to the main file. I currently am reworking that portfolio into a book using the same setup. Both portfolio and book are based on The Orange Book
by Legrand. a public template that can be found on Overleaf
among others.
The Orange Book
uses a structure.tex
file that defines a lot of the layout of the book to be created. It essentially is the preamble
of the main file. That file is loaded into the main file using the command \input{structure.tex}
. Since the bibliographic environment
is also included in the structure.tex
file the first few lines of the main document look like this:
\documentclass[11pt,fleqn]{book}
\input{structure.tex} % Insert the commands.tex file which contains the majority of the structure behind the template
\addbibresource{hb_specialist_new.bib} % BiblateX bibliography file
\input{appendix/woordenlijst}
\usepackage{subfiles}
As you can see I load three separate files into my main tex file. The last file woordenlijst
contains the glossery
entries used in all chapters in this book. The bibliography
source file is loaded the usual way. Both structure.tex
and hb_specialist_new.bib
files are located in the same directory as the main.tex
file. The woordenlijst.tex
file is located in a subfolder called appendix.
The the chapters are in subfolders to the main folder and contain their figures in subfolders to their folder. So two folders deep relative to the main folder. The folder structure is in short like this:
Parent folder containing the `main.tex`, `structure.tex` and `hb_specialist_new.bib` files
|_ figures folder that contain images for chapter heading and main file
|_ appendox folder containing `woordenlijst.tex`
|_ domein1 folder containing `chapter_one.tex`
|_ figures1 folder containing the figures used in chapter one
|_ domein2 folder containing `chapter_two.tex`
|_ figures2 folder containing the figures used in chapter two
|_ etc.
The main.tex
file loads the chapter files using the line (here given for the first two chapters):
%----------------------------------------------------------------------------------------
% CHAPTER 1
%----------------------------------------------------------------------------------------
\chapterimage{lancaster1.jpg} % Chapter heading image
\subfile{domein1/zien_weten}
%----------------------------------------------------------------------------------------
% CHAPTER 2
%----------------------------------------------------------------------------------------
\subfile{domein2/zien_begrijp}
Since the Orange Book
template uses pictures in the chapter heading that file is included in this example to show how a relative path is used in the chapter file. That image file has to be included in the heading of the chapter files, when you use the package subfiles
. When you use the package import
you can remove that image loading line.
\documentclass[../hbspec_main_mhc]{subfiles}
\chapterimage{../figures/lancaster1.jpg} % Chapter heading image
\begin{document}
\chapter{Weten en begrijpen}\index{Weten en begrijpen}
\label{chp:weten}
As you can see, the path to the image heading is given by its relative path.
Inside the chapter file graphics are loaded using the line:
{\includegraphics[width=0.95\linewidth]{figures1/Emotional-Intelligence-Competencies.png}}
Remember that the folder figures1 is a subfolder of the domein1 (chapter one) folder. On compilation these images are loaded from their respective paths.
To answer your questions in summarise:
- It doesn't matter how you include another file into a subfile as long as you maintain path integrity throughout your folders and subfolders.
- You don't need to change the
\graphicspath
when you use the relative path structure inside \includegraphics
. But if you want to, the both answers in the question you referred to, are very useful.
- As long as you load the
bibliography.bib
file in the preamble of the main file, all subfiles have access to that file and the bibliography will be created for all subfiles in the main file.
Note I currently use the package import
inside the main.tex file. Switching from subfiles
to import
is rather easy to achieve changing the lines loading the chapter files. The main file now contains these lines to load the first chapter:
%----------------------------------------------------------------------------------------
% CHAPTER 1
%----------------------------------------------------------------------------------------
\chapterimage{lancaster1.jpg} % Chapter heading image
\subimport{domein1}{zien_weten}
In the heading of the first chapter the preamble lines aren't required anymore, so the first line in the chapter file reads:
\chapter{Weten en begrijpen}\index{Weten en begrijpen}
\label{chp:weten}