# Let the width of a cell be set by a picture

I wish to have a table with two rows - first one with a picture, and the second is some text (I know I can probably do it within the figure environment, but I want to do it on my own). I want the text to be split whenever necessary, so I use \begin{tabular}{p{width}}. However, I decided that I want to firstly set the height of the picture, and then let the width of the scaled picture determine the width of the text cell. How can I do it?

-
“I want the text to be split whenever necessary…” Could you elaborate: Split to where? – morbusg Feb 3 '12 at 11:04

First set the picture into a box, then you can get the width of the box to use in your p argument using \settowidth (or just the \wd primitive) then use \usebox to put the picture into your table.

\documentclass{article}

\newsavebox\foo

\begin{document}

\savebox\foo{%
%\includegraphics...
a picture here}

\begin{tabular}{|p{\wd\foo}|}
\usebox\foo\\
some text here some text here
\end{tabular}

\end{document}

-
Perhaps you should elaborate on how the OP can accomplish this, perhaps an example would make things clearer. – Roelof Spijker Feb 3 '12 at 11:23
yes well if the OP had provided a MWE I'd have probably edited it with an explicit fix, but OK I'll edit my answer in a bit. – David Carlisle Feb 3 '12 at 11:27
Supplementary question on personal preferences: I would have put the \savebox in the preamble (to keep it out of the way). Would you care to comment on that? – Brent.Longborough Feb 3 '12 at 12:10
The savebox contents are logically part of the document flow and so belong after begin{document}. If it's just a graphic it probably works here (but would mean you'd need one box per table, which is expensive) but if it contains text (as in my cut down example) it's only really reliable to do it after begin{document} as that is when all the font setup is finalised. – David Carlisle Feb 3 '12 at 12:32
Thank you. It's always rewarding to learn from a Master... – Brent.Longborough Feb 3 '12 at 14:32