I am creating a table with special dates and a background image, like this one.
I want to automatize the process, and create tables with different heights, but using the same background image. My solution is to have a long image inside a tcolorbox
, where the upper section of the image is just an homogeneous color. Then, I want tex to crop it automatically, according to the size of the table. My chosen background image is here (as you can see, I simple extended the original, shorter image).
My code is the following:
\documentclass{report}
\usepackage[table,dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{booktabs}
\tcbset{
bgtable/.style={
freelance,
frame code={\draw[ultra thick] (interior.north west) -- (interior.north east);}
center title,
fonttitle=\bfseries\sffamily,
watermark graphics=#1,
watermark stretch=1.00,
%watermark zoom=1.0,
clip lower,
arc=0pt,
outer arc=0pt,
nobeforeafter}
}
\begin{document}
\begin{tcolorbox}[bgtable=Winter_term_card.png]
\begin{tabular*}{11cm}{c c}
\multicolumn{2}{c}{\large\textbf{Second Term}} \\
\textbf{Week 1} & \\
\midrule{1-2}
06/01 & \textbf{Wed:} Event 1 blah blah. \\
\textbf{Week 2} & \\
\midrule{1-2}
16/01 & \textbf{Fri:} Event 2 blah blah. \\
\textbf{Week 3} & \\
\midrule
21/01 & \textbf{Mon:} Event 3 blah blah. \\
\bottomrule
\end{tabular*}
\vspace{2cm}
\end{tcolorbox}
\end{document}
Yet, the image is not being clipped. Instead, the image shrinks to occupy the whole of the tcolorbox
space. The result is this:
Any idea how to proceed? I just can't get it to work.
Best Answer
As OP mentions,
tcolorbox
sectionClip Environments
provides a solution. Following code is just an adaptation ofpicturebox
environment in page 166.picturebox
has a mandatory parameter which is the background image. This image is scaled to cover tcolorbox width but keeping the aspect ratio. As you can see provided image shows a long upper part almost uniformTherefore I preferred to define the background of the tcolorbox showing the image from bottom to top, this way is easy to observe how taller boxes include larger part of picture but without scaling it.
The solution uses a
tcbclipenvironment
with anode
whichincludegraphics
instead of thewatermark
option proposed in original code.