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
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.
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
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"
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
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
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
> 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>
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
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
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.
> 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
Great, now it works much better, thanks Ulrike.
When does space matter? Is there any good documentation? :-)
You can always look in the TeXbook or Victor Eijkhouy's
TeX by Topic <http://www.eijkhout.net/tbt/>...
-- m