3

I am trying to place the bottom right figure in the same way as the bottom left figure but I find it really really difficult. Any ideas?

\begin{figure}
\begin{tabular}{cccc}
  \includegraphics[width=35mm]{./Figures/10026cropped.jpg} &   \includegraphics[width=35mm]{./Figures/10026cropped.jpg} &  \includegraphics[width=35mm]{./Figures/10026cropped.jpg} & \\
\multicolumn{2}{c}{\includegraphics[width=35mm]{./Figures/10026cropped.jpg} } & \multicolumn{2}{c}{\includegraphics[width=35mm]{./Figures/10026cropped.jpg}}
\end{tabular}
\caption{caption}
\end{figure}

The figure

1
  • I added an explanation on what happened here that I think is interesting not as a solution but on realizing what happened!
    – koleygr
    Mar 16, 2019 at 23:53

2 Answers 2

1

You don't need tabular for this:

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}
\centering

\includegraphics[width=35mm]{example-image}\quad
\includegraphics[width=35mm]{example-image}\quad
\includegraphics[width=35mm]{example-image}\\[2ex]
\includegraphics[width=35mm]{example-image}\quad
\includegraphics[width=35mm]{example-image}

\caption{caption}

\end{figure}

\end{document}

enter image description here

0

Just for fun (Programming is fun but sometimes makes you too think very strange things and to feel silly after realizing what you are trying to do).

  1. First step...

    Ok, I have 5 figures and I need 3 on top and two on bottom, I want to control their placement... A tabular seems a good solution to me...

Let's think:

Three on top: {ccc} First row normal centered and I will split cells via \multicolumn in second to share the space... But...

\begin{tabular}{ccc}
\include..&\include..&\include..\\
\multicolumn{2}{c}&\multicolumn{2}{c}
\end{tabular}

Oh! writing the second \multicolumn I realized that they became 4 columns... Don't even compiling...

Seems I need a fourth column:

Let's try:

  1. Second step... four columns:

I will split the top middle columns with \multicolumn:

\begin{tabular}{cccc}
\include...&\multicolumn{2}{c}{\include...}&\include...\\ %Nice... Let's finish with the next row
\multicolumn{2}{c}{\include...}&\multicolumn{2}{c}{\include}
\end{tabular}

4 in the up row 4 in the next... perfect! Let's compile

enter image description here

Seems I didn't count correct... Lets count...

  • Above row 4 cells middle 2 merged
  • Below row 2 & 2 cells...

Why first cell of second row doesn't merge with the second? This should give the fourth figure centered in two first columns like fifth... Why?

Do I need to add a fifth column?

Lets see:

\begin{tabular}{cccc}
1&2&3&4\\
\include...&\multicolumn{2}{c}{\include...}&\include...\\ %Nice... Let's finish with the next row
\multicolumn{2}{c}{\include...}&\multicolumn{2}{c}{\include}
\end{tabular}

enter image description here

Fourth image stops before 2nd column... Lets think... Do I need 5 columns?

  1. Third step... Let's see the vertical lines there? before reporting a bug... But I should!

Full code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\begin{tabular}{|c|c|c|c|}
1&2&3&4\\
  \includegraphics[width=35mm]{example-image-a} &   \multicolumn{2}{c}{\includegraphics[width=35mm]{example-image-b}} &  \includegraphics[width=35mm]{example-image-c} \\
\multicolumn{2}{|c}{\includegraphics[width=35mm]{example-image-a}} & \multicolumn{2}{|c|}{\includegraphics[width=35mm]{example-image-b}}
\end{tabular}
\end{document}

enter image description here

They need the bug report... But...

Ok... I think I got it:

The second column has no the width of the third... Of course... No width needed there... Lets add a width:

... Ok I will add centered 17.5mm in both the middle columns:

\documentclass{article}
\usepackage{graphicx}
\usepackage{array}
\begin{document}
\begin{tabular}{|c|>{\centering\arraybackslash}p{17.5mm}|>{\centering\arraybackslash}p{17.5mm}|c|}
  \includegraphics[width=35mm]{example-image-a} &   \multicolumn{2}{c|}{\includegraphics[width=35mm]{example-image-b}} &  \includegraphics[width=35mm]{example-image-c} \\
\multicolumn{2}{|c}{\includegraphics[width=35mm]{example-image-a}} & \multicolumn{2}{|c|}{\includegraphics[width=35mm]{example-image-b}}
\end{tabular}
\end{document}

enter image description here

Why me??? Let's ask at stackexchange... I am out of here!

  1. No more steps: Some explanation:

Let's add the 1&2&3&4 row back there:

\documentclass{article}
\usepackage{graphicx}
\usepackage{array}
\begin{document}
\begin{tabular}{|c|>{\centering\arraybackslash}p{17.5mm}|>{\centering\arraybackslash}p{17.5mm}|c|}
1&2&3&4\\
  \includegraphics[width=35mm]{example-image-a} &   \multicolumn{2}{c|}{\includegraphics[width=35mm]{example-image-b}} &  \includegraphics[width=35mm]{example-image-c} \\
\multicolumn{2}{|c}{\includegraphics[width=35mm]{example-image-a}} & \multicolumn{2}{|c|}{\includegraphics[width=35mm]{example-image-b}}
\end{tabular}
\end{document}

enter image description here

Perfect... But what happened?

LaTeX used just 3 columns since the maximum of the cells needed there was 3 per row... So, the first column was a single column and not really a multicolumn... By adding these help numbers... we are actually lucky and found out what happened... So, adding a full row with empty cells (but all the cells) can solve the problem... Then remove the extra vertical space of the line with [-1em] ... Also, with some simple thoughts the second row cells should not be centered because of the extra width of the first and last column... May be r and l is a better choice ... and a \tabcolsep fixed width would help... same distance too (as \tabcolsep between rows) and:

\documentclass{article}
\usepackage{graphicx}
\usepackage{array}
\begin{document}
\setlength{\tabcolsep}{1mm}
\begin{tabular}{c>{\centering\arraybackslash}p{17.5mm}>{\centering\arraybackslash}p{17.5mm}c}
&&&\\[-1em]
  \includegraphics[width=35mm]{example-image-a} &   \multicolumn{2}{c}{\includegraphics[width=35mm]{example-image-b}} &  \includegraphics[width=35mm]{example-image-c} \\[1mm]
\multicolumn{2}{r}{\includegraphics[width=35mm]{example-image-a}} & \multicolumn{2}{l}{\includegraphics[width=35mm]{example-image-b}}
\end{tabular}
\end{document}

enter image description here

But why didn't made it in a simpler tabular (of 3 columns)?

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\setlength{\tabcolsep}{1mm}
\begin{tabular}{ccc}
\includegraphics[width=35mm]{example-image-a}& \includegraphics[width=35mm]{example-image-b}&\includegraphics[width=35mm]{example-image-c}\\[1mm]
\multicolumn{3}{c}{\includegraphics[width=35mm]{example-image-a}\hspace{2mm}\includegraphics[width=35mm]{example-image-b}}
\end{tabular}
\end{document}

Nice... Clever!

But @egreg's answer is more clever!!! At least I found the problem!

PS:My answer is because I think that the OPs problem could be happen to anyone and I think that may offer to someone with similar problems even if (of course) some hours (after relaxing) (s)he should think in a simpler way!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .