The Subfiles package makes compiling individual parts of a LaTex document convenient. The package works so that each subfile inherits the master preamble main.tex
and the user is able to compile individual files separately. The package itself has no mention about TOCs for separate parts that are compiled.
Independent TOCs with Subfiles pkg must have some convenient solution. The options contain minitoc, shorttoc and titletoc, more in comment.
Which TOC package to use with Subfiles pkg to outline the document more conveniently consisting of multiple files?
Best Answer
One can have
independent TOCs
without using any package, we need just to add in the main fileWith packages
Here are examples of how one can use packages
1- tableof. (edited) :
With the two lines approach above, one can compile separately each included sub-file, and it will have its own TOC. And the main file will have a global TOC. If that's what is wanted no need to read further.
If however one wants the included files to have their own TOC also in the main file, one can use tableof in the following, somewhat convoluted way. The constraints are:
tableof
does not modify the book class default\tableofcontents
, which, when used once displays the TOC but also erases the.toc
file until the end of the document, so one can not use it twice.tableof
has its own additional commands such as\tableoftaggedcontents
or\tableof
. By themselves these commands display a TOC but do not open a.toc
file for write. One must use, if no\tableofcontents
command has been used, the package\tofOpenTocFileForWrite
.If one uses
\tofOpenTocFileForWrite
, after it\tableofcontents
displays an empty TOC, one must use the package commands such as\tableoftaggedcontents
or\tableof
rather.The latter commands do not print a heading, this can be done by the user with a
\section*
or a\chapter*
etc...If one insists despite the above constraints to use
tableof
package, here is how to do it. I have made it so that the included files are supposed to have only one chapter, and their TOC is for the contents of this chapter.To test this and other examples make sure to start from a clean state with no auxiliary files. And as usual with TOCs, at least two compilations are needed, be it for the main file or the subfiles, if compiled individually. Naturally the numbering of sections and chapters will not be the same in the main file as it is in individually compiled subfiles.
main file myfile.tex
myfile1.tex
myfile2.tex
myfile3.tex
2- titletoc
main file myfile.tex
myfile1.tex
myfile2.tex
myfile3.tex
3- minitoc we add in the main file
and in subfiles we add just
\tableofcontents
.Further reading
Documentation for tableof
Minitoc and its README