1

I have 8 images, in which i want two images across, by 4 images down. I am trying to do this with the following code:

\begin{figure}[htb]
\centering
  \begin{tabular}{@{}cccc@{}}
    \includegraphics[scale=0.4]{../random_forest/TP-Pred/program/error1.jpg} 
    \includegraphics[scale=0.4]{../random_forest/AFP-AFP-like/program/error1.jpg}
    \includegraphics[scale=0.4]{../random_forest/TP-Pred/program/error1.jpg} 
    \includegraphics[scale=0.4]{../random_forest/AFP-AFP-like/program/error1.jpg}  
    \multicolumn{4}{c}{\includegraphics[width=.23\textwidth]{example-image-a}}
  \end{tabular}
  \caption{A plot of the random forest error split culmulatively over the 4 sets of features}
\end{figure}

however all 4 images appear on the same horizontal line. How do I get them to appear like:

image 1      image 2
image 3      image 4
image 5      image 6
image 7      image 8

thanks in advance.

  • 2
    use \\ within a tabular to start a new line :) – cmhughes Nov 5 '13 at 20:27
  • also you have a 4 column tabular but have put all the images in the same cell you need & between the cells. – David Carlisle Nov 5 '13 at 20:36
3

I gather the eight jpegs are all the same size, right? In that case, there's no need to embed them in a tabular environment. You could do the following instead:

\begin{figure}[htb]
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image1.jpg}%
    \hspace*{\fill}% induce some horizontal separation between images 1 and 2
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image2.jpg}

    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image3.jpg}%
    \hspace*{\fill}% induce some horizontal separation between images 3 and 4
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image4.jpg}

    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image5.jpg}%
    \hspace*{\fill}% induce some horizontal separation between images 5 and 6
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image6.jpg}

    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image7.jpg}%
    \hspace*{\fill}% induce some horizontal separation between images 7 and 8
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image8.jpg}

  \caption{A plot of the random forest error split culmulatively over the 4 sets of features}
\end{figure}

Observe that a blank line will automatically force the following images to show up on a new "line". If you want more than the minimum amount of vertical separation, you could insert directives such as \smallskip, \medskip, or \bigskip (while still leaving a blank line to force a line break).


Addendum: If you really want/need to embed the images in a tabular structure, I would recommend you use the tabular* environment and set its width to \textwidth to assign as much width as possible to the images. The somewhat odd looking construct @{\extracolsep{\fill}} spreads the two columns maximally apart.

\begin{figure}[htb]
\begin{tabular*}{\textwidth}{@{} c @{\extracolsep{\fill}} c @{}}
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image1.jpg}&
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image2.jpg}\\
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image3.jpg}&
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image4.jpg}\\
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image5.jpg}&
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image6.jpg}\\
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image7.jpg}&
    \includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image8.jpg}\\
\end{tabular*}
\caption{A plot of the random forest error split culmulatively over the 4 sets of features}
\end{figure}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.