2

I am currently writing / typing up lecture notes in the article class from a entry level university course I attended this semester. There are four main sections. I use the index package and use a modified command, which highlights the word, that should be indexed and indexes it. Furthermore, I am using the following code to have fancier theorem statement layouts.

\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=subsection]{mytheo1}{Satz}
{colback=green!5,colframe=green!35!black,fonttitle=\scshape\bfseries}{th}

I want to (similar to a feature of the ulem package) be able to declare a color for each of those for sections, so that the color of the theorem environments and indexed words change accordingly.

I am also using

\usepackage[explicit]{titlesec}
\titleformat{\section}{\normalfont\Large\bfseries
{\llap{\colorbox{blue}{\makebox[3em][r]
{\textcolor{white}{\thesection}}}\hspace{1em}}}
{0pt}{#1}

as a section headline format and would like to change the color here accordingly, too.

Is this possible?

Kind regards.

PS: If you require additional information to answer my question please ask instead of shutting this question down immediately.

Minimal working example:

\documentclass[a4paper,ngerman]{article}
\usepackage{amsmath,amsfonts,cancel,mathtools,framed,mathabx,enumitem,array}
\usepackage{tikz,tikz-cd}

\usepackage{babel} % neue Rechtschreibung, Worttrennung
\usepackage[utf8]{inputenc} % Inputencoding
\usepackage[T1]{fontenc} % Umlaute

%new borders and header config

%Index
\usepackage{index}
\makeindex

\newcommand{\emphi}[1]{\index{#1}\textcolor{blue}{\textbf{#1}}} % above mentioned command
\renewcommand{\emph}[1]{\textcolor{blue}{\textbf{#1}}} % just highlight, don't index (i.e. for subentries)


% formatting
\usepackage[explicit]{titlesec}
\titleformat{\section}
{\normalfont\Large\bfseries}
{\llap{\colorbox{blue}{\makebox[3em][r]{\textcolor{white}
{\thesection}}}\hspace{1em}}}{0pt}{#1}

%newcommands
\DeclareMathOperator{\End}{End} % Die Menge aller Endomorphismen
% and lots of similar commands


%%Theoreme

\usepackage[thmmarks,framed,thref]{ntheorem} % [thmmarks] guarantees endmarks

%theorem
\usepackage{tcolorbox}          % I have used 4 different theorem styles for the 4 different sections
\tcbuselibrary{theorems}
\newtcbtheorem[number within=subsection]{mytheo1}{Satz} % grüne Theoreme für Kapitel 3
{colback=green!5,colframe=green!35!black,fonttitle=\scshape\bfseries}{th}

\newtcbtheorem[number within=subsection]{mytheo2}{Satz} % blaue Theoreme für Kapitel 4
{colback=blue!5,colframe=blue!55!black,fonttitle=\scshape\bfseries}{th}

\newtcbtheorem[number within=subsection]{mytheo3}{Satz} % orange Theoreme für Kapitel 5
{colback=orange!5,colframe=orange!55!black,fonttitle=\scshape\bfseries}{th}

\newtcbtheorem[number within=subsection]{mytheo4}{Satz} % magenta Theoreme für Kapitel 6
{colback=magenta!5,colframe=magenta!55!black,fonttitle=\scshape\bfseries}{th}

% defn
\theoremstyle{break}
\theorembodyfont{\normalfont}
\theoremheaderfont{\kern-5mm\scshape\bfseries} 
\theorempreskip{1em}
\theorempostskip{1em}
\theoremindent=5mm
\newframedtheorem{defn}{Definition}[subsection]
\newframedtheorem{altdef}{Alternative Definition}

% similarly defined lemma, corollary, proof etc.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                       Start of Document 

\begin{document}

\begin{titlepage}
    % titles and stuff
    \tableofcontents
    \vfill
\end{titlepage}

\setcounter{section}{2} 

\section{Determinanten II} % first section

\subsection{Die Determinante eines Endomorphismus}


% mathematical content starts here. Includes the above mentioned theorems and more: example
\begin{defn}[Determinante eine Endomorphismus\index{Determinante!eines Endomorphismus}]
    Sei $V$ ein $n$-dimensionaler $K$-Vektorraum und $F \in \End(V)$ ein Endomorphismus und $\B$ eine beliebige Basis von $V$.
    Die Determinante eines Endomorphismus ist definiert durch
    \begin{equation*}
        \det(F)
        = \det(M_{\B}(F)).
    \end{equation*}
\end{defn}

\begin{mytheo1}{$\det(F \circ G) = \det(F) \cdot \det(G)$}{Determinante von verknüpften Endomorphismen}
    Für zwei Endomorphismen $F$ und $G$ gilt $\det(F \circ G)= \det(F) \cdot \det(G)$.
\end{mytheo1}

% more subsections
\section{the second section}
% again content as above

\printindex

\end{document} \end{document}

1
  • You would greatly benefit from providing a complete MWE, i.e. a document that starts with \documentclass and ends with \end{document}.
    – user121799
    Jul 31, 2018 at 20:59

1 Answer 1

2

Here is a proposal. First define a color list and then set the color accordingly.

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{listofitems}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=subsection]{mytheo1}{Satz}
{{colback=\mycolors[\thesection]!5},{colframe=\mycolors[\thesection]!35!black},fonttitle=\scshape\bfseries}{th}
\setsepchar{,}
\readlist\mycolors{red,green,blue,purple,yellow}
\begin{document}
\section{Pythagoras}
\begin{mytheo1}{Pythagoras}{Pythagoras}
$a^2+b^2=c^2$
\end{mytheo1}

\section{Fermat}
\begin{mytheo1}{Fermat}{Fermat}
$a^n+b^n=c^n$ is not possible for positive integers $a,b,c,n$ and $n>2$
\end{mytheo1}
\end{document}

enter image description here

EDIT: For completeness: your code.

\documentclass[a4paper,ngerman]{article}
\usepackage{amsmath,amsfonts,cancel,mathtools,framed,mathabx,enumitem,array}
\usepackage{tikz,tikz-cd}

\usepackage{babel} % neue Rechtschreibung, Worttrennung
\usepackage[utf8]{inputenc} % Inputencoding
\usepackage[T1]{fontenc} % Umlaute

%new borders and header config

%Index
\usepackage{index}
\makeindex

\newcommand{\emphi}[1]{\index{#1}\textcolor{blue}{\textbf{#1}}} % above mentioned command
\renewcommand{\emph}[1]{\textcolor{blue}{\textbf{#1}}} % just highlight, don't index (i.e. for subentries)


% formatting
\usepackage[explicit]{titlesec}
\titleformat{\section}
{\normalfont\Large\bfseries}
{\llap{\colorbox{blue}{\makebox[3em][r]{\textcolor{white}
{\thesection}}}\hspace{1em}}}{0pt}{#1}

%newcommands
\DeclareMathOperator{\End}{End} % Die Menge aller Endomorphismen
% and lots of similar commands


%%Theoreme

\usepackage[thmmarks,framed,thref]{ntheorem} % [thmmarks] guarantees endmarks

%theorem
\usepackage{tcolorbox}          % I have used 4 different theorem styles for the 4 different sections
\tcbuselibrary{theorems}
% \newtcbtheorem[number within=subsection]{mytheo1}{Satz} % grüne Theoreme für Kapitel 3
% {colback=green!5,colframe=green!35!black,fonttitle=\scshape\bfseries}{th}

\newtcbtheorem[number within=subsection]{mytheo2}{Satz} % blaue Theoreme für Kapitel 4
{colback=blue!5,colframe=blue!55!black,fonttitle=\scshape\bfseries}{th}

\newtcbtheorem[number within=subsection]{mytheo3}{Satz} % orange Theoreme für Kapitel 5
{colback=orange!5,colframe=orange!55!black,fonttitle=\scshape\bfseries}{th}

\newtcbtheorem[number within=subsection]{mytheo4}{Satz} % magenta Theoreme für Kapitel 6
{colback=magenta!5,colframe=magenta!55!black,fonttitle=\scshape\bfseries}{th}

% defn
\theoremstyle{break}
\theorembodyfont{\normalfont}
\theoremheaderfont{\kern-5mm\scshape\bfseries} 
\theorempreskip{1em}
\theorempostskip{1em}
\theoremindent=5mm
\newframedtheorem{defn}{Definition}[subsection]
\newframedtheorem{altdef}{Alternative Definition}

% similarly defined lemma, corollary, proof etc.

\usepackage{listofitems}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=subsection]{mytheo1}{Satz}
{{colback=\mycolors[\thesection]!5},{colframe=\mycolors[\thesection]!35!black},
fonttitle=\scshape\bfseries}{th}
\setsepchar{,}
\readlist\mycolors{green, blue, orange, magenta}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                       Start of Document 

\begin{document}

\begin{titlepage}
    % titles and stuff
    \tableofcontents
    \vfill
\end{titlepage}

\setcounter{section}{2} 

\section{Determinanten II} % first section

\subsection{Die Determinante eines Endomorphismus}


% mathematical content starts here. Includes the above mentioned theorems and more: example
\begin{defn}[Determinante eine Endomorphismus\index{Determinante!eines Endomorphismus}]
    Sei $V$ ein $n$-dimensionaler $K$-Vektorraum und $F \in \End(V)$ ein Endomorphismus und 
    $\mathcal{B}$ eine beliebige Basis von $V$.
    Die Determinante eines Endomorphismus ist definiert durch
    \begin{equation*}
        \det(F)
        = \det(M_{\mathcal{B}}(F)).
    \end{equation*}
\end{defn}

\begin{mytheo1}{$\det(F \circ G) = \det(F) \cdot \det(G)$}{Determinante von verknüpften Endomorphismen}
    F\"ur zwei Endomorphismen $F$ und $G$ gilt $\det(F \circ G)= \det(F) \cdot \det(G)$.
\end{mytheo1}

\section{Pythagoras}
\begin{mytheo1}{Pythagoras}{Pythagoras}
 $a^2+b^2=c^2$
\end{mytheo1}


\end{document}

enter image description here

3
  • Great, but I use \setcounter{section}{2} because the course I am typesetting is Linear Algebra II, so my document won't start with Chapter 1. Jul 31, 2018 at 21:18
  • @ViktorGlombik That should not matter, or does it?
    – user121799
    Jul 31, 2018 at 21:20
  • I 'fixed it' by prepending 'black' to the list twice. Jul 31, 2018 at 21:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .