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:

second page:

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

second page

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:

Second page:

Last page:

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:

Second page:
