Thanks to flav.
Transparent background in tcolorbox is only possible with the skin key standard jigsaw
. Otherwise there is no effect of the key opacityback=0
\documentclass{article}
\usepackage{xcolor}
\usepackage{pagecolor}
\pagecolor{yellow}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}[
standard jigsaw,
title=Title,
opacityback=0, % this works only in combination with the key "standard jigsaw"
]
This should have transparent backround. \\
Background should look yellow.
\end{tcolorbox}
\end{document}
I suggest to define a separate style for this, say mysubtitle
.
(I've changed Arash Esbati's proposition 'slightly')
Since \tcbsubtitle
itself is a tcolorbox
, it accepts the same options like the outer box.
The most crucial option (in my point of view) is top=0pt
(for example) and nobeforeafter
for the subtitle.
Since tcbsubtitle
is tcbox
, fontupper
instead of fonttitle
has to be used, as well as colback
.
\documentclass[]{article}
\usepackage[most]{tcolorbox}
\usepackage{xcolor}
\definecolor{commentgreen}{HTML}{E0E5C1}
\newtcolorbox{commentbox}[2][]{
frame hidden,
boxrule=0pt,
breakable,
enhanced,
before skip=8pt plus 1pt,
toptitle=3mm,
boxsep=0.25ex,
left=8pt,
right=8pt,
arc=0mm,
fonttitle=\fontfamily{fosj}\selectfont\scshape\bfseries\color{black},
fontupper=\fontfamily{lmss}\selectfont,
title=#2,
parbox = false,
colback=commentgreen,
colframe=commentgreen,
colbacktitle=commentgreen,
after={\vspace{5pt plus 1pt}\noindent},
#1
}
\tcbset{mysubtitle/.style={subtitle style={fontupper={\fontfamily{fosj}\selectfont\itshape\scriptsize\color{black}},nobeforeafter,top=0pt,colback={commentgreen}},top=0pt}}
\begin{document}
\begin{commentbox}[mysubtitle]{Title}
\tcbsubtitle{Sub-title}
Main Text is going to be here
\end{commentbox}
\end{document}
Best Answer
This is really wierd and is probably a bug. The hack in the code below fixes the problem to produce:
but I don't understand what is happening. The
before skip=...
is supposed to take care of this but adjusting the skip amount alone does not fix the problem. Similarly, it should be possible to do this using only a\vskip
command but I could not get this to work either. I was only able to fix the problem by having both a\vskip
and abefore skip
. Here's the hack:You may need to adjust the
\vskip
amount as I think that-\baselineskip
puts the subtitle a fraction too high, but using this was more asthetically pleasing than choosing a random distance.