0

I have to display 4 images in two columns and two rows. The text in \hbox is so long that's why it is overriding the second image text in the next column. How to make the first image text break after a certain width so it will come into the new line. I have used \linebreak, \ but none of them is working.

\hbox to\linewidth{%
    \hfil%
    \vbox{%
        \hbox{\includegraphics[scale=0.5]{sampleimage1.png}}%
        \hbox to 5cm {Sample text 1}
    }%
    \hfil%
    \vbox{%
        \hbox{\includegraphics[scale=0.5]{sampleimage2.png}}%
        \hbox{Sample text 2}
    }%
    \hfil%
}
\hbox to\linewidth{%
    \hfil%
    \vbox{%
        \hbox{\includegraphics[scale=0.5]{sampleimage3.png}}%
        \hbox{Sample text 3}
    }%
    \hfil%
    \vbox{%
        \hbox{\includegraphics[scale=0.5]{sampleimage4.png}}%
        \hbox{Sample text 4}
    }%
    \hfil%
}
\caption{caption text}

Here is the output

Rohit Suthar
  • 105
  • 4
  • 1
    First of all always give full examples others can copy and test as is, not sniplets like this. Secondly are you writing in plain tex? If not why thise nested constructions? And why aren't you then using parbox instead it even supports line breaks. – daleif Apr 07 '20 at 14:14
  • Lastly it us probably easier to control the size of an image using width not scale – daleif Apr 07 '20 at 14:15
  • I have problem with the text not image – Rohit Suthar Apr 07 '20 at 14:16
  • 1
    It is all related, just look at the last one – daleif Apr 07 '20 at 14:17
  • How about using subcaptions? – Abby Apr 07 '20 at 14:19
  • neither \hbox nor \vbox should appear in a latex document and if you use them in this way they will not react normally to any latex constructs, no latex box commands use boxes unguarded by \leavevmode in this way. – David Carlisle Apr 07 '20 at 14:29
  • 1
    \hbox naturally forces the text to be on one line so \\, \newline etc do not produce line breaks. You could put a \parbox inside the \hbox but as noted above the real issue is that the \hbox should not be there. – David Carlisle Apr 07 '20 at 14:31
  • Why not use minipages? – leandriis Apr 07 '20 at 14:42
  • Hello there! This is Tom from the Overleaf Support Team. Please note that I removed the [tag:overleaf] tag as this is not directly Overleaf-related. – yo' Apr 07 '20 at 14:47

1 Answers1

2

Don't use low level commands if you don't know what they do.

Isn't the following simpler?

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htp]
\setlength{\tabcolsep}{0pt}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  p{0.48\textwidth}
  p{0.48\textwidth}
  @{}
}
\includegraphics[width=\linewidth]{example-image-a} &
\includegraphics[width=\linewidth]{example-image-b} \\
Sample Text 1 Sample Text 1 Sample Text 1 Sample Text 1 &
Sample Text 2 Sample Text 2 Sample Text 2 Sample Text 3 \\[2ex]
\includegraphics[width=\linewidth]{example-image-c} &
\includegraphics[width=\linewidth]{example-image-a} \\
Sample Text 3 Sample Text 3 Sample Text 3 Sample Text 3 &
Sample Text 4 Sample Text 4 Sample Text 4 Sample Text 4
\end{tabular*}

\caption{Caption text Caption text Caption text Caption text Caption text}

\end{figure}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thanks! But can you please change the caption text of images because it is considered as plagiarised for my report. – Rohit Suthar Apr 11 '20 at 15:49
  • @RohitSuthar Plagiarism? It should be a joke, but unfortunately it might be (very sadly) true. Next time a thesis with the words “I love you” not properly equipped with a citation will be considered plagiarism. – egreg Apr 11 '20 at 16:06
  • I'm also shocked!! Anyway Thanks!! – Rohit Suthar Apr 11 '20 at 16:10