[Tex/LaTex] How to define an inner margin for a tcolorbox

tcolorbox

I created a poster with the baposter class. The basic structure is defined through posterbox objects. Within these, I did embed pictures, using tcolorbox as frame.

Actual Code:

\begin{tcolorbox}[colframe=gray,colback=white,boxrule=2pt,arc=0.6em,boxsep=-1mm]
\includegraphics[width=5.8cm]{figure.eps}
\end{tcolorbox}

Minimal working example:

\documentclass[a0paper,portrait]{article}


\usepackage{tcolorbox}
\begin{document}
\title{Test}

\begin{tcolorbox}[colframe=gray,colback=white,boxrule=2pt,arc=0.6em,boxsep=-1mm]

\end{tcolorbox}
\end{document}

I did realize that the embedded image protrudes the rounded corners. How can I apply something like an inner margin? I did play with the boxsep argument, which did not seem to help.

Sorry for not providing the complete file. I would have to strip quite a lot, since the poster contains a lot of unpublished data.

rendering problem or user error?

Edit: Sorry for not providing an image! MWE also included now.
Also happens for empty tcolorboxes.


This portion added by Steven Segletes to better demonstrate the strange behavior. Changing the arc units from em to pt changes the behavior completely.

\documentclass[a0paper,portrait]{article}
\usepackage{tcolorbox}
\begin{document}
\title{Test}
\begin{tcolorbox}[colframe=gray,colback=white,boxrule=2pt,arc=.3em,boxsep=-1mm]

\end{tcolorbox}

\begin{tcolorbox}[colframe=gray,colback=white,boxrule=2pt,arc=3.4pt,boxsep=-1mm]

\end{tcolorbox}
\end{document}

enter image description here

Best Answer

There is more than one question to answer here. I try to answer them step by step.

1. How to define an inner margin for a tcolorbox?

The margins are set by left, right, top, bottom. Additionally, boxsep is added to all these values for the resulting margin.

E.g.

\begin{tcolorbox}[boxsep=1pt,left=2pt,right=2pt,top=0pt,bottom=0pt]...

gives a total of 3pt for the left and right margin, and a total of 1pt for the top and bottom margin.

2. Content clipping

If rounded corners are used, but there is no margin or a very small margin, the text content (e.g. a picture) can protrude over the rounded corners. This can be avoided by using the enhanced and clip upper options of the skins library which clip the interior:

\documentclass[a0paper,portrait]{article}
\usepackage[skins]{tcolorbox}
\begin{document}
\title{Test}

\begin{tcolorbox}[
  enhanced,clip upper,%<------------
  colframe=gray,colback=white,boxrule=2pt,arc=10pt,
  boxsep=0pt,left=0pt,right=0pt,top=0pt,bottom=0pt]
\includegraphics[width=\linewidth]{example-image}
\end{tcolorbox}

\end{document}

enter image description here

3. Font dependend units

A tcolorbox is drawn inside a pgfpicture or a tikzpicture environment. Inside such an environment, a nullfont is used. If font dependend units like arc=.3em are given, the actual sizing depends on where this setting is used exactly inside the internal implementation. If it is used (and expanded) before the actual tikzpicture, it will have the intended size, but if it is used very lately in the drawing process, it may become zero.

Using

\begin{tcolorbox}[arc=0.3em]

\end{tcolorbox}

gives an unlucky combination of this effect. The outer arc is computed automatically before the graphical environment is started. It gets the intended (expanded) size. The inner arc (i.e. arc) stays at 0.3em and becomes 0pt inside the graphical environment.

So, currently, one should use fixed units like 3pt or 3mm to avoid such effects. But, for the next tcolorbox version (3.36 or higher), I will implement a sanitize procedure which freezes font depended units before entering the graphical environment.