5

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):

enter image description here

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:

enter image description here

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}

enter image description here

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

enter image description here

when exported into .eps and placed in TeX becomes

enter image description here

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

Wasabi
  • 759
  • 1
  • 4
  • 14
  • 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}. –  Aug 26 '14 at 14:14
  • The output depends on the size of the figure itself. There is no information on this! –  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
  • You say "but the results aren't much better" but give no indication of what is wrong. The image you show appears to show the image being vertically centred with respect to the alignment in the second column. Is that not what you want? – David Carlisle Aug 26 '14 at 14:51
  • The longtable doesn't seem to be doing much here you could just set each row as a separate paragraph, alignment will be automatic if the images are scaled to the same width. – David Carlisle Aug 26 '14 at 14:57
  • I have edited my post with an MWE. Since you wish to compile it, I had to put a link to an external package. This includes the university's .cls file and the original figure itself. @DavidCarlisle I didn't give an indication of what isn't much better because I thought it was clear in the attached image. It seems to me that the vertical space above the second image is larger than the space beneath it. Shouldn't they be the same in a vertically centered cell, as per the examples in Andrew Swann's answer? – Wasabi Aug 26 '14 at 16:01
  • The vertical centre of the image is aligned with the centre of the alignment the real problem shown by your image is that the spacing around the alignment is unsymmetric with a lot more space above. Fix that and the image would fix itself. – David Carlisle Aug 26 '14 at 16:09
  • 1
    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
  • I understand that and would must rather not post external links. However since there was a wish expressed by @ChristianHupfer for a compilable example and the fact that the output depends on the size of the figure itself, I don't know how else to present this information. I will however now edit the question once more with the MWE code. – Wasabi Aug 26 '14 at 16:14
  • 1
    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
  • Jesus, I just realized the problem is that, contrary to what I posted originally, the image is not trimmed. I placed a \frame{\includegraphics{}} and saw a lot of white space around the image. I exported it again, trimmed it again with GIMP but it keeps getting padded. Regardless, this is no longer a TeX issue but a GIMP one. Nevermind. My appologies. – Wasabi Aug 26 '14 at 16:40

2 Answers2

4

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

Sample output

\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}
Andrew Swann
  • 95,762
  • 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
1

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}
\usepackage[export]{adjustbox}

\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}

enter image description here

  • 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 04:25