2

How can I get all the name of my chapter without using a ToC please ?

\documentclass{memoir}

\begin{document}


\part{part ONE}

%Display all the chapter name of Part ONE

\chapter{One}
\chapter {Two}

\end{document}
  • How can we get a MWE by you? ;-) – user31729 Oct 8 '14 at 20:51
  • How do you want to "display all the chapter names"? A ToC is the ideal way, or perhaps something like a mini-ToC. – Werner Oct 8 '14 at 20:56
  • Minitoc, shorttoc, titletoc are not working with my memoir document :) and I have already a TOC at the beginning of my doc... – Terriguest Oct 8 '14 at 20:59
  • Maybe if you write a code in your preamble where you do the same task that those packages you don't want to use ;-) – Aradnix Oct 8 '14 at 21:10
  • Yes, a kind of script – Terriguest Oct 8 '14 at 21:29
4

Is there any reason you can't use etoc? You at least don't mention it and it is designed to respect memoir's configuration. (For example, it ensures that ToCs are added to the ToC if memoir is loaded.)

\documentclass{memoir}
\usepackage{etoc}
\begin{document}
  \tableofcontents

  \part{part ONE}
  \localtableofcontents

  \chapter{One}
  \chapter {Two}

  \part{part two}
  \localtableofcontents

  \chapter{three}
  \chapter{four}

\end{document}

This will produce a main ToC:

main ToC

a ToC for part 1:

part 1 ToC

and a ToC for part 2:

part 2 ToC

EDIT

Just to respond to your query regarding different configurations for the main and local ToCs, etoc allows you to do entirely ridiculous things, even. If you want, you can use a different layout for every ToC in your document, typeset the same ToC in different ways, and print particular elements of your ToC in bright orange italics against a green background with a blue border. This example just shows a couple of different local ToCs using two of etoc's default formats: ruled and framed.

\documentclass{memoir}
\usepackage{etoc}
\begin{document}
  \tableofcontents

  \part{part ONE}
  \etoclocalruled[1]{Local Contents Rules!}

  \chapter{One}
  \chapter {Two}

  \part{part two}
  \etoclocalframed[2]{Local Contents Framed}

  \chapter{three}
  \chapter{four}
  \chapter{five}
  \chapter{six}

  \part{part three}
  \localtableofcontents
  \chapter{seven}
  \chapter{eight}

\end{document}

This produces the standard main ToC:

main toc in default style

a ToC with a rule for part 1:

ruled toc

a framed ToC for part 2:

framed toc

and a local ToC in the default style for part 3:

local default toc

Obviously, it would be crazy to change styles for every ToC. However, you can easily change the global style after issuing the main \tableofcontents. (You can also restore the default later if you prefer to put your main ToC later for some reason.) The package manual should give you a sense of the possibilities.

  • Thanks cfr, it is working !!! However, is it possible to modify the style of my etoc's table of content without affecting the true toc ? – Terriguest Oct 9 '14 at 7:19
  • @Terriguest That code doesn't modify the style of the main ToC as far as I can tell. At least, if I remove etoc and the local ToCs, the style of the main ToC looks the same to me. Could you explain what difference you see? – cfr Oct 9 '14 at 10:40
  • There is no difference. But I would like two difference styles for my two toc. – Terriguest Oct 9 '14 at 15:47
  • @Terriguest Oh. Yes. etoc certainly lets you do that. You can have a different style for every ToC if you wish to. The documentation has lots of examples. – cfr Oct 9 '14 at 16:41
  • @Terriguest See updated question. I have no idea what you want to do so I've just demonstrated that you can configure the format of the ToCs independently. – cfr Oct 10 '14 at 1:31
3

It's possible to reuse the ToC and extract only the contents for every \part. This is discussed via example in the memoir basic user manual (sniplet C.7 (USING CLASS TOOLS TO MAKE A CHAPTER TOC), p 405). The following discussion is taken from the manual with some modifications (chapter > part) to match your requirement...


By using a few hooks, we will be able to create a simple part ToC. First a few notes:

  1. In this class, the ToC data can be reused, thus we can load the ToC data as many times as we would like.

  2. Data in the ToC is stored as arguments to the \contentsline macro, say (see also Figure 9.1 on page 143):

    \contentsline{part}{\partnumberline {I}Test}{3}
    

    where the first argument determines which macro is used to process the data. Each of these macros look at the value of the tocdepth counter to know whether to typeset or not.

  3. Using some hooks we can insert local changes to tocdepth in order to only typeset the sections from the current part.

The idea is to be able to add hooks at key points in the ToC data, and then use these hooks to enable and disable typesetting.

We will need to add hooks just after a part line (like the one above), and we will need to be able to insert hooks just before items that mark the end of a part, that is the next \part, \book, plus a macro like \appendixpage which also write to the ToC.

First we define hooks that add hooks into the ToC. We use a counter to make each start and end hook unique. We add end markers above the ToC entries for \part and \book.

\newcounter{tocmarker}
\renewcommand\mempreaddparttotochook {\cftinserthook{toc}{end-\thetocmarker}}
\renewcommand\mempreaddbooktotochook {\cftinserthook{toc}{end-\thetocmarker}}
\renewcommand\mempreaddapppagetotochook{\cftinserthook{toc}{end-\thetocmarker}}
% start marker
\renewcommand\mempostaddparttotochook{%
  \stepcounter{tocmarker}\cftinserthook{toc}{start-\thetocmarker}}
\let\normalchangetocdepth\changetocdepth % for later

The hooks inserted into the ToC file, does nothing by default. You will notice that the line above will now look like:

\cftinsert {end-0}
\contentsline{part}{\partnumberline {I}Test}{3}
\cftinsert {start-1}
...
\cftinsert {end-1}
\contentsline{part}{\partnumberline {II}Test}{5}

Thus to get a part ToC command we need to make sure that (1) all entries are disabled, (2) at start-1 we re-enable ToC entries, and (3) at end-1 disable ToC entries again. Here is the rest of the code, explained via comments.

\makeatletter
\newcommand\parttoc{
  % make changes local, remember counters a global
  \begingroup
    % store current value, to be restored later
    \setcounter{@memmarkcntra}{\value{tocdepth}}
    % when ever \settocdepth is used, it adds the new value to the
    % ToC data. This cause problems when we want to disable all
    % entries. Luckily the data is added via a special macro, we
    % redefine it, remember we stored the original value earlier.
    \let\changetocdepth\@gobble
    % disable all entries (using our copy from above)
    \normalchangetocdepth{-10}
    % enable ToC data within our block, we go as far as subsubsection
    \cftinsertcode{start-\thetocmarker}{\normalchangetocdepth{3}}
    % when the block is done, disable the remaining
    \cftinsertcode{end-\thetocmarker}{\normalchangetocdepth{-10}}
    % remove the spacing above the ToC title
    \let\tocheadstart\relax
    % remove the ToC title itself
    \let\printtoctitle\@gobble
    % remove space below title
    \let\aftertoctitle\relax
    % reformat ToC entries:
    \setlength{\cftchapterindent}{0pt}
    \setlength{\cftsectionindent}{\cftchapternumwidth}
    \setlength{\cftsubsectionindent}{\cftsectionnumwidth}
    \setlength{\cftsubsubsectionindent}{\cftsubsectionindent}
    \addtolength{\cftsubsubsectionindent}{\cftsubsectionnumwidth}
    \renewcommand\cftchapterfont{\small}
    \renewcommand\cftsectionfont{\small}
    \renewcommand\cftsectionpagefont{\small}
    \renewcommand\cftsubsectionfont{\small}
    \renewcommand\cftsubsectionpagefont{\small}
    \renewcommand\cftsubsubsectionfont{\small}
    \renewcommand\cftsubsubsectionpagefont{\small}
    % include the actual ToC data
    \tableofcontents*
  \endgroup
  % restore tocdepth
  \setcounter{tocdepth}{\value{@memmarkcntra}}
  % to indent or not after the chapter ToC
  \m@mindentafterchapter
  % space between part ToC and text
  \par\bigskip
  % handles indentation after the macro
  \@afterheading}
\makeatother

Note that if the \partprecistoc or \partprecis has been used then that data is also added to the ToC data, and we will need to locally disable it in the part ToC. This can be done by adding

\let\precistoctext\@gobble

to the \parttoc definition above, just make sure it is added before calling before \tableofcontents*.

enter image description here

\documentclass{memoir}

\newcounter{tocmarker}
\renewcommand\mempreaddparttotochook {\cftinserthook{toc}{end-\thetocmarker}}
\renewcommand\mempreaddbooktotochook {\cftinserthook{toc}{end-\thetocmarker}}
\renewcommand\mempreaddapppagetotochook{\cftinserthook{toc}{end-\thetocmarker}}
% start marker
\renewcommand\mempostaddparttotochook{%
  \stepcounter{tocmarker}\cftinserthook{toc}{start-\thetocmarker}}
\let\normalchangetocdepth\changetocdepth % for later

\makeatletter
\newcommand\parttoc{
  % make changes local, remember counters a global
  \begingroup
    % store current value, to be restored later
    \setcounter{@memmarkcntra}{\value{tocdepth}}
    % when ever \settocdepth is used, it adds the new value to the
    % ToC data. This cause problems when we want to disable all
    % entries. Luckily the data is added via a special macro, we
    % redefine it, remember we stored the original value earlier.
    \let\changetocdepth\@gobble
    % disable all entries (using our copy from above)
    \normalchangetocdepth{-10}
    % enable ToC data within our block, we go as far as section
    \cftinsertcode{start-\thetocmarker}{\normalchangetocdepth{1}}
    % when the block is done, disable the remaining
    \cftinsertcode{end-\thetocmarker}{\normalchangetocdepth{-10}}
    % remove the spacing above the ToC title
    \let\tocheadstart\relax
    % remove the ToC title itself
    \let\printtoctitle\@gobble
    % remove space below title
    \let\aftertoctitle\relax
    % reformat ToC entries:
    \setlength{\cftchapterindent}{0pt}
    \setlength{\cftsectionindent}{\cftchapternumwidth}
    \renewcommand\cftchapterfont{\small}
    \renewcommand\cftsectionfont{\small}
    % include the actual ToC data
    \tableofcontents*
  \endgroup
  % restore tocdepth
  \setcounter{tocdepth}{\value{@memmarkcntra}}
  % to indent or not after the chapter ToC
  \m@mindentafterchapter
  % space between part ToC and text
  \par\bigskip
  % handles indentation after the macro
  \@afterheading}
\makeatother

\begin{document}

\tableofcontents

\part{First part}

\parttoc

\chapter{First chapter}
\section{First section}
\section{Second section}
\section{Last section}

\chapter{Second chapter}
\section{First section}
\section{Second section}
\section{Last section}

\chapter{Last chapter}
\section{First section}
\section{Second section}
\section{Last section}

\end{document}

Note that you have the \parttoc on a separate page from the \part title. You have do modify some of the \part internals and perhaps some of \parttoc to display things on the same page properly. However, for now, without more guidelines, this should suffice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.