# Removing white space beside images

I'm trying to display a bunch of images side by side. Originally I wanted them on the same line, but I got them to fit by putting 2 on the next line. I'd like to make the pictures bigger but the white space beside the images seems to grow proportionally and push the second image off the page.

\documentclass[]{article}
\usepackage[demo]{graphicx}

\begin{document}
\begin{figure}[h]
\centering
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=0.4\linewidth]{p1}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=0.4\linewidth]{p2}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=0.4\linewidth]{p3}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=0.4\linewidth]{p4}
\end{minipage}
\end{figure}
\end{document}

• you could remove all the minipage which are not doing anything useful, and delete the blank lines which are paragraph breaks so forcing things to stack vertically. – David Carlisle Mar 11 '15 at 14:06
• The rules for white space around an image are exactly the same as the rules for a letter such as X \includegraphics itself adds no space, you just get whatever white space you have added in the source file. Ends of lines introduce word spaces and blank lines introduce vertical paragraph skips. – David Carlisle Mar 11 '15 at 14:08
• Ideally I'd like the images to line up horizontally. by adding a % at the end of the second minipage I do get that, but the third image is only half on the page and the 4th is completely off – Arland Mar 11 '15 at 14:09
• Your example doesn't allow anyone to see anything as it isn't a complete document and it references figures we haven't got. If you make a complete document and add \usepackage[demo]{graphics} then the example will be more useful and you can check that it shows the problem. You have 4 images stacked vertically so they will run off the page if they are too large, but we have no indication of their size. – David Carlisle Mar 11 '15 at 14:13
• Doesn't the width=0.4 set the image width? Document is updated as suggested – Arland Mar 11 '15 at 14:23

It isn't really clear what you want, but perhaps:

\documentclass[]{article}
\usepackage[demo]{graphicx}

\begin{document}
\begin{figure}[htp]% never use h on its own
\centering
\includegraphics[width=0.2\linewidth]{p1}
\includegraphics[width=0.2\linewidth]{p2}
\includegraphics[width=0.2\linewidth]{p3}
\includegraphics[width=0.2\linewidth]{p4}
\end{figure}
\end{document}

• That looks good. I tried adding captions with \caption{} and it lined the images up vertically. Is there a way to keep it horizontal? – Arland Mar 11 '15 at 14:39
• @Arland Yes if you want \caption then you can put each image in a minipage with its caption, or use a package like subfigure or subcaption that has more extensive support. (depends if you want to number 1,2,3,f or 1a 1b 1c 1d, mainly) – David Carlisle Mar 11 '15 at 14:41
• Ok thanks, I'll look into that. Thanks for your input – Arland Mar 11 '15 at 14:48