7

I need to write a very large document, and I would like use etoc to create local tocs. (the minitoc is incompatible in my doc;)

how i can create a local list of table and figures?

why nameref gets wrong reference in this mwe?

when I use a unnumbered part (\part*{Appendix}) the command \localtableofcontents show a empty table and the previous table of contents list the appendix content, how can I correct it?

\documentclass[]{report}
\usepackage{lipsum}
\usepackage{etoc}
\usepackage{titlesec}
\usepackage{nameref}

\titleclass{\part}{top} % make part like a chapter
\titleformat{\part}
[display]
{\centering\normalfont\Huge\bfseries}
{\titlerule[2pt]\vspace{3pt}\titlerule[1pt]\vspace{3pt}\MakeUppercase{\partname} \thepart}
{0pt}
{\titlerule[1pt]\vspace{1pc}\huge\MakeUppercase}
%
\titlespacing*{\part}{0pt}{0pt}{20pt}

\begin{document}
\listoffigures\newpage
\listoftables\newpage
\tableofcontents\newpage


\etocmulticolstyle{\noindent\bfseries\footnotesize
\leaders\hrule height1pt\hfill
\MakeUppercase{Contents}}
\etocsettocdepth{1}

\part{FIRST PART}\label{part:one}
%how to make a localtableofcontents of figures and tables?
\localtableofcontents
\chapter{INTRODUCTION} \lipsum{1}
\chapter{METHODOLOGY} \lipsum{1}
\chapter{CONCLUSION} \lipsum{1}


\part{SECOND PART}
%how to make a localtableofcontents of figures and tables?
\localtableofcontents
\chapter{INTRODUCTION} 
Like in \nameref{part:one}.% why nameref gets the wrong reference? 
\lipsum{1}

\chapter{METHODOLOGY} \lipsum{1}
\chapter{CONCLUSION} \lipsum{1}

\appendix
\part{APPENDIX}
%how to make a localtableofcontents of appendix
\localtableofcontents
\chapter{document a}
\chapter{document B}
\end{document}

thank u : )

  • are you open to a solution using titletoc, which is a sibbling to titlesec? – cmhughes Mar 04 '14 at 03:52
  • i try to use \startcontents[parts] \printcontents[parts]{} before \part and in the end \stopcontents[parts], but it doesn't worked. well, i'm open to a solution using titletoc and titlesec. :) – leonardo cesar Mar 04 '14 at 03:53

2 Answers2

6

(*update: etoc 1.07k incorporates compatibility with tocloft; see bottom of answer *)

The etoc package at the time of writing does not hook into list of figures or list of tables, but only handles tables of contents.

With an unnumbered Appendix part, the usual addcontentsline should be used

\part*{APPENDIX}
\addcontentsline {toc}{part}{APPENDIX}

Note that without it, even the main \tableofcontents without etoc would look strange anyhow, as the chapters of the appendix would appear right in the continuation of the previous ones (albeit with Alpha numbering).

Nevertheless it is also possible to obtain a local table of contents in the APPENDIX part, without having an APPENDIX entry in the main table of contents.

At the main table of contents command:

\etocsetlevel{appendixplaceholder}{6}
\tableofcontents
\etocsetlevel{appendixplaceholder}{-1}

And:

\part*{APPENDIX}
\etoctoccontentsline*{appendixplaceholder}{APPENDIX}{-1}
% the above works with or without hyperref. If the document does not use
% hyperref, then
% \addcontentsline{toc}{appendixplaceholder}{APPENDIX}
% is an alternative
\localtableofcontents

With this:

  1. the local table of contents is created as desired
  2. there is no APPENDIX entry in the main table of contents
  3. there is a correct APPENDIX bookmark in the pdf output.

However 3. would not be true with the set-up of your mwe due to some interaction between the \titleclass and \titleformat commands of titlesec and hyperref. There is something dysfunctional there, I did not investigate further.

And for nameref not getting the correct reference, this is unrelated to etoc, as one can see by not loading it and commenting out all relevant portions.

This is a titlesec issue which is addressed in cmhughes 's answer.


etoc--tocloft compatibility:

The tocloft package was mentioned in a comment. Although the etoc manual always said that one could use tocloft to customize the toc lines when etoc was left in compatibility mode, it forgot to say that the user had to do \let\tableofcontents\etoctableofcontents to counteract the overwriting by tocloft of \tableofcontents done at \begin{document}.

Anyway, release 1.07k of etoc provides transparently the compatibility with tocloft, which should be loaded before etoc (else a warning is issued as tocloft will be forced into its "titles" mode). Then, in compatibility mode, tocloft customization for the toc lines, and for the toc title, will be obeyed faithfully by etoc. The user may still benefit from other aspects of etoc such as its \localtableofcontents (also obeying the tocloft customization current at that point of the document), and its \label+\ref mechanism. And it is possible to use tocloft for one TOC and etoc for another one. Besides, naturally, tocloft dealings with list of figures and list of tables will be completely untouched by etoc.

  • it works perfectly in mwe. sadly tocloft and etoc are incompatible. – leonardo cesar Mar 04 '14 at 14:25
  • 1
    @user42634 I am glad stuff is working, but I am not sure I know what you are referring too: perhaps the \addcontentsline thing? another thing when you say tocloft and etoc are incompatible, your mwe uses titlesec not tocloft, perhaps you mean I would like to use tocloft+etoc but I can't. Try the following: immediately after \begin{document} insert \let\tableofcontents\etoctableofcontents. Then the main toc will be governed by etoc but all customizing done via tocloft to the way parts and chapters are to be printed will be obeyed. –  Mar 04 '14 at 15:04
  • 1
    thanks for the tip. you're right, i was trying to say "I would like to use tocloft+etoc but I can't". Now with the command \let\tableofcontents\etoctableofcontents, i did not miss the customization done with the package tocloft in TOC. awesome! – leonardo cesar Mar 04 '14 at 15:50
  • i used the command \etocmulticolstyle[1]{\centering\normalsize\bfseries\MakeUppercase{Table of Contents}} to customize the TOC title. how to adjust the vertical align? – leonardo cesar Mar 05 '14 at 03:24
  • try with \renewcommand\etocinnertopsep{5ex} (adjust 5ex to the desired value). –  Mar 05 '14 at 15:49
  • @user42634 release 1.07k of etoc will be compatible with tocloft out of the box. No need for the \etoctableofcontents thing, and the tocloft customizing will be obeyed for the title too, not only the contents. –  Mar 08 '14 at 16:54
  • very thanks man! now i'm trying to do the lof and the lot with etoc! but it seems a bit complicated :) – leonardo cesar Mar 08 '14 at 18:20
  • @user42634 etoc is ignorant of the .lof and .lot files, it is possible to use etoc to typeset a List of Figures and a List of Tables using suitable addcontentsline and \etocsetlevel, [this isn't even properly explained in the etoc manual] but the more reasonable is definitely to wait two or three days until etoc 1.07k reaches your installation, then you can just employ tocloft to customize LOF and LOT in the usual way. –  Mar 08 '14 at 18:50
  • in my tex files main LOF and LOT are already customized... but i want the local lof and lot in the same style of local toc. – leonardo cesar Mar 08 '14 at 19:15
  • you can achieve that with suitable \etocsetlevel magic, if each table or figure does a suitable \addcontentsline {toc} or perhaps \etoctoccontentsline to avoir additional hyperref bookmark. –  Mar 08 '14 at 19:28
5

Here's a solution using the titletoc package. The important parts are:

% local tableofcontents
\section*{Local toc}
\startcontents[mytoc]
\printcontents[mytoc]{}{0}{}

% local listoffigures
\section*{Local lof}
\startlist[mylof]{lof}
\printlist[mylof]{lof}{0}{}

% local listoftables
\section*{Local lot}
\startlist[mylot]{lot}
\printlist[mylot]{lot}{0}{}

... <part content goes here>
... <part content goes here>
... <part content goes here>

% stop local toc, lof, lot
\stopcontents[mytoc]
\stoplist[mylof]{lof}
\stoplist[mylot]{lot}

This creates partial toc, lof, and lot.

Here's a complete MWE that demonstrates the idea- you'll need to run it twice, or else run it with arara which will compile it twice for you.

% arara: pdflatex
% arara: pdflatex
\documentclass{report}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{hyperref}

\titleclass{\part}{top} % make part like a chapter
\titleformat{\part}
[display]
{\centering\normalfont\Huge\bfseries}
{\titlerule[2pt]\vspace{3pt}\titlerule[1pt]\vspace{3pt}\MakeUppercase{\partname} \thepart}
{0pt}
{\titlerule[1pt]\vspace{1pc}\huge\MakeUppercase}
%
\titlespacing*{\part}{0pt}{0pt}{20pt}

\makeatletter
\let\titlesec@part\part
\renewcommand{\part}{\@ifstar\part@star\part@nostar}
\def\part@star#1{\NR@gettitle{#1}\titlesec@part*{#1}}
\def\part@nostar{\@ifnextchar[\part@nostar@opt\part@nostar@nopt}
\def\part@nostar@nopt#1{\NR@gettitle{#1}\titlesec@part{#1}}
\def\part@nostar@opt[#1]#2{\NR@gettitle{#2}\titlesec@part[#1]{#2}}
\makeatother


\begin{document}
\listoffigures
\listoftables
\tableofcontents



\part{FIRST PART}\label{part:one}
% local tableofcontents
% local tableofcontents
% local tableofcontents
\section*{Local toc}
\startcontents[mytoc]
\printcontents[mytoc]{}{0}{}

% local listoffigures
% local listoffigures
% local listoffigures
\section*{Local lof}
\startlist[mylof]{lof}
\printlist[mylof]{lof}{0}{}

% local listoftables
% local listoftables
% local listoftables
\section*{Local lot}
\startlist[mylot]{lot}
\printlist[mylot]{lot}{0}{}
\chapter{INTRODUCTION} \lipsum{1}
\chapter{METHODOLOGY} \lipsum{1}
\chapter{CONCLUSION} \lipsum{1}
\newcount\tmp
\tmp=0
\loop
\advance\tmp by 1
\begin{table}[!htb]\caption{table in part I}\end{table}
\begin{figure}[!htb]\caption{figure in part I}\end{figure}
\ifnum\tmp<5 \repeat

% stop local toc, lof, lot
\stopcontents[mytoc]
\stoplist[mylof]{lof}
\stoplist[mylot]{lot}

\part{SECOND PART}
% local tableofcontents
% local tableofcontents
% local tableofcontents
\section*{Local toc}
\startcontents[mytoc]
\printcontents[mytoc]{}{0}{}

% local listoffigures
% local listoffigures
% local listoffigures
\section*{Local lof}
\startlist[mylof]{lof}
\printlist[mylof]{lof}{0}{}

% local listoftables
% local listoftables
% local listoftables
\section*{Local lot}
\startlist[mylot]{lot}
\printlist[mylot]{lot}{0}{}
\chapter{INTRODUCTION} 
Like in \nameref{part:one}.% why nameref gets the wrong reference? 
\lipsum{1}

\chapter{METHODOLOGY} \lipsum{1}
\chapter{CONCLUSION} \lipsum{1}
\tmp=0
\loop
\advance\tmp by 1
\begin{table}[!htb]\caption{table in part II}\end{table}
\begin{figure}[!htb]\caption{figure in part II}\end{figure}
\ifnum\tmp<5 \repeat

% stop local toc, lof, lot
\stopcontents[mytoc]
\stoplist[mylof]{lof}
\stoplist[mylot]{lot}

\appendix
\part{APPENDIX}
% local tableofcontents
% local tableofcontents
% local tableofcontents
\section*{Local toc}
\startcontents[mytoc]
\printcontents[mytoc]{}{0}{}

% local listoffigures
% local listoffigures
% local listoffigures
\section*{Local lof}
\startlist[mylof]{lof}
\printlist[mylof]{lof}{0}{}

% local listoftables
% local listoftables
% local listoftables
\section*{Local lot}
\startlist[mylot]{lot}
\printlist[mylot]{lot}{0}{}

\chapter{document a}
\chapter{document B}
\tmp=0
\loop
\advance\tmp by 1
\begin{table}[!htb]\caption{Table}\end{table}
\begin{figure}[!htb]\caption{Figure}\end{figure}
\ifnum\tmp<5 \repeat

% stop local toc, lof, lot
\stopcontents[mytoc]
\stoplist[mylof]{lof}
\stoplist[mylot]{lot}
\end{document}

I have also pasted some code from Problems with part-labels using titlesec to fix the nameref for \part.

cmhughes
  • 100,947
  • very good solution!! thanks. just one little thing, i ran your mwe and the problem on this line continue:

    \chapter{INTRODUCTION} Like in \nameref{part:one}.% why nameref gets the wrong reference? \lipsum{1}

    why?

    – leonardo cesar Mar 04 '14 at 04:41
  • 1
    @user42634 glad you like it- see the update for a fix for nameref :) – cmhughes Mar 04 '14 at 05:22
  • this mwe works fine, and i understood de code. but there is a conflict when I paste this code in my tex files. do you know some incompatibility between titletoc and another package? when i compile, the console show: ! Paragraph ended before @writefile was complete. – leonardo cesar Mar 04 '14 at 05:54
  • @user42634 it's going to be hard to know the problem without a complete MWE; it is very possible that titletoc is not compatible with another tableofcontents package- are you sure you need more than one package to customize your toc? – cmhughes Mar 04 '14 at 17:03
  • i need to customize the tocloft title's... I need to write their titles in uppercase and adjust the horizontal and vertical align. i'm using titlesec, titletoc,tocloft – leonardo cesar Mar 05 '14 at 03:23
  • @user42634 your MWE doesn't contain tocloft; it might be worth opening another question given that your current question (as you've written it) has been addressed – cmhughes Mar 05 '14 at 04:56