11

When i run the following code i get my output on two pages. On first page the text line and my image on page 2. How can i get my output on the same page that is text and image on the same page. Please help.

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\begin{document}
Hi...My first test image
\begin{figure}[h]
\centering
\includegraphics[width=1\textwidth]{fig10.pdf}
\caption{My first image}
\end{figure}

\end{document}
2
  • 1
    Perhaps you want to take a look at this question. Sep 21 '13 at 8:21
  • Will the figure fit on the same page as the text if you replace [h] with [h!]? If not, the image is probably too large if you insist on its width being 1\textwidth.
    – Mico
    Sep 21 '13 at 9:21
12

Simply your image is too large to fit on the first page. Note that LaTeX consider not only if there is enough space among the margins, also make penalties for a bad design (for example, if the fraction of text with respect the floats is less than 20%) and considering this, LaTeX tries to do the best (print a format with less penalties) than could be different to what you expected. See What are penalties and which ones are defined? for more information a this respect. Follow also the Thorsten's advice and see also How to influence the position of float environments like figure and table in LaTeX?

Without knowing the size of the original figure is not possible to say exactly how to solve your minimal working example (MWE), but you can simply narrow the figure to some less than 1\textwidth. Or may help for a big figure add the option [h!] as this relax the LaTeX rules for this float. Or you can change the rules, writing in the preamble:

\renewcommand{\textfraction}{0.05} 

For example:

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\usepackage{mwe} % for the example image
\begin{document}
Hi...My first test image
\begin{figure}[h!]
\centering
\includegraphics[width=.8\textwidth]{example-image-10x16}
\caption{My first image}
\end{figure}
\end{document}

MWE

7
  • thank you so much...it really helped.. one more thing i wanted to ask caption appears very much below the figure. how can i show it just below the figure?
    – Misha
    Sep 21 '13 at 9:55
  • 1
    You're welcome. Try some like \renewcommand{\abovecaptionskip}{1cm} in the preamble. You can change 1cm by any other measure, like 4em, or 3ex, 80pt, etc.
    – Fran
    Sep 21 '13 at 10:22
  • hello...there is lot of space between the text and the image which i put up in my document and then again there is lot of space between the image and its caption..the above command which you mentioned is not working. is there any other way to reduce this unwanted space??
    – Misha
    Sep 27 '13 at 9:40
  • The command worked for me. Without looking a MWE from you it is hard to imagine what is going on and how this can be solved. Please, edit your question to add a a new MWE if you think that you have still the same problem, or open a new question if you suspect that now there are a different problem.
    – Fran
    Sep 27 '13 at 13:08
  • I ran into an obscure problem, nothing was working - the figure would always stay on a single by itself no matter what. So it turns out that I was compiling a file using pdflatex which used includegraphics on an .eps file. When it did so, it converted the .eps to a .pdf but in a buggy way which included a very large bounding box. I discovered this by using the draft option and inspecting the bounding boxes. What I did was to supply my own converted .pdf figure to pdflatex which was properly trimmed. Then the [h!] suggested here worked!
    – rfabbri
    Nov 21 '15 at 15:44

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.