列表部分的颜色不适用于第 0 部分

列表部分的颜色不适用于第 0 部分

如你看到的这里,我想为我的讲义的各个部分添加颜色,这意味着定理、标题等每个部分都会有不同的颜色。我现在使用建议的

\usepackage{listofitems}
\setsepchar{,}
\readlist\mycolors{red,green,blue,purple,yellow}

在我的标题、定理等定义中使用类似 color = \mycolors[\thesection] 的内容。对于我当前的讲义,我希望有第 -1 章和第 0 章。-1 非常完美,因为列表的最后一项用于着色,但第 0 项未定义,包文档也没有帮助我。

答案1

这对我有用:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{listofitems}
\usepackage{fancyhdr}

\tcbuselibrary{theorems}
\newtcbtheorem[number within=subsection]{mytheo1}{Satz}
{{colback=\mycolors[\mthesection]!5},{colframe=\mycolors[\mthesection]!35!black},fonttitle=\scshape\bfseries}{th}
\setsepchar{,}
\readlist\mycolors{red,green,blue,purple,yellow}
\let\oldsection\section
\def\mthesection{\ifnum\thesection<0 \thesection\else\numexpr\thesection+1\relax\fi}
%\renewcommand{\sectionmark}[1]{\markright{\color{\mycolors[\mthesection]}\textbf{#1}}}
\makeatletter
\patchcmd{\f@nch@head}{\rlap}{\color{\mycolors[\mthesection]}\rlap}{}{}
\patchcmd{\headrule}{\hrule}{\color{\mycolors[\mthesection]}\hrule}{}{}
\patchcmd{\f@nch@foot}{\rlap}{\color{\mycolors[\mthesection]}\rlap}{}{}
\patchcmd{\footrule}{\hrule}{\color{\mycolors[\mthesection]}\hrule}{}{}
\makeatother
\begin{document}
\pagestyle{fancy}
\setcounter{section}{-2}

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

\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}
\clearpage
\section{Something Else}
\begin{mytheo1}{Something}{Something}
$\alpha \ge 0$ if $\alpha \in N$
\end{mytheo1}

\end{document}

输出:

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

PS:如果不行的话请尝试:\protected\def\mthesection{\ifnum\thesection<0 \thesection\else\numexpr\thesection+1\relax\fi}如果仍然失败,请尝试给MWE(我刚刚被要求写一个最简单的例子,那是什么?

相关内容