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

includegraphics in a longtable ?

588 views
Skip to first unread message

Dan Bolser

unread,
Dec 22, 2005, 5:18:00 AM12/22/05
to
I have a problem including graphics in a longtable.

When I add graphics to a table (putting a little figure in each row), I
found that I can 'fix' the overall alignment of the row by adding a

\vspace{0px}

before the image, however this 'fix' fails in the longtable environment.


Here is an example that demonstrates what I am talking about (note that
I insert the '\vspace{0px}' using the array package);

\documentclass[a4]{article}

\usepackage{
graphicx,
longtable,
array
}

\begin{document}

%% Problem with row alignment and included figure in a table ...

\begin{tabular}{p{2em}p{4em}p{2em}}
\hline
This is some some some some&
\includegraphics[width=4em]{some.eps}&
text text text text text.\\
\hline
\end{tabular}

%% Fix suggested by sjmurdoch

\begin{tabular}{p{2em}>{\vspace{0pt}}p{4em}p{2em}}
\hline
This is some some some some&
\includegraphics[width=4em]{some.eps}&
text text text text text.\\
\hline
\end{tabular}

%% Problem with fix in 'longtable'

\setlongtables

\begin{longtable}{p{2em}>{\vspace{0pt}}p{4em}p{2em}}
\hline
This is some some some some&
\includegraphics[width=4em]{some.eps}&
text text text text text.\\
\hline
\end{longtable}

\end{document}


I have tried everything I can think of to get the above 'row' to align
properly including the image, but everything I try fails. Can you help? :)


Dan.

Ulrike Fischer

unread,
Dec 22, 2005, 6:58:06 AM12/22/05
to
Dan Bolser <dan.b...@gmail.com> schrieb:

> I have a problem including graphics in a longtable.
>
> When I add graphics to a table (putting a little figure in each row),
> I found that I can 'fix' the overall alignment of the row by adding a
>
> \vspace{0px}
>
> before the image, however this 'fix' fails in the longtable
> environment.
>


You can see where the problem lies if you use e.g. \vspace{5cm}: in the
longtable it is inserted _after_ the graphic.

When you use \vspace inside a paragraph it is inserted after the
current line. Longtable starts in p-column a paragraph and so your
\vspace comes to late.

You can use something like >{\vspace{0pt}\newline} instead.
Or \raisebox{-\height}{<graphic>}

--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.

Dan Bolser

unread,
Dec 22, 2005, 7:31:39 AM12/22/05
to Ulrike Fischer
Ulrike Fischer wrote:
> Dan Bolser <dan.b...@gmail.com> schrieb:
>
>
>>I have a problem including graphics in a longtable.
>>
>>When I add graphics to a table (putting a little figure in each row),
>>I found that I can 'fix' the overall alignment of the row by adding a
>>
>>\vspace{0px}
>>
>>before the image, however this 'fix' fails in the longtable
>>environment.
>>
>
>
>
> You can see where the problem lies if you use e.g. \vspace{5cm}: in the
> longtable it is inserted _after_ the graphic.
>
> When you use \vspace inside a paragraph it is inserted after the
> current line. Longtable starts in p-column a paragraph and so your
> \vspace comes to late.
>
> You can use something like >{\vspace{0pt}\newline} instead.
> Or \raisebox{-\height}{<graphic>}
>
>
>

Actually I found the following from the FAQ (D'oh) does the trick nicely...

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=topgraph


Most imported graphics have their base-line set at the bottom of the
picture. When using packages such as subfig, one often wants to align
figures by their tops. The following odd little bit of code does this:

\vtop{%
\vskip0pt
\hbox{%
\includegraphics{figure}%
}%
}

The \vtop primitive sets the base-line of the resulting object to that
of the first "line" in it; the \vskip creates the illusion of an empty
line, so \vtop makes the very top of the box into the base-line.

In cases where the graphics are to be aligned with text, there is a case
for making the base-line one ex-height below the top of the box, as in:

\vtop{%
\vskip-1ex
\hbox{%
\includegraphics{figure}%
}%
}

The fact is, you may choose where the base-line ends up. This answer
merely shows you sensible choices you might make.

Ulrike Fischer

unread,
Dec 22, 2005, 8:07:59 AM12/22/05
to
Dan Bolser <dan.b...@gmail.com> schrieb:

>> You can use something like >{\vspace{0pt}\newline} instead.
>> Or \raisebox{-\height}{<graphic>}

> Actually I found the following from the FAQ (D'oh) does the trick
> nicely...
>
> http://www.tex.ac.uk/cgi-bin/texfaq2html?label=topgraph
>

> \vtop{%
> \vskip0pt
> \hbox{%
> \includegraphics{figure}%

That more or less the TeX-version of the LaTeX-\raisebox solution.

0 new messages