1

I'm using the Subfiles package to compile a relatively large document in smaller steps. Each subfile is actually a chapter of the document. I would like to have a ToC in each chapter (in addition to the general ToC). I've used the lines

% !TEX encoding = IsoLatin9
\documentclass[./main.tex]{subfiles}
\begin{document}
\tableofcontents
\let\tableofcontents\relax
\chapter{My first chapter}
...

in a chapter, and I obtain indeed a ToC for the chapter, but it is placed after a header "Contents" and before the title of the chapter. Moreover, the ("Contents" + ToC) is placed in a different page with respect to the title of the chapter. I would like to obtain:

  • Title of the chapter ("My first chapter" in the above example)
  • ToC of the chapter (if possible, without the heading "Contents")
  • beginning of the text of the chapter in this order and all on the same page. Is that possible?
Simon Dispa
  • 39,141
ariel67
  • 13
  • Related (if not duplicated) https://tex.stackexchange.com/questions/284773/toc-and-subfiles-which-toc-pkg-for-unique-toc-compilation-with-each-subfile – Luis Turcio Apr 30 '21 at 20:46

1 Answers1

3

It is possible to customize the local TOCs of the subfiles as required using the package etoc

Assuming that you have the main book file in the directory BOOK and the chapters in a sub-directory chapters

t2

you will get

Full TOC of the book

mt

Chapter 1

c1

Chapter 2

c2

This is full_book-2021.tex

 %% full_book-2021.tex in its own directory BOOK

\documentclass[11pt,a4paper,twoside]{book}

\usepackage{etoc} % for local TOC

\usepackage{kantlipsum} % dummy text \usepackage{subfiles}

\begin{document}

\tableofcontents
\etocsettocstyle{}{} % now only local tocs

\subfile{./chapters/chapter1}  % chapter 1  file in  BOOK/chapters/ subdirectory

\subfile{./chapters/chapter2}  % chapter 2  file in  BOOK/chapters/ subdirectory

\end{document}

These are the chapter subfiles

%% chapter1.tex in /chapters subdirectory

\documentclass[../full-book-2021.tex]{subfiles}

\begin{document}

\chapter{My First Chapter}

\etocsettocstyle{% before code \noindent\rule{\linewidth}{.4pt} \vspace{-4\baselineskip} \section{} } {% after code \noindent\rule{\linewidth}{.4pt} \vspace*{2\baselineskip} }

\localtableofcontents

  1. \kant[3-5]

\section{Sec1Ch1 Blue}

  1. \kant[4-9]

\section{Sec2Ch1 Green}

  1. \kant[5-11]

\end{document}

and

%% chapter2.tex in /chapters subdirectory

\documentclass[../full-book-2021.tex]{subfiles}

\begin{document}

\etocsettocstyle{% before code
    \noindent\rule{\linewidth}{.4pt}
    \vspace*{-4\baselineskip}
    \section*{}
}
{% after code
    \noindent\rule{\linewidth}{.4pt}
    \vspace*{2\baselineskip}
}


\chapter{My Second Chapter}
\localtableofcontents

6. \kant[6-12]

\section{Sec1Ch2 Red}

7. \kant[7-14]

\section{Sec2Ch2 Yellow}

8. \kant[8-16]  

\end{document}

Simon Dispa
  • 39,141