# Vertical alignment of images in longtable

I am trying to create a longtable where the first column contains only images. The longtable is defined as (with only one row):

\begin{longtable}{m{0.2\linewidth} m{0.7\linewidth}}
\hline
\includegraphics[keepaspectratio,width=\linewidth]{RectSolid.eps} & \!\begin{aligned} A &= b\cdot{}h\\ P &= 2(b+h)\\ y &= \dfrac{h}{2}\\ I_y &= \dfrac{1}{12}b\cdot{}h^3 \end{aligned}
\\\hline
\end{longtable}


The result I get is (the image is tightly cropped, with no white-space padding):

It seems as though the image's baseline is at its bottom, so that it rests at the midpoint of the row. Or perhaps longtable expects text and therefore places the basepoint not at the midpoint, but at "midpoint - textHeight". Regardless, this is clearly not good enough.

I've seen at Vertical aligning in longtable environment the suggestion of using \raisebox{-\height}{\includegraphics{....}} (or \normalbaselineskip-\height or, on my own 0.5\height), but the results aren't much better:

Another suggestion given in a comment by @egreg in that link is the use of adjustbox, but I unfortunately can't even see if that'd work for me because I'm forced to use a .cls file given by my university which doesn't compile with that package (the university's .cls file is garbage, using a bunch of depreciated packages).

So the question is: is it possible to vertically align figures in a longtable without the adjustbox package? It doesn't need to be the longtable package, but the table needs to span multiple pages. So if there's some other package that pulls that off, I'm willing to give it a try.

EDIT 1: People have asked for a MWE, so here it is. I placed it in the public directory of my Dropbox and it can be downloaded here. I can't simply put the code because the \documentclass is given by my university's .cls file (ThesisPKKN2, which is actually a modification of the original I created to use subcaption instead of the outdated subfigure package).

EDIT 2: The MWE linked above actually uses Andrew Swann's idea of \vcenter, but even though it clearly works wonders in the example he presents, in my case this is the result:

\begin{longtable}{m{0.2\linewidth} m{0.7\linewidth}}
\hline
$\vcenter{\includegraphics[keepaspectratio,width=\linewidth]{RectSolid.eps}}$ & \!\begin{aligned} A &= b\cdot{}h\\ P &= 2(b+h)\\ y &= \dfrac{h}{2}\\ I_y &= \dfrac{1}{12}b\cdot{}h^3 \end{aligned}
\\\hline
\end{longtable}


I'd say this is the best result so far, but there still seems to be more space below than above the image.

EDIT 3: Here is the MWE code itself.

\documentclass[dissertacao,brazil]{ThesisPKKN2}
\usepackage{array}
\usepackage{amsmath}
\usepackage{epstopdf}
\usepackage{etoolbox}
\usepackage{fixltx2e}
\usepackage{longtable}
\graphicspath{{./figures/}} % graphicx

\begin{document}
\begin{longtable}{m{0.2\linewidth} m{0.7\linewidth}}
\hline
$\vcenter{\includegraphics[keepaspectratio,width=\linewidth]{RectSolid.eps}}$ & \!\begin{aligned} A &= b\cdot{}h\\ P &= 2(b+h)\\ y &= \dfrac{h}{2}\\ I_y &= \dfrac{1}{12}b\cdot{}h^3 \end{aligned}
\\\hline
\end{longtable}
\end{document}


EDIT 4: As commented, I just realized this is an issue using GIMP, not with TeX. My trimmed image is getting massive padding around it which is what is causing the image to be off-center. For whatever reason, this image

when exported into .eps and placed in TeX becomes

Regardless, this is a GIMP issue, not a TeX issue. Nevermind. That being said, Swann's \vcenter method actually works like a charm.

• Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Aug 26 '14 at 14:14
• The output depends on the size of the figure itself. There is no information on this! – user31729 Aug 26 '14 at 14:15
• Can you provide a complete MWE? Testing this with graphicx, array, longtable and amsmath packages only seems to produce images that are places pretty well. – greyshade Aug 26 '14 at 14:15
• Please don't link to external files (especially dropbox links that are transient while this question is archived forever) the idea is that you make an example small enough that demonstrates the problem that you can post inline here. – David Carlisle Aug 26 '14 at 16:11
• You can use \rule{2cm}{5cm} or whatever is needed to make a rectangular blob in place of an image and remove any packages not needed to show the problem and end up with a little document just enough to make the images you show in this question (with a rule replacing the real image). That is if you can reproduce the problem using article class, do that, if not, then that in itself is useful information. – David Carlisle Aug 26 '14 at 16:18

You can use $\vcenter{...}$:

\documentclass{article}

\usepackage{graphicx}
\usepackage{longtable,amsmath,tabularx}

\begin{document}
\begin{longtable}{m{0.2\linewidth} m{0.7\linewidth}}
\hline
$\vcenter{\includegraphics[keepaspectratio,width=\linewidth]{example-image-a.jpg}}$ & \!\begin{aligned} A &= b\cdot{}h\\ P &= 2(b+h)\\ y &= \dfrac{h}{2}\\ I_y &= \dfrac{1}{12}b\cdot{}h^3 \end{aligned}
\\\hline
$\vcenter{\includegraphics[keepaspectratio,width=0.2\linewidth]{example-image-a.jpg}}$ & \!\begin{aligned} A &= b\cdot{}h\\ P &= 2(b+h)\\ y &= \dfrac{h}{2}\\ I_y &= \dfrac{1}{12}b\cdot{}h^3 \end{aligned}
\\\hline
\end{longtable}

\end{document}

• I have edited my post with an MWE which is actually currently using this method, but even this doesn't work too well in my case, for some reason, even though it clearly works perfectly here. – Wasabi Aug 26 '14 at 16:05
• I just noticed this does actually work perfectly. For whatever reason my image was getting padded without my knowledge. Considering the real size of the image, this method works wonders. – Wasabi Aug 26 '14 at 16:48

You can use adjustbox package with export option so that the keys are available inside the \includegraphics command.

 \usepackage[export]{adjustbox}


and then use valign=c

\includegraphics[keepaspectratio,width=\linewidth,valign=c]{example-image-a.jpg}


Code:

\documentclass{article}

\usepackage{graphicx}
\usepackage{longtable,amsmath,tabularx}

\begin{document}
\begin{longtable}{m{0.2\linewidth} m{0.7\linewidth}}
\hline
\includegraphics[keepaspectratio,width=\linewidth,valign=c]{example-image-a.jpg} & \!\begin{aligned} A &= b\cdot{}h\\ P &= 2(b+h)\\ y &= \dfrac{h}{2}\\ I_y &= \dfrac{1}{12}b\cdot{}h^3 \end{aligned}
\\\hline
\includegraphics[keepaspectratio,width=0.2\linewidth,valign=c]{example-image-a.jpg} & \!\begin{aligned} A &= b\cdot{}h\\ P &= 2(b+h)\\ y &= \dfrac{h}{2}\\ I_y &= \dfrac{1}{12}b\cdot{}h^3 \end{aligned}
\\\hline
\end{longtable}

\end{document}


• Unfortunately, as stated in the OP, I am forced to work with a crummy class file which for whatever reason isn't compatible with adjustbox. – Wasabi Aug 27 '14 at 4:25