Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

figure with caption in table cell

129 views
Skip to first unread message

vamp...@gmail.com

unread,
Dec 12, 2007, 5:00:40 AM12/12/07
to
Hi,

i try to get a figure with a caption with entry to the list of figures
inside a table cell, but unfortunately I don't get it managed. Could
someone please give me the code that does the trick?

Regards,
Vampire

Robin Fairbairns

unread,
Dec 12, 2007, 5:35:43 AM12/12/07
to

the relevant code is trivial (see, for example,
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=figurehere)

however, istm there's a very high probability that you're doing
something that would better be done some other way.

have you looked at the subfig package? or, if you're good at reading
docs, floatrow?
--
Robin Fairbairns, Cambridge

vamp...@gmail.com

unread,
Dec 12, 2007, 6:11:19 AM12/12/07
to
On 12 Dez., 11:35, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:

> vampi...@gmail.com writes:
> >i try to get a figure with a caption with entry to the list of figures
> >inside a table cell, but unfortunately I don't get it managed. Could
> >someone please give me the code that does the trick?
>
> the relevant code is trivial (see, for example,http://www.tex.ac.uk/cgi-bin/texfaq2html?label=figurehere)

>
> however, istm there's a very high probability that you're doing
> something that would better be done some other way.
>
> have you looked at the subfig package? or, if you're good at reading
> docs, floatrow?
> --
> Robin Fairbairns, Cambridge

I already tried things similar to

\begin{center}
\includegraphics{foo}
\captionof{figure}{caption text}
\label{fig:nonfloat}
\end{center}

which is mentioned in your link and tried it again now. But if i use
it i get a bunch of errors starting with "! Misplaced \noalign." as
soon as \captionof is inserted. And the same is true with the H-
figure.
The subfig package also doesn't help. It tells me "\subfloat outside
float"

Maybe i should have mentioned that it is not a table environment but a
longtable environment, sorry.

Robin Fairbairns

unread,
Dec 12, 2007, 6:46:12 AM12/12/07
to
vamp...@gmail.com writes:
>On 12 Dez., 11:35, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:
>> vampi...@gmail.com writes:
>> >i try to get a figure with a caption with entry to the list of figures
>> >inside a table cell, but unfortunately I don't get it managed. Could
>> >someone please give me the code that does the trick?
>>
>> the relevant code is trivial (see, for example,http://www.tex.ac.uk/cgi-bin/texfaq2html?label=figurehere)
>>
>> however, istm there's a very high probability that you're doing
>> something that would better be done some other way.
>>
>> have you looked at the subfig package? or, if you're good at reading
>> docs, floatrow?
>
>I already tried things similar to
>
>\begin{center}
> \includegraphics{foo}
> \captionof{figure}{caption text}
> \label{fig:nonfloat}
>\end{center}
>
>which is mentioned in your link and tried it again now. But if i use
>it i get a bunch of errors starting with "! Misplaced \noalign." as
>soon as \captionof is inserted. And the same is true with the H-
>figure.

for goodness' sake -- you're in a tabular -- use cell alignment for
the centring of your image. (use \multicolumn{1}{c}{...} if really
necessary.) even if it worked, the center environment would produce
ugly additional vertical space..

>The subfig package also doesn't help. It tells me "\subfloat outside
>float"

because you're not using it correctly, presumably.

>Maybe i should have mentioned that it is not a table environment but a
>longtable environment, sorry.

it does always help to tell us what the problem _really_ is. it's why
we recommend people to read

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=askquestion+minxampl
--
Robin Fairbairns, Cambridge

vamp...@gmail.com

unread,
Dec 12, 2007, 7:04:00 AM12/12/07
to

I wouldn't use the center environment in this place but the
multicolumn macro. I just copied the example that was listed on the
page that you linked to.

And how do I use it correctly?

Neither

\begin{longtable}[c]{|r|l|}
\hline
Image & \subfloat[testcaption]{
\includegraphics[keepaspectratio=true,
width=20pt,
totalheight=20pt]
{Navigone.png}
}
\hline
\end{longtable}

nor

\begin{longtable}[c]{|r|l|}
\hline
Image & \subfloat[testcaption]{
\begin{figure}[h]
\includegraphics[keepaspectratio=true,
width=20pt,
totalheight=20pt]
{Navigone.png}
\end{figure}
}
\hline
\end{longtable}

works.
Both give me the error "\subfloat outside float"

Robin Fairbairns

unread,
Dec 12, 2007, 7:22:12 AM12/12/07
to
vamp...@gmail.com writes:
>On 12 Dez., 12:46, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:
>> vampi...@gmail.com writes:
>> for goodness' sake -- you're in a tabular -- use cell alignment for
>> the centring of your image. (use \multicolumn{1}{c}{...} if really
>> necessary.) even if it worked, the center environment would produce
>> ugly additional vertical space..
>
>I wouldn't use the center environment in this place but the
>multicolumn macro. I just copied the example that was listed on the
>page that you linked to.

no comment.

>And how do I use it correctly?

i presume you mean subfig?

>Neither
>
>\begin{longtable}[c]{|r|l|}
> \hline
> Image & \subfloat[testcaption]{
> \includegraphics[keepaspectratio=true,
> width=20pt,
> totalheight=20pt]
> {Navigone.png}
> }
> \hline
>\end{longtable}
>
>nor
>
>\begin{longtable}[c]{|r|l|}
> \hline
> Image & \subfloat[testcaption]{
> \begin{figure}[h]
> \includegraphics[keepaspectratio=true,
> width=20pt,
> totalheight=20pt]
> {Navigone.png}
> \end{figure}
> }
> \hline
>\end{longtable}
>
>works.
>Both give me the error "\subfloat outside float"

as would be expected. subfig enables you to arrange multiple
subfloats inside a float. it expects to be inside a float, not a
table. i mentioned it as part of my speculation that you were putting
things in a tabular because you wanted to arrange several figures on
the same page. now you've bothered to tell us you're after something
else, it's clear that subfig is useless for your requirements.

as always with computers, you have an example of gigo, from me.
--
Robin Fairbairns, Cambridge

vamp...@gmail.com

unread,
Dec 12, 2007, 7:48:20 AM12/12/07
to

Ok, then freshly from the beginning.

I want to have a longtable environment with mostly text. Some of the
cells should contain images for clarification. These images should
have captions.

A simple example:

\begin{longtable}[c]{|r|l|}
\hline

Image & \includegraphics[keepaspectratio=true,


width=20pt,
totalheight=20pt]
{Navigone.png}\\
\hline
\end{longtable}

In this example i want to add a caption to the Navigone.png figure and
also want the figure to be listed in the list of figures.
I hope my question is clear now.

Btw. if i use \multicolumn{1}{c}{...} to center the image in the cell,
the righthand vertical line disappears for that cell. Is there a way
to make that work?

Regards,
Vampire

Robin Fairbairns

unread,
Dec 12, 2007, 10:32:16 AM12/12/07
to
vamp...@gmail.com writes:
>I want to have a longtable environment with mostly text. Some of the
>cells should contain images for clarification. These images should
>have captions.
>
>A simple example:
>
>\begin{longtable}[c]{|r|l|}
> \hline
> Image & \includegraphics[keepaspectratio=true,
> width=20pt,
> totalheight=20pt]
> {Navigone.png}\\
> \hline
>\end{longtable}

you're overspecifying, there. either drop the keepaspectratio or one
of the dimensions; i don't actually remember the rules if the
dimensions say not to preserve the aspect ratio, but you also ask to
retain it.

>In this example i want to add a caption to the Navigone.png figure and
>also want the figure to be listed in the list of figures.
>I hope my question is clear now.

where actually do you want the caption? in a separate column, or
under the image in its column?

anyway, i've written an even-more-stripped-down version of capt-of for
you

http://www.cl.cam.ac.uk/~rf10/latex/caption-text.sty

which defines \capttext, which you use as

\capttext{figure}{caption} % or
\capttext{figure}[short for lof]{real caption}

let me know if it does what you need, and i'll install it on ctan.

>Btw. if i use \multicolumn{1}{c}{...} to center the image in the cell,
>the righthand vertical line disappears for that cell. Is there a way
>to make that work?

\multicolumn{1}{c|}{...}

(the standard answer is not to add the clutter of vertical rules...
read the documentation of the booktabs package -- an excellent essay
on the design of tables.)
--
Robin Fairbairns, Cambridge

David Kastrup

unread,
Dec 12, 2007, 11:15:40 AM12/12/07
to
rf...@cl.cam.ac.uk (Robin Fairbairns) writes:

> vamp...@gmail.com writes:
>>I want to have a longtable environment with mostly text. Some of the
>>cells should contain images for clarification. These images should
>>have captions.
>>
>>A simple example:
>>
>>\begin{longtable}[c]{|r|l|}
>> \hline
>> Image & \includegraphics[keepaspectratio=true,
>> width=20pt,
>> totalheight=20pt]
>> {Navigone.png}\\
>> \hline
>>\end{longtable}
>
> you're overspecifying, there. either drop the keepaspectratio or one
> of the dimensions;

Huh? The whole point of keepaspectratio is to declare how to treat the
overspecification of dimensions.

> i don't actually remember the rules if the dimensions say not to
> preserve the aspect ratio, but you also ask to retain it.

Well, why would he need to ask when just giving one dimension?

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>

vamp...@gmail.com

unread,
Dec 12, 2007, 11:45:40 AM12/12/07
to
On 12 Dez., 16:32, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:

> vampi...@gmail.com writes:
> >I want to have a longtable environment with mostly text. Some of the
> >cells should contain images for clarification. These images should
> >have captions.
>
> >A simple example:
>
> >\begin{longtable}[c]{|r|l|}
> > \hline
> > Image & \includegraphics[keepaspectratio=true,
> > width=20pt,
> > totalheight=20pt]
> > {Navigone.png}\\
> > \hline
> >\end{longtable}
>
> you're overspecifying, there. either drop the keepaspectratio or one
> of the dimensions; i don't actually remember the rules if the
> dimensions say not to preserve the aspect ratio, but you also ask to
> retain it.

Besides that it is only an example, I don't overspecify. These three
arguments ensure that the image keeps its aspect ratio and is at most
20pt by 20pt. If I drop the keepaspectratio, the image is distorted to
be exactly 20pt by 20pt and if I drop one of the dimensions, I could
also drop keepaspectratio because it doesn't do anything in that case.
The problem then is that one dimensions could exceed the 20pt. The
keepaspectratio only makes sense with both dimensions as it is made
for that.

> >In this example i want to add a caption to the Navigone.png figure and
> >also want the figure to be listed in the list of figures.
> >I hope my question is clear now.
>
> where actually do you want the caption? in a separate column, or
> under the image in its column?

Under the image in its column

> anyway, i've written an even-more-stripped-down version of capt-of for
> you
>
> http://www.cl.cam.ac.uk/~rf10/latex/caption-text.sty
>
> which defines \capttext, which you use as
>
> \capttext{figure}{caption} % or
> \capttext{figure}[short for lof]{real caption}
>
> let me know if it does what you need, and i'll install it on ctan.

Besides that the caption appears next to the image and not below and
that it would be nice if the formatting of the "caption" packet and
the localization of the "babel" package are used. :-)

> >Btw. if i use \multicolumn{1}{c}{...} to center the image in the cell,
> >the righthand vertical line disappears for that cell. Is there a way
> >to make that work?
>
> \multicolumn{1}{c|}{...}

Great, thanks. Besides that it doesn't work well with the code I
borrowed and modified from the l2picfaq

\newlength{\imagewidth}
\newlength{\imageheight}

\newcommand{\setimagesize}[2][\relax]{
\settowidth{\imagewidth}{\includegraphics[{#1}]{#2}}
\settoheight{\imageheight}{\includegraphics[{#1}]{#2}}
}

\newcommand{\includegraphicstotab}[2][\relax]{
\setimagesize[{#1}]{#2}
\parbox[c][1.1\imageheight][c]{\imagewidth}{
\includegraphics[{#1}]{#2}
}
}

Unfortunately the parbox has the wrong width and therefore it is not
exactly centered.

>
> (the standard answer is not to add the clutter of vertical rules...
> read the documentation of the booktabs package -- an excellent essay
> on the design of tables.)

thanks, I will do so.

Regards,
Vampire

Robin Fairbairns

unread,
Dec 12, 2007, 11:58:37 AM12/12/07
to
vamp...@gmail.com writes:
>On 12 Dez., 16:32, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:
>> where actually do you want the caption? in a separate column, or
>> under the image in its column?
>
>Under the image in its column
>
>> anyway, i've written an even-more-stripped-down version of capt-of for
>> you

i should have pointed out that it does *no* formatting of anything,
just creates the text of the caption.

>> let me know if it does what you need, and i'll install it on ctan.
>
>Besides that the caption appears next to the image and not below and

so put it below

>that it would be nice if the formatting of the "caption" packet and
>the localization of the "babel" package are used. :-)

what localisation? where appropriate, it uses the code of latex for
setting captions, which is what babel diddles with. if you want
caption.sty formatting, do it yourself, or get someone else to do it
for you. i don't propose to learn the insides of caption.sty to save
you the bother of doing the same thing.

>[...] Besides that it doesn't work well with the code I


>borrowed and modified from the l2picfaq

i read german so slowly that i've never actually completed reading
l2picfaq. perhaps someone more fluent in the language can help
(everyone who ever taught me german is now dead ... my last lesson was
in 1960...)
--
Robin Fairbairns, Cambridge

vamp...@gmail.com

unread,
Dec 13, 2007, 5:00:17 AM12/13/07
to
On 12 Dez., 17:58, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:

> vampi...@gmail.com writes:
> >On 12 Dez., 16:32, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:
> >> where actually do you want the caption? in a separate column, or
> >> under the image in its column?
>
> >Under the image in its column
>
> >> anyway, i've written an even-more-stripped-down version of capt-of for
> >> you
>
> i should have pointed out that it does *no* formatting of anything,
> just creates the text of the caption.
>
> >> let me know if it does what you need, and i'll install it on ctan.
>
> >Besides that the caption appears next to the image and not below and
>
> so put it below
>
> >that it would be nice if the formatting of the "caption" packet and
> >the localization of the "babel" package are used. :-)
>
> what localisation? where appropriate, it uses the code of latex for
> setting captions, which is what babel diddles with. if you want
> caption.sty formatting, do it yourself, or get someone else to do it
> for you. i don't propose to learn the insides of caption.sty to save
> you the bother of doing the same thing.

Okok, I didn't want to make you more work than necessary. I thought
maybe you know how to do it easily.

> >[...] Besides that it doesn't work well with the code I
> >borrowed and modified from the l2picfaq
>
> i read german so slowly that i've never actually completed reading
> l2picfaq. perhaps someone more fluent in the language can help
> (everyone who ever taught me german is now dead ... my last lesson was
> in 1960...)

I quoted the code I used. It is meant for vertically centering the
image in the table cell.

Ulrike Fischer

unread,
Dec 13, 2007, 6:19:05 AM12/13/07
to
Am Wed, 12 Dec 2007 08:45:40 -0800 (PST) schrieb vamp...@gmail.com:


> Great, thanks. Besides that it doesn't work well with the code I
> borrowed and modified from the l2picfaq
>
> \newlength{\imagewidth}
> \newlength{\imageheight}
>
> \newcommand{\setimagesize}[2][\relax]{
> \settowidth{\imagewidth}{\includegraphics[{#1}]{#2}}
> \settoheight{\imageheight}{\includegraphics[{#1}]{#2}}
> }
>
> \newcommand{\includegraphicstotab}[2][\relax]{
> \setimagesize[{#1}]{#2}
> \parbox[c][1.1\imageheight][c]{\imagewidth}{
> \includegraphics[{#1}]{#2}
> }
> }
>
> Unfortunately the parbox has the wrong width and therefore it is not
> exactly centered.

You should pay more attention to the spaces in your input. Some of
them matters. Use more %-sign:

\parbox[c][1.1\imageheight][c]{\imagewidth}{%
\includegraphics[{#1}]{#2}%
}

--
Ulrike Fischer

vamp...@gmail.com

unread,
Dec 13, 2007, 8:32:31 AM12/13/07
to
On 13 Dez., 12:19, Ulrike Fischer <ne...@nililand.de> wrote:

Great, now it works much better, thanks Ulrike.
When does space matter? Is there any good documentation? :-)

Mariano Suárez-Alvarez

unread,
Dec 13, 2007, 5:38:40 PM12/13/07
to

You can always look in the TeXbook or Victor Eijkhouy's
TeX by Topic <http://www.eijkhout.net/tbt/>...

-- m

0 new messages