CODE HAS BEEN UPDATED, I THINK MY NEW ANSWER IS BETTER; Old with bophook (outdated package) is at the bottom!
New Code
\documentclass{article} %% Book works aswell, I just don't like
\usepackage{blindtext} %% Just for testing
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{etoolbox} % provides if-else-conditionals
\usepackage{eso-pic} % provides the \AddToShipoutPictureBG command
%% TOPIC A
\def \currentTopicColor{white!100}
\newcommand{\Topic}[0]{
\begin{tikzpicture}[remember picture,overlay]
\path[draw=black] let \p1 = ($ (current page.west)$) in node(A) at (\x1,0) {};
\fill [\currentTopicColor,line width=10pt] ($ (A) + (1cm,0.4cm) $) rectangle ($ (A) + (2cm,-40cm) $);
\end{tikzpicture}
}
\newcounter{brain}
\setcounter{brain}{0}
\newcounter{didWeJustChangePage}
\setcounter{didWeJustChangePage}{0} %Sæt 0 ved hver topic
\AddToHook {shipout/background}{
\ifodd\thebrain
{
\setcounter{didWeJustChangePage}{1}
\begin{tikzpicture}[remember picture,overlay]
\path[draw=black] let \p1 = ($ (current page.west)$) in node(A) at (\x1,0) {};
\fill [\currentTopicColor,line width=0pt] ($ (A) + (1cm,0.4cm) $) rectangle ($ (A) + (2cm,-40cm) $);
\end{tikzpicture}
}
\else{
\setcounter{didWeJustChangePage}{1}
\setcounter{brain}{1}
}\fi
}
\newcommand{\previoustopicdrawing}{
\begin{tikzpicture}[remember picture,overlay]
\path[draw=black] let \p1 = ($ (current page.west)$) in node(A) at (\x1,0) {};
\fill [yellow,line width=0pt] ($ (A) + (1cm,7cm) $) rectangle ($ (A) + (2cm,-0.4cm) $);
\end{tikzpicture}
}
\newcommand{\topicdrawing}[1]{
\ifodd\thedidWeJustChangePage
{
\begin{tikzpicture}[remember picture,overlay]
\path[draw=black] let \p1 = ($ (current page.west)$) in node(A) at (\x1,0) {};
\fill [\currentTopicColor,line width=10pt] ($ (A) + (1cm,40cm) $) rectangle ($ (A) + (2cm,-0.4cm) $);
\fill [#1,line width=10pt] ($ (A) + (1cm,0.4cm) $) rectangle ($ (A) + (2cm,-40cm) $);
\end{tikzpicture}
}
\else{
\begin{tikzpicture}[remember picture,overlay]
\path[draw=black] let \p1 = ($ (current page.west)$) in node(A) at (\x1,0) {};
\fill [#1,line width=10pt] ($ (A) + (1cm,0.4cm) $) rectangle ($ (A) + (2cm,-40cm) $);
\end{tikzpicture}
}\fi
}
\def \TopicAColor{orange!20}
\def \TopicBColor{green!20}
\def \TopicCColor{red!20}
\def \TopicDColor{blue!20}
\def \TopicFColor{yellow!20}
\newcommand{\TopicA}{
\topicdrawing{\TopicAColor}
\def \currentTopicColor{\TopicAColor}
\setcounter{brain}{0}
\setcounter{didWeJustChangePage}{0}
}
\newcommand{\TopicB}{
\topicdrawing{\TopicBColor}
\def \currentTopicColor{\TopicBColor}
\setcounter{brain}{0}
\setcounter{didWeJustChangePage}{0}
}
\newcommand{\TopicC}{
\topicdrawing{\TopicCColor}
\def \currentTopicColor{\TopicCColor}
\setcounter{brain}{0}
\setcounter{didWeJustChangePage}{0}
}
\newcommand{\TopicD}{
\topicdrawing{\TopicDColor}
\def \currentTopicColor{\TopicDColor}
\setcounter{brain}{0}
\setcounter{didWeJustChangePage}{0}
}
\newcommand{\TopicF}{
\topicdrawing{\TopicFColor}
\def \currentTopicColor{\TopicFColor}
\setcounter{brain}{0}
\setcounter{didWeJustChangePage}{0}
}
\newcommand{\TopicRemove}{
\topicdrawing{white!100}
\def \currentTopicColor{white!100}
\setcounter{brain}{0}
\setcounter{didWeJustChangePage}{0}
}
\begin{document}
\tableofcontents
\section{Fundamental of Topic (including some A and some B)}
\TopicF
\subsection{Here is some text about fundamental}
\noindent\blindtext[2]
\bigskip\par
\TopicA
\subsection{Here is some text about topic A}
\noindent \blindtext[2] \par
\TopicB
\subsection{Here is some text about topic B}
\blindtext[2] \par
\TopicRemove
\par
\subsection{Here is some text with no topic}
\blindtext[3] \par
\TopicB
\subsection{Here is some more text about topic B}
\blindtext[2] \par
\end{document}
And the output of the MWE
Old code with outdated package
I'm not quite sure what you want with the table of content, however you can make colored stripes along the margins with a bunch of different packages.
Below is an example code, but first how the output of the code.
\documentclass{article} %% Book works aswell, I just don't like
\usepackage{blindtext} %% Just for testing
%% NOT IMPORTANT BUT I JUST NEED
\usepackage{fancyhdr}
\usepackage{lastpage}
\newcommand{\titlesetup}[4]{
\title{#2 }
\author{af #1}
\date{#3}
\pagestyle{fancy}
\fancyhf{}
\setlength\headheight{15pt}
\fancyhead[L]{#4}
\fancyhead[R]{#2}
\fancyfoot[R]{\thepage}
\fancypagestyle{plain}{
\fancyhf{}
\rfoot{\thepage}
} }
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{etoolbox} % provides if-else-conditionals
\usepackage{eso-pic} % provides the \AddToShipoutPictureBG command which adds content to background of every page
\usepackage{bophook} %% Lader os gøre det på hver side
\newtoggle{TopicA} % default: deactivated
\AddToShipoutPictureBG{% this command adds content to background of every page
\iftoggle{TopicA}{
\AtBeginPage{\TopicA}
}{%else, but we need no else ;)
}}
\newtoggle{TopicE} % default: deactivated
\AddToShipoutPictureBG{% this command adds content to background of every page
\iftoggle{TopicE}{
\AtBeginPage{\TopicE}
}{%else, but we need no else ;)
}}
\newtoggle{TopicD} % default: deactivated
\AddToShipoutPictureBG{% this command adds content to background of every page
\iftoggle{TopicD}{
\AtBeginPage{\TopicD}
}{%else, but we need no else ;)
}}
\newtoggle{NOTOPIC} % default: deactivated
\AddToShipoutPictureBG{% this command adds content to background of every page
\iftoggle{NOTOPIC}{
\AtBeginPage{\TopicRemove}
}{%else, but we need no else ;)
}}
%% TOPIC D
\newcommand{\TopicD}[0]{
\begin{tikzpicture}[remember picture,overlay]
\path[draw=black] let \p1 = ($ (current page.west)$) in node(A) at (\x1,0) {};
\fill [blue!20,line width=10pt] ($ (A) + (1cm,0.4cm) $) rectangle ($ (A) + (2cm,-40cm) $);
\end{tikzpicture}
\TR
\toggletrue{TopicD} %% Toggle D on
}
%% TOPIC A
\newcommand{\TopicA}[0]{
\begin{tikzpicture}[remember picture,overlay]
\path[draw=black] let \p1 = ($ (current page.west)$) in node(A) at (\x1,0) {};
\fill [orange!20,line width=10pt] ($ (A) + (1cm,0.4cm) $) rectangle ($ (A) + (2cm,-40cm) $);
\end{tikzpicture}
\TR %% Toggles all other enviroments off
\toggletrue{TopicA} %% Toggle A on
}
%% TOPIC E
\newcommand{\TopicE}[0]{
\begin{tikzpicture}[remember picture,overlay]
\path[draw=black] let \p1 = ($ (current page.west)$) in node(A) at (\x1,0) {};
\fill [green!20,line width=10pt] ($ (A) + (1cm,0.4cm) $) rectangle ($ (A) + (2cm,-40cm) $);
\end{tikzpicture}
\TR
\togglefalse{NOTOPIC}
}
\newcommand{\TR}[0]{
\togglefalse{TopicA}
\togglefalse{TopicD}
\togglefalse{TopicE}
\togglefalse{NOTOPIC}
}
\newcommand{\TopicRemove}[0]{
\TR
\toggletrue{NOTOPIC}
\begin{tikzpicture}[remember picture,overlay]
\path[draw=black] let \p1 = ($ (current page.west)$) in node(A) at (\x1,0) {};
\fill [white!100,line width=0pt] ($ (A) + (1cm,0.4cm) $) rectangle ($ (A) + (2cm,-40cm) $);
\end{tikzpicture}
}
\begin{document}
\titlesetup{Test of Test}{Test}{Test}{Test}
\tableofcontents
\section{Fundamental of Topic (including some A and some B)}
\TopicD
\subsection{Here is some text about fundamental}
\noindent\blindtext[2]
\bigskip\par
\TopicA
\subsection{Here is some text about topic A}
\noindent \blindtext[2] \par
\TopicE
\subsection{Here is some text about topic B}
\blindtext[2] \par
\TopicRemove
\par
\subsection{Here is some text with no topic}
\blindtext[3] \par
\TopicA
\subsection{Here is some more text about topic B}
\blindtext[2] \par
\end{document}
Found some "inspiration here", might help explain things a bit :):
Colored Margins
How to set colored ruled margins for some pages?
Tikz one coordinate
TikZ: Node at same x-coordinate as another node, but specified y-coordinate?
Do some on the start of page(make colored margins)
Execute a command at the start of every page
E-tools package
http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/etoolbox/etoolbox.pdf#page=3&zoom=100,0,0