1

enter image description hereI'm trying to align the main title so it starts after the counter box [red] and runs towards the right side of the box, but so far it stretches to the left. What am I doing wrong? Merci in advance for any help.

MWE:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}%erlaubt Umlaute
\usepackage{lmodern}
\usepackage[skins]{tcolorbox}



\newtcolorbox[auto counter, ]{mybox1}[3][]{
  enhanced,
  arc=.3mm, 
  boxrule=0.3pt,
 fonttitle=\bfseries,
  colback=white,
  colframe=red!65!black,
  enlarge top by=10mm,
  subtitle style={ boxrule=0.2pt,
  colback=blue!40!white}, 
  overlay={%
    \path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
    \node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{
        \textbf{\sffamily  #2}}};
    \path[fill=red!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
    \node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \thetcbcounter}}};
    \node at ([shift={(18mm,4mm)}]n2){
     \itshape\textbf{\sffamily #3}};
  },
  #1
}

\newcounter{mycounter}

%----------------------------------------------------------------------------------------
%TCOLORBOXES
%----------------------------------------------------------------------------------------


\begin{document}


\begin{mybox1}[label=one]{sample}{Gebäudeheizlast nach DIN 12831 nach Temperatur}
This is a \textbf{tcolorbox}.\par
a lot of text here ... This is Example \ref{one}
\tcbsubtitle{\textbf{ Formeln}}
some text
\end{mybox1}

\end{document}
  • 1
    Use the correct anchor: \node[anchor=west] at ([shift={(18mm,4mm)}]n2){\itshape\textbf{\sffamily #3}}; I think you'll have to reduce 18mm. – Ignasi Apr 22 '18 at 16:41
  • @Ignasi Would you like to post a short answer? – Troy May 3 '18 at 10:58
  • @Troy You have it! – Ignasi May 3 '18 at 12:42
1

The quickest solution is to select the correct anchor for title positioning (default is center) and the desired xshift. This is what is done in mybox1 in following code.

A more elaborated solution consists in replacing filled paths with superposed nodes by three nodes placed with positioning library. The left node is a rounded rectangle from symbols.misc library. Finally, text and font options has been used to adjust aspect of nodes' contents. This is what is shown in mybox2.

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}%erlaubt Umlaute
\usepackage{lmodern}
\usepackage[skins]{tcolorbox}
\usetikzlibrary{positioning, shapes.misc}

\newtcolorbox[auto counter, ]{mybox1}[3][]{
  enhanced,
  arc=.3mm, 
  boxrule=0.3pt,
 fonttitle=\bfseries,
  colback=white,
  colframe=red!65!black,
  enlarge top by=10mm,
  subtitle style={ boxrule=0.2pt,
  colback=blue!40!white}, 
  overlay={%
    \path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
    \node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{
        \textbf{\sffamily  #2}}};
    \path[fill=red!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
    \node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \thetcbcounter}}};
    \node[anchor=west] at ([shift={(8mm,4mm)}]n2){
     \itshape\textbf{\sffamily #3}};
  },
  #1
}

\newtcolorbox[auto counter]{mybox2}[3][]{
    enhanced,
    arc=.3mm, 
    boxrule=0.3pt,
    fonttitle=\bfseries,
    colback=white,
    colframe=red!65!black,
    enlarge top by=10mm,
    subtitle style={ boxrule=0.2pt,
    colback=blue!40!white}, 
    overlay={%
        \node[fill=blue!65, rounded rectangle, rounded rectangle right arc=none, anchor=south west, text=white, font=\bfseries\sffamily, minimum width=24mm, minimum height=8mm] at (frame.north west) (n2) {#2};
    \node[fill=red!65!blue, right=0pt of n2, minimum height=8mm, minimum width=7mm, text=white, font=\bfseries\sffamily] (n3) {\thetcbcounter};
    \node[anchor=west, right=0mm of n3, minimum height=8mm, font=\bfseries\itshape\sffamily] {#3};
  },
  #1
}

\newcounter{mycounter}

%----------------------------------------------------------------------------------------
%TCOLORBOXES
%----------------------------------------------------------------------------------------


\begin{document}


\begin{mybox1}[label=one]{sample}{Gebäudeheizlast nach DIN 12831 nach Temperatur}
This is a \textbf{tcolorbox}.\par
a lot of text here ... This is Example \ref{one}
\tcbsubtitle{\textbf{ Formeln}}
some text
\end{mybox1}

\begin{mybox2}[label=one]{sample}{Gebäudeheizlast nach DIN 12831 nach Temperatur}
This is a \textbf{tcolorbox}.\par
a lot of text here ... This is Example \ref{one}
\tcbsubtitle{\textbf{ Formeln}}
some text
\end{mybox2}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.