One can have independent TOCs
without using any package, we need just to add in the main file
\tableofcontents
\let\tableofcontents\relax
With 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
\documentclass{book}
\usepackage{subfiles}
\usepackage{lipsum}
\usepackage{tableof}
\AtBeginDocument{\tofOpenTocFileForWrite}% see tableof's doc
\begin{document}
\tableof{}% replaces book class \tableofcontents, which one
% can not use after \tofOpenTocFileForWrite
\chapter{Foo}
\section{Bar}
\lipsum[1-2]
\section{Baz}
\lipsum[1-2]
\subfile{myfile1}
\subfile{myfile2}
\subfile{myfile3}
\end{document}
myfile1.tex
% main file is called myfile.tex
% this is myfile1.tex
\documentclass[myfile]{subfiles}
\begin{document}
\chapter{Foo1}
\tableof{myfile1}
\toftagstart{myfile1}
\section{Bar1}
\lipsum[1-2]
\section{Baz1}
\lipsum[3-4]
\toftagstop{myfile1}
\end{document}
myfile2.tex
% main file is called myfile.tex
% this is myfile2.tex
\documentclass[myfile]{subfiles}
\begin{document}
\chapter{Foo2}
\tableof{myfile2}
\toftagstart{myfile2}
\section{Bar2}
\lipsum[5-6]
\section{Baz2}
\lipsum[7-8]
\toftagstop{myfile2}
\end{document}
myfile3.tex
% main file is called myfile.tex
% this is myfile3.tex
\documentclass[myfile]{subfiles}
\begin{document}
\chapter{Foo3}
\tableof{myfile3}
\toftagstart{myfile3}
\section{Bar3}
\lipsum[9-10]
\section{Baz3}
\lipsum[10-11]
\toftagstop{myfile3}
\end{document}
2- titletoc
main file myfile.tex
\documentclass{book}
\usepackage{subfiles}
\usepackage{lipsum}
%------
\usepackage{titletoc}
\startcontents
\begin{document}
%------
\printcontents{}{-1}{% parts are add to toc
\setcounter{tocdepth}{2}%
\chapter*{\contentsname}% or section ...
}
%\renewcommand{\printcontents}[4][default]{} %if you don't want partial tocs
%------
\part{one}
\chapter{Foo}
\section{Bar}
\lipsum[1-2]
\section{Baz}
\lipsum[1-2]
\subfile{myfile1}
\subfile{myfile2}
\subfile{myfile3}
\end{document}
myfile1.tex
\documentclass[myfile]{subfiles}
\begin{document}
%------
\printcontents{}{-1}{%
\setcounter{tocdepth}{2}%
\chapter*{\contentsname}% or section ...
}
%------
\chapter{Foo1}
\section{Bar1}
\lipsum[1-2]
\section{Baz1}
\lipsum[3-4]
\end{document}
myfile2.tex
\documentclass[myfile]{subfiles}
\begin{document}
%------
\printcontents{}{-1}{%
\setcounter{tocdepth}{2}%
\chapter*{\contentsname}% or section ...
}
%------
\chapter{Foo2}
\section{Bar2}
\lipsum[5-6]
\section{Baz2}
\lipsum[7-8]
\end{document}
myfile3.tex
\documentclass[myfile]{subfiles}
\begin{document}
%------
\printcontents{}{-1}{%
\setcounter{tocdepth}{2}%
\chapter*{\contentsname}% or section ...
}
%------
\chapter{Foo3}
\section{Bar3}
\lipsum[9-10]
\section{Baz3}
\lipsum[10-11]
\end{document}
3- minitoc we add in the main file
\usepackage{minitoc}
\dominitoc
\begin{document}
\tableofcontents
\let\tableofcontents\relax
and in subfiles we add just \tableofcontents
.
Further reading
This is a problem with an outdated biblatex
version on Overleaf. Currently Overleaf reports biblatex 2016/05/14 v3.4
in its logs.
The Bath bibliography files for biblatex
from http://www.bath.ac.uk/library/infoskills/referencing-plagiarism/, however use recent date commands that have only been introduced in version 3.5.
Until Overleaf update their system to use a biblatex
version newer than 3.5, you can add the following lines before loading biblatex
\newcommand*{\mkdaterangetrunc}{}
\newcommand*{\mkdaterangetruncextra}{}
\newcommand*{\bibdatetimesep}{}
\newcommand*{\bibtimesep}{}
\newcommand*{\printtime}{}
As in
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\newcommand*{\mkdaterangetrunc}{}
\newcommand*{\mkdaterangetruncextra}{}
\newcommand*{\bibdatetimesep}{}
\newcommand*{\bibtimesep}{}
\newcommand*{\printtime}{}
\usepackage[backend=biber, style=bath]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\cite{sigfridsson,geer,worman}
\printbibliography
\end{document}
On Overleaf: https://www.overleaf.com/read/zcmphqjfgsgv
Note that you will have to live with a few rough edges and possible deviations from the extended output, because biblatex
3.4 does not support all the commands used by bath.bbx
, bath.cbx
.
Best Answer
There are several ways of handling multiple documents
for example if you have an
article
classdoc1
and amemoir
doc2
You can have a
main.tex
That includes
doc1
and
doc2
If you hit recompile on the main document it will run pdflatex on all three.
See in action:
https://www.overleaf.com/read/jkkbgwfbkpvn#01e47c