1
\section{Question 1}
\begin{figure}
    \centering
    \includegraphics[width=\linewidth]{Cute Goat In Pink.jpg}
    \caption{Daredevil}
    \label{fig:my_label}
\end{figure}

Above is the code I am trying to use but for some reason, it is not showing up on the compiled pdf.

So, I am using the online version of overleaf so I don't think the issue is with my version. Also, below is the entire code I am currently using:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images

\title{CPSC} \author{} \date{July 2023}

\begin{document}

\maketitle

\section{Question 1} Hello \begin{figure} \centering \includegraphics[width=\linewidth]{Cute Goat In Pink.jpg} \caption{Daredevil} \label{fig:my_label} \end{figure} Goodbye \end{document}

Unfortunately, the only thing showing up is hello and goodbye. As for the picture name, that is how it is saved. I tried replacing it with another one that is in all small letters with no spaces and still had the same issues. The log files in the pdf are showing absolutely no errors which is making me even more confused. And I copied this code directly from Overleaf so theoretically, it should work.

  • 1
    Remove the spaces from the picture file name? – Stephen Jul 30 '23 at 06:47
  • Welcome. // Unfortunately your code, as posted, can‘t compile… – MS-SPO Jul 30 '23 at 06:49
  • 1
    What exactly is not showing up, the whole section or the figure or the image only? Are there error messages or warnings in the log file? Does it work using a replacement image like example-image.png? How do you compile? Are you using pdflatex or something like latex + dvips + ps2pdf? Can you please extend your code to a minimal working example, that can be used to reproduce your issue? If it does work with an replacement image, we would also need the problematic image file. Maybe it is broken or the filename is not absolutely correct. – cabohah Jul 30 '23 at 07:03
  • @Stephen Up-to-date LaTeX distributions with an up-to-date graphics/graphicx package should not have problems with spaces in filenames. – cabohah Jul 30 '23 at 07:06
  • @cabohah Sorry for that, I have posted a more detailed snippet of what the code looks like on my end. – River Uzoma Jul 30 '23 at 07:22
  • @Stephen I tried that already. As well as changing all of them to small letters. It is still not working as intended – River Uzoma Jul 30 '23 at 07:23
  • Show the log file of your small example. – Ulrike Fischer Jul 30 '23 at 07:23
  • After I've replaced your image (which I do not have and therefore cannot test) by example-image.png (as already recommended), the image and the caption are shown at page 2. If your image is also quite large, you should have a look if it is also moved to the next page. – cabohah Jul 30 '23 at 07:27
  • 1
    @cabohah I cannot believe I forgot to consider the possibility that it was moved to the next page. Thank you very much. I will try and resize the image to reduce it's size. – River Uzoma Jul 30 '23 at 07:42
  • 1
    I’m voting to close this question because the real issue underlying the OP's query was discovered and remedied fully in a comment. – Mico Jul 30 '23 at 08:06
  • 1
    @Mico I've added an answer using not only the information of the question but also River's comment. I think a real answer (or a link to a duplicate question) is always better than closing because of an answer in a comment only. – cabohah Jul 30 '23 at 09:52
  • @cabohah - Thanks for posting an answer. Indeed, it's better for a query to get a full answer than to be closed due to the main issue having been addressed in a comment. – Mico Jul 30 '23 at 10:02

1 Answers1

1

figure is a floating environment. This means, if the image + caption does not fit to the current page (depending on the floating parameters) it can be moved to the next page. This seems to be also the case here.

Note, that the default placement of article if tbp (top, bottom, page). So a figure somewhere at the page will not be printed, where it has been placed in the source, but only at the top or bottom of this or the next page or at a page on its own.

Additionally you've placed the float inside a paragraph. Note, that even if you'd change the float parameters using \begin{figure}[!htbp] it would not be printed between “Hello” and “Goodbye” but at first after “Goodbye“, because LaTeX will not print it before the end of the current line.

So to have a replacement image between “Hello” and “Goodbye”, I would not only have to change the floating options, but also add a paragraph (empty line) before “Goodbye”:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images

\title{CPSC} \author{} \date{July 2023}

\begin{document}

\maketitle

\section{Question 1} Hello \begin{figure}[!htbp] \centering \includegraphics[width=\linewidth]{example-image} \caption{Daredevil} \label{fig:my_label} \end{figure}

Goodbye \end{document}

enter image description here

If your image is higher than the replacement example-image, you may also need to reduce the size by changing \includegraphics option width=\linewidth.

But if you don't want the image to float, another solution could be to not use a floating figure.

cabohah
  • 11,455