[Tex/LaTex] Textures or pictures as background for a table.

graphicstables

I wonder how I can set a texture or a picture in the background of a table. I have tried to google it but I haven't found any satisfactory answer 🙁

I try to explain better: I know that it is possible to put a background color in a table just by nesting a tabular environment into a \colorbox command, e.g. the command

\colorbox{COLOR}{\begin{tabular} ... \end{tabular}}

creates a tabular with a COLOR background.

Now, I wish to do the same, but instead of using a background color, I want use a background image or a background texture (e.g a "zebra"-like texture, etc). Is it possible? Does it exist some command that I can use in the same way as \colorbox, e.g.

\some_command{IMAGE}{\begin{tabular} ... \end{tabular}}

that puts IMAGE as background to the tabular? If not, how I can accomplish my goal? I hope my request is clear… :-S

Best Answer

Here's one option using the powerful tcolorbox package in combination with the also powerful tabularx. Using a style you can specify the table preamble, the image and possibly other attributes:

\documentclass{report}
\usepackage[table,dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{lipsum}

\tcbset{
bgtable/.style={
enhanced,
colframe=red!50!black,
colbacktitle=Salmon!30,
coltitle=black,
center title,
fonttitle=\bfseries\sffamily,
watermark graphics=#1,
watermark opacity=0.3,
nobeforeafter}
}

\begin{document}

\noindent\begin{tcolorbox}[bgtable=mushrooms.jpg,tabularx*={}{XXXXX},title=My table,watermark stretch=1.00]
One & Two & Three & Four & Five\\
\midrule
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
\end{tcolorbox}

\noindent\begin{tcolorbox}[bgtable=ctanlion.png,tabularx*={}{XXXXX},title=My table,watermark stretch=1.00,width=8cm,watermark opacity=0.3]
One & Two & Three \\
\midrule
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
\end{tcolorbox}

\end{document}

enter image description here

Or, if you prefer a more sober style:

\documentclass{report}
\usepackage[table,dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{lipsum}

\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 opacity=0.3,
arc=0pt,
outer arc=0pt,
nobeforeafter}
}

\begin{document}

\noindent\begin{tcolorbox}[bgtable=papiro.png,tabularx*={}{XXXXX},watermark opacity=0.6]
One & Two & Three & Four & Five\\
\midrule
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
\bottomrule
\end{tcolorbox}

\noindent\begin{tcolorbox}[bgtable=papiro.png,tabularx*={}{XXXXX},title=My table,watermark stretch=1.00,width=8cm,watermark opacity=0.6]
One & Two & Three \\
\midrule
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
1000.00 & 2000.00 & 3000.00 \\
\bottomrule
\end{tcolorbox}

\end{document}

enter image description here

A third example:

\documentclass{report}
\usepackage[table,dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{lipsum}

\tcbset{
bgtable/.style={
freelance,
frame code={}
center title,
fonttitle=\bfseries\sffamily,
fontupper=\bfseries\sffamily,
watermark graphics=#1,
watermark stretch=1.00,
watermark opacity=1,
arc=0pt,
outer arc=0pt,
nobeforeafter,
coltext=white}
}

\begin{document}

\noindent\begin{tcolorbox}[bgtable=drops.jpeg,tabularx*={\arrayrulecolor{white}}{XXXXX}]
One & Two & Three & Four & Five\\
\midrule
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
1000.00 & 2000.00 & 3000.00 & 4000.00 & 5000.00 \\
\end{tcolorbox}

\end{document}

enter image description here

CTAN lion drawing by Duane Bibby.

Related Question