0

The background color behind the image should be white over the whole height of the box. Just the text has to be with the green background color. Is it possible to do it inside the box or only with another box just for the image?

\documentclass{article}

\usepackage[skins,hooks,xparse,breakable]{tcolorbox}
\usepackage{xcolor}
\usepackage{chngcntr}
\usepackage{blindtext}
\usepackage{tikz}
\usepackage{graphicx}
\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);
    },
}



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


\newlength\myheight
\newlength\mydepth
\settototalheight\myheight{Xygp}
\settodepth\mydepth{Xygp}
\newcommand*\inlinegraphics[1]{%
    \settototalheight\myheight{Xygp}%
    \settodepth\mydepth{Xygp}%
    \raisebox{-\mydepth}{\includegraphics[height=\myheight]{#1}}%
}

\newcommand{\dpcalc}{\textbf{\inlinegraphics{example-image-b}\space}}



\author{}
\title{}
\date{\today}

\begin{document}

    
    \begin{aufgabe}[subtitle=This is a subtitle \dpcalc]
        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}
    

\end{document}

1 Answer 1

1

Use

\newcommand{\dpcalc}{\rlap{\hspace{1em}\textbf{\inlinegraphics{example-image-b}\space}}}

I added some \hspace you can twiddle.

aufgabe with image

2
  • Great. But now i have a problem if i want to add two or more in a row. How i have to modify the code? May 23 at 0:04
  • the \rlap hides the width. So if "two or more" refers to the \includegraphics, make sure they are all one after the other inside the \rlap argument (only one \rlap for all)
    – user691586
    May 23 at 7:10

You must log in to answer this question.

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