2

I want to write a text next to an image. I tried to use minipage with figure, because I want to utilize label and caption.

Here is my code:

\begin{figure}[htbp]
  \centering
  \begin{minipage}{0.5\textwidth}
    \includegraphics[width=\textwidth]{img/Kinect image 3.png}
    \caption{\cite{Prochazka.2015}\label{fig:introduction}}
  \end{minipage}
  \begin{minipage}{0.5\textwidth}
   Here is the text.
  \end{minipage}
\end{figure}

The output is:

enter image description here

But the text should be next to the image on the right. How can I reach this? Thanks for helping me.

3
  • 1
    Try putting the figure environment inside the first minipage and the text inside the second.
    – Bernard
    Commented May 25, 2020 at 22:09
  • Welcome to TeX.SE! If I insert your code fragment to an example of document, it works fine. Right of the image is text. Image, which you show, is not produced by provided code fragment. Please clarify, what is your problem.
    – Zarko
    Commented May 25, 2020 at 22:51
  • Hello there! This is Tom from the Overleaf Support Team. Please note that I removed the overleaf tag as this is not directly Overleaf-related. This should work if you bring the \caption out of any of the minipages. Also please add % directly after the fist \end{document} (without any spaces or newlines) to ensure proper horizontal spacing..
    – yo'
    Commented May 25, 2020 at 22:51

1 Answer 1

2

You should avoid spurious white space between the two minipages. It is causing the sum of horizontal dimensions to be greater than \textwidth:

0.5\textwidth + (space width) + 0.5\textwidth > \textwidth

This spurious spaces appears by the TeX syntax itself. The right syntax demands adding a comment symbol % just at the end of the line where the first minipage is.

By the way, remember that you can choose the horizontal alignment of minipage environment using its [pos] optional argument. For the alignment of graphics, it is usefull the graphbox package. It adds to \includegraphics command the [align=t,c,b] option.

For example, if you want your text to start at the top:

The [t] option in minipage aligns that environment horizontally with the current line or test (even in your document, no material yet) so you must set \begin{minipage}[t]{0.5\textwidth} in both cases.
The [align=t] option in \includegraphics, aligns the top of the image with the current line of text (which will be the first line of the right text)
.

At least, note that the \centering sentence is not necessary in this example, because there is nothing to center: you are taking up the entire width of the text.

So the complete code:

\documentclass{article}
\usepackage{graphicx,graphbox}

\begin{document}

\begin{figure}[htbp]
  \begin{minipage}[t]{0.5\textwidth}
    \includegraphics[align=t,width=\textwidth]{your_image.jpg}%
    \caption{\cite{Prochazka.2015}\label{fig:}}%
  \end{minipage}%
   \begin{minipage}[t]{0.5\textwidth}
   Here is the text.
  \end{minipage}
\end{figure}

\end{document}

enter image description here

4
  • Thanks @e_moro ! This is how I wanted it. Have you got an idea how I can reach that the text starts at the top and not in the middle of the picture? And also the distance between picture and caption is too big.
    – mathsqt
    Commented May 26, 2020 at 10:27
  • @mathsqt, look at the answer again, it has been updated. To reduce the distance between picture and caption, please search in this site. For example, take a look to the second answer to: tex.stackexchange.com/questions/67143/…
    – e_moro
    Commented May 26, 2020 at 11:38
  • Thank you! I will try it like that.
    – mathsqt
    Commented May 27, 2020 at 9:36
  • You are welcome, @mathsqt. Remember that if an answer was useful for you, you can up-vote it in addition to accepting it.
    – e_moro
    Commented May 27, 2020 at 11:39

You must log in to answer this question.

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