每个部分改变关键词、定理等的颜色

每个部分改变关键词、定理等的颜色

我目前正在撰写/输入我本学期参加的大学入门课程的文章课讲义。主要有四个部分。我使用索引包并使用修改后的命令,该命令突出显示应编入索引的单词并对其进行索引。此外,我使用以下代码来获得更精美的定理语句布局。

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

我希望(类似于 ulem 包的一个功能)能够为每个部分声明一种颜色,以便定理环境和索引词的颜色相应地改变。

我也正在使用

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

作为部分标题格式,并且也想相应地更改这里的颜色。

这可能吗?

亲切的问候。

附言:如果您需要更多信息来回答我的问题,请提出问题,而不是立即关闭此问题。

最小工作示例:

\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

\打印索引

\结束{文档} \结束{文档}

答案1

这里有一个建议。首先定义一个颜色列表,然后相应地设置颜色。

\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}

在此处输入图片描述

编辑:为了完整性:您的代码。

\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}

在此处输入图片描述

相关内容