1

I would like to create a template for my tcolorboxes in my thesis, but I dont seem to get the options to work properly. Here my MWE (the first tcolorbox is the one not using the \newtcolorbox command, just showing the result i want to achieve, and the second is using the \newtcolorbox:

\documentclass[openany,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tcolorbox} 

\definecolor{Carmine}{HTML}{960018}%define a color  for code blocks [background Latex Code]


\newtcolorbox{mybox2}[3][Heading]
{
title= \textbf{#1},
colback=#2!5!white, %background color box
colframe=red!50!black, %framecolor box
colbacktitle=#3!85!white, %backgroundcolor titile box
coltitle=white, %color title
%sharp corners,
arc=.3mm, 
fonttitle=\bfseries,
}

\begin{document}

\begin{tcolorbox}[%
colback=red!5!white, %background color box
colframe=red!50!black, %framecolor box
colbacktitle=Carmine!85!white, %backgroundcolor titile box
coltitle=white, %color title
%sharp corners,
arc=.3mm, 
fonttitle=\bfseries,
title= \textbf{Gaspreisfunktion},
]
Zusammensetzung einer \textbf{Indexformel}.
\end{tcolorbox}

\vspace{2cm}


\begin{mybox2}{Uberschrift}{red}{Carmin}
Zusammensetzung einer \textbf{Indexformel}
\end{mybox2}


\end{document}
5
  • 1
    \begin{mybox2}[Uberschrift]{red}{Carmine} should give you the desired result.
    – leandriis
    Commented Apr 21, 2018 at 13:20
  • While possible I don't recommend numbers in environment names
    – user31729
    Commented Apr 21, 2018 at 13:47
  • Merci, I was searching for a proper treatise/ paper detailing the subtleties of using /newcommand since I surmise /newtcolorbox follows the same rules. Something like a documentation for the usepackages to thourougly study and understand the topic "use of newcommand" with all subtleties. Unfortunately I was not able to find a comprehensive paper covering just this topic. Any chance some can give me a hint/ link to auch a paper?
    – aerioeus
    Commented Apr 21, 2018 at 14:08
  • tcolorbox has a pretty manual. We call it documentation and not papers, however.
    – user31729
    Commented Apr 21, 2018 at 14:16
  • @ChristianHupfer thank you, thats was I was looking for
    – aerioeus
    Commented Apr 21, 2018 at 16:33

1 Answer 1

2

\newtcolorbox{foo}[3][Heading} defines a tcolorbox with one optional argument (the first one!), to be used with [...] and two mandatory arguments with {} pairs.

The usage

\begin{mybox2}{Uberschrift}{red}{Carmin} is wrong then, it must be \begin{mybox2}[Uberschrift]{red}{Carmine}, also correcting the typo for Carmine.

\documentclass[openany,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tcolorbox} 

\definecolor{Carmine}{HTML}{960018}%define a color  for code blocks [background Latex Code]


\newtcolorbox{mybox2}[3][Heading]{
  title= \textbf{#1},
  colback=#2!5!white, %background color box
  colframe=red!50!black, %framecolor box
  colbacktitle=#3!85!white, %backgroundcolor titile box
  coltitle=white, %color title
  % sharp corners,
  arc=.3mm, 
  fonttitle=\bfseries,
}

\begin{document}

\begin{tcolorbox}[%
  colback=red!5!white, %background color box
  colframe=red!50!black, %framecolor box
  colbacktitle=Carmine!85!white, %backgroundcolor titile box
  coltitle=white, %color title
  % sharp corners,
  arc=.3mm, 
  fonttitle=\bfseries,
  title= \textbf{Gaspreisfunktion},
  ]
  Zusammensetzung einer \textbf{Indexformel}.
\end{tcolorbox}

\vspace{2cm}


\begin{mybox2}[Uberschrift]{red}{Carmine}
Zusammensetzung einer \textbf{Indexformel}
\end{mybox2}


\end{document}

enter image description here

You must log in to answer this question.

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