# Given a 3x4 table of images, how do I make all the images the same size and remove vertical space so the table looks seamless?

I'm using a table to format a series of images. My goal is to create an image array where the transition from one figure to the next is seamless i.e. no white space anywhere. My problem is that the images are individual pdf files with white borders of varying widths/heights.

Is there any way for the border to be 'ignored' i.e. not displayed, and also to set the images to a specific width and height? I'd also like to remove any vertical/horizontal in the table.

Here is my MWE:

\documentclass[varwidth]{standalone}
\usepackage{graphicx}
\usepackage{longtable}

\newcommand{\x}{0.15}
\newcommand\ig[1][]{\includegraphics[width= \x\linewidth, height = \x\linewidth,#1]}

\def\thmbpth{./thumbnails}

\begin{document}
\setlength{\tabcolsep}{-1.9pt}
\begin{longtable}{cccc}
\ig{\thmbpth/p13_frame39_cpp_test58} & \ig{\thmbpth/p13_frame42_cpp_test58} & \ig{\thmbpth/p91_frame162_cpp_test58} & \ig{\thmbpth/p39_frame104_cpp_test58} \\
\ig{\thmbpth/p50_frame43_cpp_test58} & \ig{\thmbpth/p50_frame49_cpp_test58} & \ig{\thmbpth/p80_frame152_cpp_test58} & \ig{\thmbpth/p91_frame158_cpp_test58} \\

\ig{\thmbpth/p92_frame63_cpp_test58} & \ig{\thmbpth/p93_frame70_cpp_test58} & \ig{\thmbpth/p52_frame226_cpp_test58} & \ig{\thmbpth/p44_frame85_cpp_test58} \\
\end{longtable}
\end{document}


The figure names are the real ones. This is a link to the actual data.

Would it be more better to crop all of the images first?

My question is similar to this one but I have far more images.

Question was edited to update the data link

Edit: Operating System is Windows 7. Tex system is MikTex.

• I don't think there is anyway for TeX to know how you want the images cropped unless you tell it. If they were all the same, you could specify it in your definition of \ig but otherwise, you'd have to pass that information for each image. See the graphicx manual for details of how to do this but I suspect cropping first will be easier. – cfr Jul 18 '14 at 23:01
• What operative system do you use? and what LaTeX system? – skpblack Jul 18 '14 at 23:46
• @skpblack Latex system? I don't know what you are referring to. – Neil Jul 18 '14 at 23:49
• By operating system I am referring to Windows or Linux or MacOS. By LaTeX system I am referring to TexLive (version?) or MikTeX (version?) or MacTeX (version?). – skpblack Jul 18 '14 at 23:59
• @skpblack Windows and Miktex – Neil Jul 19 '14 at 0:01

If you crop the images first, it works easily setting \tabcolsep=0pt and adjusting the vertical spacing between the longtable lines. This adjustment is obtained experimentally to -4.1pt, but this value will depend on the height of the images. Note that setting width and height options of \includegraphics will stretch or shrink the images in both directions until they the prescript values.

In order to crop the images, you can use the pdfcrop --hires perl script. Here is the batch file I used under Windows (a linux script must not be very different). The cropped files have -c added to their names:

@echo off
echo "Cropping pdf files ..."
for %%i in (./*.pdf) do pdfcrop %%i  %%~ni-c.pdf --hires --verbose
echo.
echo Done
pause


The LaTeX code, improved thanks to @skpbnlack's tip:

    \documentclass[varwidth]{standalone}

\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{longtable}
\newcommand{\x}{0.15}
\newcommand\ig[1][]{\includegraphics[width= \x\linewidth, height = \x\linewidth,#1]}
\def\thmbpth{./thumbnails}

\begin{document}

\setlength{\tabcolsep}{0pt}\renewcommand\arraystretch{0}
\begin{longtable}{cccc}
\noalign{\vskip-11.8pt}
\ig{\thmbpth/p13_frame39_cpp_test58-c} & \ig{\thmbpth/p13_frame42_cpp_test58-c} & \ig{\thmbpth/p91_frame162_cpp_test58-c} & \ig{\thmbpth/p39_frame104_cpp_test58-c} \\
\ig{\thmbpth/p50_frame43_cpp_test58-c} & \ig{\thmbpth/p50_frame49_cpp_test58-c} & \ig{\thmbpth/p80_frame152_cpp_test58-c} & \ig{\thmbpth/p91_frame158_cpp_test58-c} \\
\ig{\thmbpth/p92_frame63_cpp_test58-c} & \ig{\thmbpth/p93_frame70_cpp_test58-c} & \ig{\thmbpth/p52_frame226_cpp_test58-c} & \ig{\thmbpth/p44_frame85_cpp_test58-c} \\
\end{longtable}

\end{document}


Note there remains a white strip above the ‘mosaic’due to first row height, hence the \noalign{\vskip -11.8pt} the table begins with.

• Works but if you use Windows you must install an Perl script interpreter for pdfcrop. I recommend to install ActivePerl of here. – skpblack Jul 19 '14 at 2:44
• I use Strawberry Perl. – Bernard Jul 19 '14 at 3:07
• You can use \renewcommand{\arraystretch}{0} instead of \noalign{\vskip-11.8pt} to avoid test with hand measures and \\[..] specifications in each row. – skpblack Jul 19 '14 at 3:43
• @skpblack: didn't know that trick! For me, \ arraystretch was necessarily a non-zero factor. However it does not make white strip on top disappear. I tried to play with standalone option, but nothing else worked than \vskip{-11.8pt}. Thanks a lot anyway, it will improve my answer! – Bernard Jul 19 '14 at 9:52
• My code really does not generate whitespace anywhere. Here is my [code] (docs.google.com/file/d/0B23g3DBFautBLVN3WjFXbXUzWmc) – skpblack Jul 19 '14 at 13:02