3

I want to redefine the aufgabe environment and combine it with the declared tcolorbox. In the end Aufgabe 1 subtitle should have the same textcolor/backgroundcolor like Exercise 0.1.

I also want to use the same command \begin{aufgabe}...\end{aufgabe} with the redefined environment.

\documentclass{article}

\usepackage[skins,hooks,xparse,breakable]{tcolorbox}
\usepackage{xcolor}
\usepackage{chngcntr}
\usepackage{blindtext}
\usepackage{tikz}

\newcounter{examplecounter}
\counterwithin{examplecounter}{section}

\usetikzlibrary{calc}


\definecolor{headercolourgreen}{rgb}{0,0.7019,0.7019}

\usepackage[
typ=ab,
fach=,
lerngruppe=,
farbig
% nummer=2A,
% datumAnzeigen,
% namensfeldAnzeigen,
]{schule}


\DeclareTColorBox{new}{O{}}{
    enhanced,
    breakable,
    arc=0pt,
    boxrule=0pt,
    colback=white,
    before skip={2em}, % increase spacing before the env
    overlay unbroken and first={
        % draw box on the left
        \node[fill=headercolourgreen!5,
        font=\color{headercolourgreen}\sffamily\bfseries\large,
        anchor=south west,
        xshift=2mm
        ] (titlebox) at (frame.north west) 
        {Exercise \refstepcounter{examplecounter}\theexamplecounter};
        
        
        \draw[draw=headercolourgreen, line width=2pt] 
        (titlebox.north west-|frame.north west)--+(0,-1.5);

    },
%   
}
\author{}
\title{}
\date{\today}



\begin{document}
            \begin{aufgabe}[subtitle=subtitle]
        \blindtext
    \end{aufgabe}
    \null
    \begin{aufgabe}[subtitle=subtitle]
        \blindtext
    \end{aufgabe}
    

    
    \null
    \begin{new}
        \blindtext
    \end{new}
    
    
    
    \null
    \begin{new}
        \blindtext
    \end{new}
    


\end{document}

1 Answer 1

3

If I understood you comment, here is one way to acieve the desired results: First, setup pgfkeys to extract the value of the subtitle= option:

\pgfkeys{MyAufgabe/.cd,
    subtitle/.store in=\MyAufgabeSubtitle,
}

This will store the value of the subtitle= in \MyAufgabeSubtitle.

Next redefine the aufgabe enviroment to extract the subtitle and pass \MyAufgabeSubtitle to tcolobbox. I defined this as aufgabeAux enviroment so it is simpler to see the difference between this and the new enviroment:

\renewenvironment{aufgabe}[1][]{%
    \pgfkeys{MyAufgabe/.cd, subtitle={}, #1}%
    \begin{aufgabeAux}[\MyAufgabeSubtitle]%
}{%
    \end{aufgabeAux}%
}%

References:

Result:

enter image description here

Code:

\documentclass{article}

\usepackage[skins,hooks,xparse,breakable]{tcolorbox}
\usepackage{xcolor}
\usepackage{chngcntr}
\usepackage{blindtext}
\usepackage{tikz}

\newcounter{examplecounter}
\counterwithin{examplecounter}{section}

\usetikzlibrary{calc}
\definecolor{headercolourgreen}{rgb}{0,0.7019,0.7019}

\usepackage[
typ=ab,
fach=,
lerngruppe=,
farbig
% nummer=2A,
% datumAnzeigen,
% namensfeldAnzeigen,
]{schule}

\tcbset{MyStyle/.style={
    enhanced,
    breakable,
    arc=0pt,
    boxrule=0pt,
    colback=white,
    before skip={2em}, % increase spacing before the env
}}

\DeclareTColorBox{new}{O{}}{
    MyStyle,
    overlay unbroken and first={
        % draw box on the left
        \node[fill=headercolourgreen!5,
        font=\color{headercolourgreen}\sffamily\bfseries\large,
        anchor=south west,
        xshift=2mm
        ] (titlebox) at (frame.north west) 
        {Exercise \refstepcounter{examplecounter}\theexamplecounter};
        \draw[draw=headercolourgreen, line width=2pt] 
        (titlebox.north west-|frame.north west)--+(0,-1.5);
    },
}


\DeclareTColorBox{aufgabeAux}{O{}}{
    MyStyle,
    overlay unbroken and first={
        % draw box on the left
        \node[fill=headercolourgreen!5,
        font=\color{headercolourgreen}\sffamily\bfseries\large,
        anchor=south west,
        xshift=2mm
        ] (titlebox) at (frame.north west) 
        {Aufgabe \refstepcounter{aufgabe}\theaufgabe\ #1};
        \draw[draw=headercolourgreen, line width=2pt] 
        (titlebox.north west-|frame.north west)--+(0,-1.5);
    },
}

%% Save the original version in case it is still needed
\let\oldaufgabe\aufgabe
\let\endoldaufgabe\endaufgabe

\pgfkeys{MyAufgabe/.cd,
    subtitle/.store in=\MyAufgabeSubtitle,
}
\renewenvironment{aufgabe}[1][]{%
    \pgfkeys{MyAufgabe/.cd, subtitle={}, #1}%
    \begin{aufgabeAux}[\MyAufgabeSubtitle]%
}{%
    \end{aufgabeAux}%
}%

\author{}
\title{}
\date{\today}
\begin{document}
    \begin{oldaufgabe}[subtitle=Some Subtitle]
        This is an example of using the original \verb|aufgabe| environment.
        This should appear as the original did.
    \end{oldaufgabe}
    \bigskip\hrule\bigskip
    
    \begin{aufgabe}[subtitle=This is a subtitle]
        This is an example of using the new \verb|aufgabe| environment with a subtitle.
        This should have the title appear as the \verb|new| environment.
    \end{aufgabe}
    
    \begin{aufgabe}
        Another example of using the new \verb|aufgabe| environment, 
        but \textbf{without a subtitle}.
    \end{aufgabe}
    
    \begin{new}[subtitle This is a subtitle]
        This the sample format that is the desired format for the new 
        \verb|aufgabe| environment .
    \end{new}
\end{document}
5
  • Maybe I expressed myself in a misleading way. To be precise, I wanted the end result to be rather the opposite. If i compile your proposal, the design and the redefinition of the commands are good. But if i use \begin{aufgabe}[subtitle=This is a subtitle the headline should be Aufgabe 1 This is a subtitle but in green and with the line on the left. May 17 at 16:08
  • @user2809537: Have updated answer. Let me know if this is what you were describing. If not, please provide a mocked up image of the desired result. May 18 at 7:29
  • Perfect. Thanks! May 19 at 10:44
  • Your modification works fine, but i have got a problem when i add some option to the environment. It doesn't count the points. \begin{aufgabe}[subtitle={subtitle text}, points=2+3, bonus-points=8] Compiled with the original code the output is like Aufgabe 1 subtitle text (5(+8) Punkte) May 20 at 17:37
  • @user2809537: I am not familiar with all the options of the aufgabe environment so won't be able to help you with those. May 20 at 21:02

You must log in to answer this question.

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