2

For a LaTeX/beamer presentation i want to add those nice lifted drop shadows which tcolorbox provides to all of my images. This worked fine so far for images included via includegraphics but not so fine for images drawn with tikzs (included via tikzpicture). The problem is, there is a spacing inside the tcolorbox between the tikzpicture and the right frame of the tcolorbox. Here is my example:

\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\begin{document}
\begin{tcolorbox}[enhanced,drop large lifted shadow,boxsep=0mm,left=0mm%
              right=0mm,top=0mm,bottom=0mm,arc=0mm,boxrule=0.5pt]%
  \begin{tikzpicture}
  \draw (0.0, 0.0) grid (5.0, 5.0);
  \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
  \end{tikzpicture}
\end{tcolorbox} 
\end{document}

This space can get drastically reduced by adding the hbox option as I recently found out:

\begin{tcolorbox}[enhanced,drop large lifted shadow,boxsep=0mm,left=0mm,hbox,% <---- added the hox option here!
              right=0mm,top=0mm,bottom=0mm,arc=0mm,boxrule=0.5pt]%

but there is still some spacing! How get I get rid of the rest?

edit: i have just noticed that tcolorbox is not the problem! The unwanted space to the right is created by Tikz. I tested this by putting the tikzpicture part only into a standalone environment and created a pdf from that (with pdflatex). The resulting pdf already had the unwanted space.

Maybe there are other reasons but tcolorbox can be ruled out though. A workaround for me at the moment is to create standalone pdfs from all of my tikzpictures (which are a lot) and then apply pdfcrop to all of them. The cropped images can be used fine within a tcolorbox then.

Oliver
  • 131
  • tcolorbox is actually a tikzpicture, you're nesting ticzpicture environments, which is not recommended, also there is a , missing in your tcolorbox options list –  Mar 29 '17 at 14:24
  • I see no spacing with a current tcolorbox (and the hbox-option). – Ulrike Fischer Mar 29 '17 at 14:38
  • hbox works for me –  Mar 29 '17 at 14:40
  • I do not know what to say, if i compile the example with hbox i get this result: http://imgur.com/a/ONI1o there is a cleary visible space to the right. – Oliver Mar 29 '17 at 14:44
  • @Oliver: What is the version of the tcolorbox package installed on your system? The newest is 4.02, released about one month ago –  Mar 29 '17 at 14:49
  • I am not sure, i use the version provided by the package management system of openSUSE tumbleweed, the package is part of Texlive. The version it provides is: 2016.113.3.91svn40792-30.2 it was last updated/patched december the 7th in 2016. – Oliver Mar 29 '17 at 14:53
  • this unwanted space that you mention appears in TikZ pictures where control points are needed. In this case, the boundinx box is wrong, because it includes all these phantom points and tcolorbox or standalone cannot crop them because they are based in tikz boundingbox. See: http://tex.stackexchange.com/questions/43621/bounding-box-is-larger-than-expected-when-drawing-a-curved-path?noredirect=1&lq=1 – Ignasi Mar 30 '17 at 14:39
  • Are you sure? Because none of the other persons answering here have problems with the bounding box in my example. I also tried manual setting the bounding box and/or adding a clip as mentioned in the link you posted, but the result was the same. So i the bounding box probably is not the issue here i guess. – Oliver Mar 30 '17 at 14:55

1 Answers1

1

This document (with the hbox) option

\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\begin{document}
\begin{tcolorbox}[enhanced,drop large lifted shadow,boxsep=0mm,left=0mm,hbox,%
              right=0mm,top=0mm,bottom=0mm,arc=0mm,boxrule=0.5pt]%
  \begin{tikzpicture}
  \draw (0.0, 0.0) grid (5.0, 5.0);
  \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
  \end{tikzpicture}
\end{tcolorbox}
\end{document}

gives this output with a current texlive 2016:

enter image description here

and this with texlive 2015

enter image description here

So there was a bug leading to bad spacing but it has been resolved, so you should update your system.

Ulrike Fischer
  • 327,261