# How to get the natural height of a box in tcolorbox

I need to do some calculation in which the actural height of a tcolorbox has to be introduced(Please see the following code for my purpose). I wonder if there is such a macro(\macro in my code as an example, not \tcbtextheight) to store the value of the actual box height.

\documentclass[12pt,a4paper]{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{tcolorbox}[
lefthand width=3em,
arc=3mm,
boxrule=0pt,sidebyside,enhanced,
colback=green!60,
bicolor,colbacklower=gray,
collower=white,
underlay={
\path[fill=green!60]
(segmentation.south) -- ++(0.5\macro,0.5\macro)--(segmentation.north);},
]
Upper
\tcblower
\quad This is the lower part.
\end{tcolorbox}

\end{document}


From above code, I want to get the following effect

In this examples, the cleanest way is to extract the height dimension from segmentation. Therefore,

\tcbsetmacrotoheightofnode\macro{segmentation}


will do the trick.

The full code is:

\documentclass[12pt,a4paper]{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{tcolorbox}[
lefthand width=3em,
arc=3mm,
boxrule=0pt,sidebyside,enhanced,
colback=green!60,
bicolor,colbacklower=gray,
collower=white,
underlay={
\tcbsetmacrotoheightofnode\macro{segmentation}
\path[fill=green!60]
(segmentation.south) -- ++(\dimexpr0.5\dimexpr\macro,\dimexpr0.5\dimexpr\macro)--(segmentation.north);},
]
Upper
\tcblower
\quad This is the lower part.
\end{tcolorbox}

\end{document}


Of course, this will not look good, if the box becomes too large. The solution of Ignasi gives no rectangular angle, but is more stable for different heights.

• Many thanks for your simple and perfect soluntion. Yet, I change "-- ++(\dimexpr0.5\dimexpr\macro,\dimexpr0.5\dimexpr\macro)" by " --([xshift=0.5\dimexpr\macro]segmentation.center)", the typeset gives no rectangle angle which I think it should be (as the height and width are equal). Could you tell me the cause? – lyl Sep 18 '17 at 8:35
• And If the upper/lower parts are not sidebyside, how to get the natual height of a box? – lyl Sep 18 '17 at 8:46
• For your changed code, you missed a \dimexpr before 0.5. – Thomas F. Sturm Sep 18 '17 at 11:12
• The node frame can alternatively used for the height of the whole box (even without lower part), i.e. \tcbsetmacrotoheightofnode\macro{frame} – Thomas F. Sturm Sep 18 '17 at 11:13
• Could you tell me why \dimexpr must be used before 0.5 and what the unit is for \tcbsetmacrotoheightofnode\macro{frame,segmentation etc},only a value? or a length? – lyl Sep 18 '17 at 13:14

Like this?

\documentclass[12pt,a4paper]{article}
\usepackage[most]{tcolorbox}
%\tcbuselibrary{skins}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{tcolorbox}[
enhanced,
lefthand width=3em,
arc=3mm,
boxrule=0pt,sidebyside,enhanced,
colback=green!60,
bicolor,colbacklower=gray,
collower=white,
underlay={
\path[fill=green!60]
(segmentation.south) -- ([xshift=5mm]segmentation.center)--(segmentation.north)--cycle;},
]
Upper
\tcblower
\quad This is the lower part.
\end{tcolorbox}
\end{document}


Update:

It's possible to draw an arrow proportional to box height with calc tikzlibrary help.

\documentclass[12pt,a4paper]{article}
\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\usepackage{lipsum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newtcolorbox{mybox}[1][]{%
enhanced,
lefthand width=3em,
arc=3mm,
boxrule=0pt,sidebyside,enhanced,
colback=green!60,
bicolor,
colbacklower=gray,
collower=white,
underlay={
\path[fill=green!60]
let \p1=($(segmentation.north)-(segmentation.south)$),
\n2={veclen(\x1,\y1)} in
(segmentation.south) --
([xshift=\n2/2]segmentation.center) --
(segmentation.north)
{[rounded corners]-|(frame.west)|-(segmentation.south)}--
cycle;},
#1
}

\begin{document}
\begin{mybox}
Upper
\tcblower