# newenvironment behaving differently inside another environment

Friends,

Please have a look at the code below. The problem is the environment hlcard is behaving differently when it is inside card environment, or directly under frame. I have picked the card environment directly from net, and doesn't have much clue what those long optional argument is doing. Kindly help.

The behaivour directly inside frame is the expected behaviour

\documentclass[12pt]{beamer}
\RequirePackage[many]{tcolorbox}
\definecolor{dcol}{HTML}{3F51B5}
\definecolor{BGgrey03}{RGB}{190,190,190}
\definecolor{BGgrey04}{RGB}{230,230,230}
\usecolortheme[named=dcol]{structure}
\usepackage{biblatex}

\tcbset{%
colback=BGgrey04, colbacktitle=dcol, coltitle=white, coltext=dcol,%
enhanced, sharpish corners=all,%
left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,%
title filled, boxrule=0mm, %
segmentation code={\path[draw=BGgrey01](segmentation.west) -- (segmentation.east);}%
}

\newenvironment{card}[1][pR23s2OTKY]{%
\ifthenelse{\equal{#1}{pR23s2OTKY}}{%
\begin{tcolorbox}%
}{%
\begin{tcolorbox}[colbacktitle=dcol, coltitle=white, title=#1, left=1mm, right=6mm, top=1mm,
bottom=1mm, middle=4mm, toptitle=1mm, bottomtitle=1mm, ]%
}%
}{%
\end{tcolorbox}%
}

\newenvironment{hlcard}[1][pR23s2OTKY]{%
\begin{tcolorbox}[noparskip, breakable, colback=dcol,%
coltitle=black,coltext=white, fonttitle={\bfseries \scshape}, left=1mm, right=6mm, top=1mm,
bottom=1mm, middle=4mm, toptitle=1mm, bottomtitle=1mm,]%
}{%
\end{tcolorbox}%
}

\begin{document}
\begin{frame}
\begin{card}[Problem]
\begin{hlcard}
Foo
\end{hlcard}
\end{card}
\begin{hlcard}
Bar
\end{hlcard}
\end{frame}
\end{document}


• You're nesting tcolorbox environments -- so why should hlcard look the same inside or outside of the box card, concerning skipping coming from card? Why are you using \newenvironment at all when you can use the better suited \newtcolorbox macro? Also gluing contents from the net together to something what 'might' work is not a very well-designed strategy – user31729 Oct 3 '17 at 13:02
• Thanks a lot for your comment. The reason behind not using \newtcolorbox is very simple...I was not aware of it. I have moved both the \newenvironment to \newtcoorbox. Thanks a lot for this. But, about the main problem: when it is nested, I can't find why in nested env, its getting the dark border at all. Can you kindly help? – BaRud Oct 3 '17 at 13:40
• The nested boxes are 'reset', so they are using some default values or the ones explicitly with \tcbset, which is the common 'pool' of options for all tcolorboxes. – user31729 Oct 3 '17 at 13:42

The \tcbset macro provides for .style options, i.e. collections of specific tcolorbox (or tikz/pgfkeys), otherwise any option that is not 'wrapped' in a .style is used globally and has a side effect on tcolorbox 'layers'

Nested boxes are reset, using a default setting and the global values from tcbset.

I suggest to use an outerlayer style and an innerlayer style which calls outerlayer first, then applies its own settings.

Also the environments should be defined with \newtcolorbox instead of wrapping them in \newenvironment macros.

\documentclass[12pt]{beamer}
\RequirePackage[many]{tcolorbox}
\definecolor{dcol}{HTML}{3F51B5}
\definecolor{BGgrey03}{RGB}{190,190,190}
\definecolor{BGgrey04}{RGB}{230,230,230}
\usecolortheme[named=dcol]{structure}
\usepackage{biblatex}

% Common options
\tcbset{%
left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,
}

\tcbset{
outerlayer/.style={
enhanced,
sharpish corners=all,
colbacktitle=dcol,
coltitle=white,
left=1mm,
right=6mm,
top=1mm,
bottom=1mm,
middle=4mm,
toptitle=1mm,
bottomtitle=1mm,
title filled, boxrule=0mm, %
segmentation code={\path[draw=BGgrey01](segmentation.west) -- (segmentation.east);}
},
innerlayer/.style={outerlayer,
noparskip,
breakable,
colback=dcol,%
coltitle=black,
coltext=white,
fonttitle={\bfseries \scshape},
bottomtitle=1mm}
}

\newtcolorbox{card}[1][]{%
outerlayer,
title=#1,
}

\newtcolorbox{hlcard}[1][]{%
innerlayer,
#1
}

\begin{document}
\begin{frame}
\begin{card}[Problem]
\begin{hlcard}
Foo
\end{hlcard}
\end{card}
\begin{hlcard}
Bar
\end{hlcard}
\end{frame}
\end{document}