定义随每个部分改变颜色的bclogo环境

定义随每个部分改变颜色的bclogo环境

对于我的定理和章节标题,我使用即

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

在此处输入图片描述

相关内容