0

I'm working on a two-column TOC. It's rather detailed with subsections, subsubsections, and even named paragraphs included. Of course the columns run for the whole page and restart from the next page.

1) I would rather like these two-column blocks to restart not from page boundary but from each new section. I accept that the blocks will be of different heights then, and quite ragged.

2) Not relying on the natural boundaries provided by page edges anymore, I would instead like the section-two-column-blocks to be mdframed individually, across page boundaries when necessary.

The etoc.pdf has a provision for frames quoted below. But it's complex and still quite far from what I want, and I feel it's going to take me weeks unless someone could help, please. (Solutions based on tcolorbox are also welcome.)

42.5. The commands \etocframedstyle , \etocframed , and \etoclocalframed

The entire table of contents is framed. The title itself is not framed: if one wants a frame one should set it up inside the title argument to \etocframedstyle or \etocframed.The colors for the background and for the components (top, left, right, bottom) of the border are specified via suitable \renewcommand ’s (see subsection 46.2). A minipage is used, hence the produced table of contents isn’t compatible with a page break. For allowing page breaks, use of the commands of mdframed 39 or tcolorbox 40 in the arguments of \etocsettocstyle is recommended.

  • the biggest problem here seems to be multicols+mdframed. Do you mean mdframed inside multicols or multicols inside mdframed? – user4686 Aug 28 '18 at 14:54
3

Here are attempts with framed and mdframed. I did not try tcolorbox.

But I encountered a difficulty: probably because multicols facilitates breaking page before or after it, it is very hard to get the boxes to break nicely: either they don't break or they break preferentially right after the chapter title.

So in the end, I commented out the usage of multicols and I post here examples with single-column.

Some remarks:

  • because in both cases the title are printed (either by framed or mdframed) in a delayed manner, the \etocname and \etocnumber must be somehow stored and then reused,

  • because the chapter style may close a group, one issues \etocglobaldefs in preamble,

  • because we re-define the chapter style, etoc automatically uses its own custom line styles for the other levels (section, subsection, subsubsection). But this custom styling drops paragraphs and subparagraphs and prints subsubsections "horizontally". Thus a complete example needs to rework all levels.

with framed

\documentclass[a4paper]{book}
\usepackage{etoc}
\usepackage{framed}
\usepackage{color}
\definecolor{TFTitleColor}{rgb}{0,0,1}
\definecolor{TFFrameColor}{gray}{0.75}
\usepackage{amssymb}% \blacktriangleright needed by framed.sty

\usepackage{hyperref}% testing compatibility

\usepackage{geometry}

\begin{document}

\etocglobaldefs % needed because our chapter style closes a group

\etocsetstyle{chapter}
   {}
   {\etocxiffirst{}%
                 {%\end{multicols}
                  \end{titled-frame}}%
    % the above possibly closed a group, this is why we issued \etocglobaldefs
    % seems we need to preserve meaning for later expansion
    \global\let\savedchapterlinkednumber\etocthelinkednumber
    \global\let\savedchapterlinkedname\etocthelinkedname
    \begin{titled-frame}{\savedchapterlinkednumber. \savedchapterlinkedname}
    %\begin{multicols}{2}
    }
   {}
   {%\end{multicols}
    \end{titled-frame}}

% \renewcommand{\etocaftertitlehook}{\columnsep1cm }% multicols

\tableofcontents

\part{ONE}
\chapter{Test chapter one}
\section{Section one one}
\subsection{Subsection one one one}
\subsection{Subsection one  one two}
\section{Section one two}
\subsection{Subsection one two one}
\subsection{Subsection one  two two}
\section{Section one three}
\subsection{Subsection one three one}
\subsection{Subsection one three two}
\section{Section one four}
\subsection{Subsection one four one}
\subsection{Subsection one four two}

\chapter{Test chapter two}
\section{Section two one}
\subsection{Subsection two one one}
\subsection{Subsection two one two}
\subsection{Subsection two one three}
\section{Section two two}
\subsection{Subsection two two one}
\subsection{Subsection two  two two}
\subsection{Subsection two two three}
\section{Section two three}
\subsection{Subsection two three one}
\subsection{Subsection two three two}
\subsection{Subsection two three three}
\section{Section two four}
\subsection{Subsection two four one}
\subsection{Subsection two four two}
\subsection{Subsection two four three}
\section{Section two five}
\subsection{Subsection two five one}
\subsection{Subsection two five two}
\subsection{Subsection two five three}
\section{Section two six}
\subsection{Subsection two six one}
\subsection{Subsection two six two}
\subsection{Subsection two six three}
\subsection{Subsection two four three}
\section{Section two seven}
\subsection{Subsection two seven one}
\subsection{Subsection two seven two}
\subsection{Subsection two seven three}
\section{Section two eight}
\subsection{Subsection two eight one}
\subsection{Subsection two eight two}
\subsection{Subsection two eight three}


\chapter{Test chapter three}
\section{Section three one}
\subsection{Subsection three one one}
\subsection{Subsection three one two}
\section{Section three two}
\subsection{Subsection three two one}
\subsection{Subsection three two two}
\section{Section three three}
\subsection{Subsection three three one}
\subsection{Subsection three three two}
\section{Section three four}
\subsection{Subsection three four one}
\subsection{Subsection three four two}

\chapter{Test chapter four}
\section{Section four one}
\subsection{Subsection four one one}
\subsection{Subsection four one two}
\subsection{Subsection four one three}
\section{Section four two}
\subsection{Subsection four two one}
\subsection{Subsection four two two}
\subsection{Subsection four two three}
\end{document}

first page:

enter image description here

second page:

enter image description here

with mdframed

\documentclass{book}
\usepackage{etoc}
\usepackage{mdframed}
\begin{document}

\global\mdfdefinestyle{myexampledefault}{%
  linecolor=red,linewidth=3pt,%
  leftmargin=1cm,rightmargin=1cm,%
  rightline=true,innerleftmargin=10,innerrightmargin=10,
  frametitlerule=true,frametitlerulecolor=green,
  frametitlebackgroundcolor=yellow,
  frametitlerulewidth=2pt}

\etocglobaldefs % needed because our chapter style closes a group

\etocsetstyle{chapter}
   {}
   {\etocxiffirst{}%
                 {%\end{multicols}
                  \end{mdframed}}%
    % the above possibly closed a group, this is why we issued \etocglobaldefs
    % seems we need to preserve meaning for later expansion
    \global\let\savedchapterlinkednumber\etocthelinkednumber
    \global\let\savedchapterlinkedname\etocthelinkedname
    \begin{mdframed}[style=myexampledefault,%
      frametitle={\savedchapterlinkednumber. \savedchapterlinkedname}]%
    %\begin{multicols}{2}
    }
   {}
   {%\end{multicols}
    \end{mdframed}}

% \renewcommand{\etocaftertitlehook}{\columnsep1cm }% multicols

\tableofcontents

\part{ONE}
\chapter{Test chapter one}
\section{Section one one}
\subsection{Subsection one one one}
\subsection{Subsection one  one two}
\section{Section one two}
\subsection{Subsection one two one}
\subsection{Subsection one  two two}
\section{Section one three}
\subsection{Subsection one three one}
\subsection{Subsection one three two}
\section{Section one four}
\subsection{Subsection one four one}
\subsection{Subsection one four two}

\chapter{Test chapter two}
\section{Section two one}
\subsection{Subsection two one one}
\subsection{Subsection two one two}
\subsection{Subsection two one three}
\section{Section two two}
\subsection{Subsection two two one}
\subsection{Subsection two  two two}
\subsection{Subsection two two three}
\section{Section two three}
\subsection{Subsection two three one}
\subsection{Subsection two three two}
\subsection{Subsection two three three}
\section{Section two four}
\subsection{Subsection two four one}
\subsection{Subsection two four two}
\subsection{Subsection two four three}
\section{Section two five}
\subsection{Subsection two five one}
\subsection{Subsection two five two}
\subsection{Subsection two five three}
\section{Section two six}
\subsection{Subsection two six one}
\subsection{Subsection two six two}
\subsection{Subsection two six three}
\subsection{Subsection two four three}
\section{Section two seven}
\subsection{Subsection two seven one}
\subsection{Subsection two seven two}
\subsection{Subsection two seven three}
\section{Section two eight}
\subsection{Subsection two eight one}
\subsection{Subsection two eight two}
\subsection{Subsection two eight three}


\chapter{Test chapter three}
\section{Section three one}
\subsection{Subsection three one one}
\subsection{Subsection three one two}
\section{Section three two}
\subsection{Subsection three two one}
\subsection{Subsection three two two}
\section{Section three three}
\subsection{Subsection three three one}
\subsection{Subsection three three two}
\section{Section three four}
\subsection{Subsection three four one}
\subsection{Subsection three four two}

\chapter{Test chapter four}
\section{Section four one}
\subsection{Subsection four one one}
\subsection{Subsection four one two}
\subsection{Subsection four one three}
\section{Section four two}
\subsection{Subsection four two one}
\subsection{Subsection four two two}
\subsection{Subsection four two three}
\end{document}

first page

enter image description here

second page

enter image description here


As I explained in incipit it does work with added multicols environment inside the breakable boxes, except the breaks are chosen in disappointing locations, and I have no solution for that. Hence I don't post pictures. Uncomment relevant lines in the MWEs to test.

Of course the above needs some reworking to fit the OP's constraints for the extra reason that as explained the own etoc styles are used, and only chapter is defined in a custom way. Perhaps things like \etocsavedsectiontocline can help, as they allow to reproduce the class defaults. See etoc docs.


I am adding version which sets the sections and subsections in class default, inside the framed chapter style. The MWE has a \part{TWO} added. Left commented out attempts to either typeset the whole thing in a multicols, or to use multicols inside the framed environment, each one having its problems (not illustrated here).

\documentclass[a4paper]{book}
\usepackage{etoc}
\usepackage{framed}
\usepackage{color}
\definecolor{TFTitleColor}{rgb}{0,0,1}
\definecolor{TFFrameColor}{gray}{0.75}
\usepackage{amssymb}% \blacktriangleright needed by framed.sty

\usepackage{hyperref}% testing compatibility

\usepackage{geometry}

\begin{document}

\etocglobaldefs % needed because our chapter style closes a group

\etocsetstyle{chapter}
   {}
   {\etocxiffirst{}%
                 {%\end{multicols}
                  \end{titled-frame}}%
    % the above possibly closed a group, this is why we issued \etocglobaldefs
    % seems we need to preserve meaning for later expansion
    \global\let\savedchapterlinkednumber\etocthelinkednumber
    \global\let\savedchapterlinkedname\etocthelinkedname
    \begin{titled-frame}{\savedchapterlinkednumber. \savedchapterlinkedname}
    %\begin{multicols}{2}
    }
   {}
   {%\end{multicols}
    \end{titled-frame}}

% \renewcommand{\etocaftertitlehook}{\begin{multicols}2\raggedcolumns}
% \renewcommand{\etocaftercontentshook}{\end{multicols}}

\etocsetstyle{section}
  {}
  {\etocsavedsectiontocline
    {\etocifnumbered{\numberline{\etocnumber}}{}%
     \etocname}
    {\etocpage}%
   }
  {}
  {}
\etocsetstyle{subsection}
  {}
  {\etocsavedsubsectiontocline
    {\etocxifnumbered{\numberline{\etocnumber}}{}%
     \etocname}
    {\etocpage}%
   }
  {}
  {}


\tableofcontents

\part{ONE}
\chapter{Test chapter one}
\section{Section one one}
\subsection{Subsection one one one}
\subsection{Subsection one  one two}
\section{Section one two}
\subsection{Subsection one two one}
\subsection{Subsection one  two two}
\section{Section one three}
\subsection{Subsection one three one}
\subsection{Subsection one three two}
\section{Section one four}
\subsection{Subsection one four one}
\subsection{Subsection one four two}

\chapter{Test chapter two}
\section{Section two one}
\subsection{Subsection two one one}
\subsection{Subsection two one two}
\subsection{Subsection two one three}
\section{Section two two}
\subsection{Subsection two two one}
\subsection{Subsection two  two two}
\subsection{Subsection two two three}
\section{Section two three}
\subsection{Subsection two three one}
\subsection{Subsection two three two}
\subsection{Subsection two three three}
\section{Section two four}
\subsection{Subsection two four one}
\subsection{Subsection two four two}
\subsection{Subsection two four three}
\section{Section two five}
\subsection{Subsection two five one}
\subsection{Subsection two five two}
\subsection{Subsection two five three}
\section{Section two six}
\subsection{Subsection two six one}
\subsection{Subsection two six two}
\subsection{Subsection two six three}
\subsection{Subsection two four three}
\section{Section two seven}
\subsection{Subsection two seven one}
\subsection{Subsection two seven two}
\subsection{Subsection two seven three}
\section{Section two eight}
\subsection{Subsection two eight one}
\subsection{Subsection two eight two}
\subsection{Subsection two eight three}

\part{TWO}

\chapter{Test chapter three}
\section{Section three one}
\subsection{Subsection three one one}
\subsection{Subsection three one two}
\section{Section three two}
\subsection{Subsection three two one}
\subsection{Subsection three two two}
\section{Section three three}
\subsection{Subsection three three one}
\subsection{Subsection three three two}
\section{Section three four}
\subsection{Subsection three four one}
\subsection{Subsection three four two}

\chapter{Test chapter four}
\section{Section four one}
\subsection{Subsection four one one}
\subsection{Subsection four one two}
\subsection{Subsection four one three}
\section{Section four two}
\subsection{Subsection four two one}
\subsection{Subsection four two two}
\subsection{Subsection four two three}
\end{document}

First page: enter image description here

Second page: enter image description here

Last page: enter image description here


Finally, here here a 2-column display, but using book class \twocolumn rather than a multicols environment. This appears to work fine.

The trick is to use \etocsettocstyle to do exactly the opposite from what the table of contents usually do, i.e. if in one column mode we will temporarily switch to two-column mode.

\documentclass[a4paper]{book}
\usepackage{etoc}
\usepackage{framed}
\usepackage{color}
\definecolor{TFTitleColor}{rgb}{0,0,1}
\definecolor{TFFrameColor}{gray}{0.75}
\usepackage{amssymb}% \blacktriangleright needed by framed.sty

\usepackage{hyperref}% testing compatibility

\usepackage{geometry}

\begin{document}

\etocglobaldefs % needed because our chapter style closes a group

\etocsetstyle{chapter}
   {}
   {\etocxiffirst{}%
                 {%\end{multicols}
                  \end{titled-frame}}%
    % the above possibly closed a group, this is why we issued \etocglobaldefs
    % seems we need to preserve meaning for later expansion
    \global\let\savedchapterlinkednumber\etocthelinkednumber
    \global\let\savedchapterlinkedname\etocthelinkedname
    \begin{titled-frame}{\savedchapterlinkednumber. \savedchapterlinkedname}
    %\begin{multicols}{2}
    }
   {}
   {%\end{multicols}
    \end{titled-frame}}

% \renewcommand{\etocaftertitlehook}{\begin{multicols}2\raggedcolumns}
% \renewcommand{\etocaftercontentshook}{\end{multicols}}

\etocsetstyle{section}
  {}
  {\etocsavedsectiontocline
    {\etocifnumbered{\numberline{\etocnumber}}{}%
     \etocname}
    {\etocpage}%
   }
  {}
  {}
\etocsetstyle{subsection}
  {}
  {\etocsavedsubsectiontocline
    {\etocxifnumbered{\numberline{\etocnumber}}{}%
     \etocname}
    {\etocpage}%
   }
  {}
  {}

\makeatletter
\etocsettocstyle
  {\if@twocolumn \@restonecolfalse
    \else \setlength{\columnsep}{1cm} \@restonecoltrue \twocolumn
   \fi
   \chapter *{\contentsname 
                 \@mkboth {\MakeUppercase \contentsname}
                          {\MakeUppercase \contentsname}%
             }%
   }
  {\if@restonecol \onecolumn \fi}
\makeatother
\tableofcontents

\part{ONE}
\chapter{Test chapter one}
\section{Section one one}
\subsection{Subsection one one one}
\subsection{Subsection one  one two}
\section{Section one two}
\subsection{Subsection one two one}
\subsection{Subsection one  two two}
\section{Section one three}
\subsection{Subsection one three one}
\subsection{Subsection one three two}
\section{Section one four}
\subsection{Subsection one four one}
\subsection{Subsection one four two}

\chapter{Test chapter two}
\section{Section two one}
\subsection{Subsection two one one}
\subsection{Subsection two one two}
\subsection{Subsection two one three}
\section{Section two two}
\subsection{Subsection two two one}
\subsection{Subsection two  two two}
\subsection{Subsection two two three}
\section{Section two three}
\subsection{Subsection two three one}
\subsection{Subsection two three two}
\subsection{Subsection two three three}
\section{Section two four}
\subsection{Subsection two four one}
\subsection{Subsection two four two}
\subsection{Subsection two four three}
\section{Section two five}
\subsection{Subsection two five one}
\subsection{Subsection two five two}
\subsection{Subsection two five three}
\section{Section two six}
\subsection{Subsection two six one}
\subsection{Subsection two six two}
\subsection{Subsection two six three}
\subsection{Subsection two four three}
\section{Section two seven}
\subsection{Subsection two seven one}
\subsection{Subsection two seven two}
\subsection{Subsection two seven three}
\section{Section two eight}
\subsection{Subsection two eight one}
\subsection{Subsection two eight two}
\subsection{Subsection two eight three}

\part{TWO}

\chapter{Test chapter three}
\section{Section three one}
\subsection{Subsection three one one}
\subsection{Subsection three one two}
\section{Section three two}
\subsection{Subsection three two one}
\subsection{Subsection three two two}
\section{Section three three}
\subsection{Subsection three three one}
\subsection{Subsection three three two}
\section{Section three four}
\subsection{Subsection three four one}
\subsection{Subsection three four two}

\chapter{Test chapter four}
\section{Section four one}
\subsection{Subsection four one one}
\subsection{Subsection four one two}
\subsection{Subsection four one three}
\section{Section four two}
\subsection{Subsection four two one}
\subsection{Subsection four two two}
\subsection{Subsection four two three}
\end{document}

Produces

First page:

enter image description here

Second page:

enter image description here

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.