11

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

  • Welcome to TeX.SX! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. – Adam Liter Aug 14 '13 at 16:49
  • Also, you can format inline code by using backticks ` and blocks of code by indenting four spaces (or highlighting the code and clicking on the {} button in the editor). This helps to make the posts clearer and easier to read. – Adam Liter Aug 14 '13 at 16:51
13

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.

  • I got an error: Unknown option most' for package tcolorbox' – schmendrich Aug 14 '13 at 18:18
  • @schmendrich you need an up-dated version of the package; in my system (TeX Live2013) I have tcolorbox.sty 2013/07/29 version 2.50 text color boxes. – Gonzalo Medina Aug 14 '13 at 18:21
  • Wow, that is fast development. I have version 2.2 and it is only 2 month older. – schmendrich Aug 14 '13 at 18:28
  • @schmendrich yes, the author has been very active. Newer versions offer a lot of new useful features. – Gonzalo Medina Aug 14 '13 at 18:30
  • 4
    That's a very nice looking solution! – Steven B. Segletes Aug 14 '13 at 19:53
7
\documentclass{article}
\usepackage{stackengine}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\bottominset{%
\color{magenta}%
\Huge%
\begin{tabular}{|c|c|c|}
\hline
This & is & a \\
\hline
test & of & tabular\\
\hline
inset & into & graphics\\
\hline
is & this & what \\
\hline
 is & & needed?\\
\hline
& & today\\
\hline
\end{tabular}%
}{%
\scalebox{.66}{\includegraphics{sbs2}}%
}{1.4in}{}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.