![定义随每个部分改变颜色的bclogo环境](https://linux22.com/image/390072/%E5%AE%9A%E4%B9%89%E9%9A%8F%E6%AF%8F%E4%B8%AA%E9%83%A8%E5%88%86%E6%94%B9%E5%8F%98%E9%A2%9C%E8%89%B2%E7%9A%84bclogo%E7%8E%AF%E5%A2%83.png)
对于我的定理和章节标题,我使用即
\usepackage{listofitem}
\setsepchar{,}
\readlist\mycolors{amaranth,blue,orange,purple}
\definecolor{amaranth}{HTML}{a82337}
\definecolor{orange}{HTML}{BF7F00}
\definecolor{blue}{HTML}{016FB9}
\definecolor{purple}{HTML}{603C96}
\usepackage[explicit]{titlesec}
\titleformat{\subsection}{
\normalfont\Large\bfseries}{}{0pt}{\colorbox{\mycolors[\thesection]!10{\thesubsection \ #1}}
使我的标题随着每个部分改变颜色(从这个答案。
现在,我对我的bclogo环境使用相同的规格:
\usepackage[tikz]{bclogo}
\begin{bclogo}[logo = \bclampe, couleur=blue!10,arrondi=0.1, couleurBarre=blue!10,noborder=true,ombre=true]{Idee}
Some text.
\end{bclogo}
现在,我想定义一个新环境,它看起来像这样,并且像我的部分标题一样随着每个部分改变其颜色,因此我不必每次使用这个环境时都写下所有的选项。
梅威瑟:
\documentclass[a4paper,twoside,ngerman]{article}
\usepackage{amsmath,amsfonts,cancel,mathtools,framed,mathabx,array,amssymb}
\usepackage{enumitem} % einfacher Nummerierung verändern
\usepackage{tikz} % zeichnen
\usetikzlibrary{cd} % kommutierende Diagramme
\usepackage{listofitems} % für Farben für Kapitel
\usepackage[tikz]{bclogo} % Kästen für Errinerung etc.
\usepackage{babel} % neue Rechtschreibung, Worttrennung
\usepackage[utf8]{inputenc} % Inputencoding
\usepackage[T1]{fontenc} % Umlaute
\usepackage[bookmarks=true,colorlinks=true,linkcolor=black]{hyperref}
\usepackage[thmmarks,framed,thref,hyperref]{ntheorem} % [thmmarks] guarantees endmarks
%theorems
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=subsection]{thm}{Satz}
{{colback=\mycolors[\thesection]!5},
{colframe=\mycolors[\thesection]!95!black},
fonttitle=\scshape\bfseries,
before skip=15pt plus 2pt,after skip=15pt plus 2pt}{th}
\setsepchar{,}
\readlist\mycolors{amaranth,blue,orange,purple}
\definecolor{amaranth}{HTML}{a82337}
\definecolor{orange}{HTML}{BF7F00}
\definecolor{blue}{HTML}{016FB9}
\definecolor{purple}{HTML}{603C96}
% formatting
\usepackage[explicit]{titlesec}
\titleformat{\section}
{\normalfont\LARGE\bfseries\raggedright}
{\llap{\colorbox{\mycolors[\thesection]}{\makebox[3em][r] {\textcolor{white}{\thesection}}}\hspace{1em}}}
{0pt}
{#1}
\begin{document}
\section{first, red section}
\begin{bclogo}[logo = \bclampe, couleur=amaranth!10,arrondi=0.1, couleurBarre= amaranth!10,noborder=true,ombre=true]{Idee}
Some text.
\end{bclogo}
\section{next, blue section}
\begin{bclogo}[logo = \bclampe, couleur=blue!10,arrondi=0.1, couleurBarre= blue!10,noborder=true,ombre=true]{Idee}
Some text.
\end{bclogo}
\end{document}
答案1
我不用颜色名称列表,而是直接在颜色名称中包含部分编号。然后,你可以像混合盒子couleur=mycol\thesection!10
的颜色一样使用它bclogo
\documentclass[a4paper,twoside,ngerman]{article}
\usepackage{amsmath,amsfonts,cancel,mathtools,framed,mathabx,array,amssymb}
\usepackage{enumitem} % einfacher Nummerierung verändern
\usepackage{tikz} % zeichnen
\usetikzlibrary{cd} % kommutierende Diagramme
\usepackage{listofitems} % für Farben für Kapitel
\usepackage[tikz]{bclogo} % Kästen für Errinerung etc.
\usepackage{babel} % neue Rechtschreibung, Worttrennung
\usepackage[utf8]{inputenc} % Inputencoding
\usepackage[T1]{fontenc} % Umlaute
\usepackage[thmmarks,framed,thref,hyperref]{ntheorem} % [thmmarks] guarantees endmarks
%theorems
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=subsection]{thm}{Satz}
{{colback=mycol\number\value{section}!5},
{colframe=mycol\number\value{section}!95!black},
fonttitle=\scshape\bfseries,
before skip=15pt plus 2pt,after skip=15pt plus 2pt}{th}
\definecolor{mycol1}{HTML}{a82337}
\definecolor{mycol2}{HTML}{016FB9}
\definecolor{mycol3}{HTML}{BF7F00}
\definecolor{mycol4}{HTML}{603C96}
% formatting
\usepackage[explicit]{titlesec}
\titleformat{\section}
{\normalfont\LARGE\bfseries\raggedright}
{\llap{\colorbox{mycol\number\value{section}}{\makebox[3em][r] {\textcolor{white}{\number\value{section}}}}\hspace{1em}}}
{0pt}
{#1}
\usepackage{etoolbox}
\newenvironment{mybclogo}[1]{%
\begin{bclogo}[logo = \bclampe, couleur=mycol\number\value{section}!10,arrondi=0.1, couleurBarre= mycol\number\value{section}!10,noborder=true,ombre=true]{#1}
}{
\end{bclogo}
}
\usepackage[bookmarks=true,colorlinks=true,linkcolor=black]{hyperref}
\begin{document}
\section{first, red section}
\begin{mybclogo}{Idee}
Some text.
\end{mybclogo}
\section{next, blue section}
\begin{mybclogo}{Idee}
Some text.
\end{mybclogo}
\end{document}