# How to define an inner margin for a 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.

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}

• Welcome to TeX.SX! Try to use the left=, right= etc. options, with some length arguments. The boxsep option acts in addition to them – user31729 Jan 7 '15 at 20:32
• Thank you for the fast response. left/right= seems to shift e.g. text within the tcolorbox, but the embedded image remains in its place. – engineer Jan 7 '15 at 20:44
• Perhaps your image is too large? ;-) – user31729 Jan 7 '15 at 20:45
• Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Jan 7 '15 at 20:51
• Interestingly, if you specify arc in pt instead of em, all seems well. Very strange. – Steven B. Segletes Jan 7 '15 at 21:16

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}

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.

• @AboAmmar Thank you :-) Meanwhile, the sanitize procedure for font dependend units is implemented in the current version 3.40. – Thomas F. Sturm Jan 17 '15 at 18:56