3

I am inserting a figure into a body of text using the 'h' float specifier. In the example below, the figure is placed at the beginning of the next page (2) since there isn't enough room left on the current page (1).

Current code:

\documentclass[11pt, oneside, letterpaper]{book}

\usepackage{graphicx}

\begin{document}
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum.

\begin{figure}[h] 
    \centering
    \includegraphics[scale=0.35]{./fig1}
    \caption{This is a figure caption.}
    \label{fig:figure1}
\end{figure} 

after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure after figure 

\end{document}

The text that follows immediately after the figure fills the remainder of page 1, but starts on a new line. Is it possible to make the text after the figure follow immediately after the text from before the figure, on the same line?

Thanks for your help!

enter image description here enter image description here

6

It is not the figure that inserted the newline (actually, paragraph break) you added it explicitly in the source file, the blank line forces a paragraph break, you would see the same if you deleted the figure.

Simply remove the blank lines.

It is almost always better to use [htp] rather than [h] normally LaTeX warns about [h] and changes it to [ht] to make it possible to set the figure.

  • Building on this, for source-readability, I often preserve whitespace around a mid-paragraph figure (or equation) by putting in a set of empty-comment lines before and after the environment. – RLH Feb 1 at 20:59
3

To exemplify David Carlisle's answer

\documentclass[11pt, oneside, letterpaper]{book}
\usepackage{graphicx}
\begin{document}
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem 
ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem 
ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem 
ipsum lorem ipsum lorem ipsum orem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum orem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum orem 
\begin{figure}[h]
    \centering
    \includegraphics[scale=0.35]{example-image-a}
    \caption{This is a figure caption.}
    \label{fig:figure1}
\end{figure}
after figure after figure after 
figure after figure after figure after figure 
after figure after figure after figure after figure after 
figure after figure after figure after figure after 
figure after figure after figure after figure after 
figure after figure after figure after figure after figure after 
figure after figure after figure after figure after figure after 
\end{document}

enter image description here

2

If you need precision when placing images, may I suggest not using floats. Floats allow images to swim around the text to provide the ideal placement according to TeX's programmed penalties. The whole purpose is to try and make them show up at the top, middle, or bottom of pages depending on how the text gets laid out while typesetting.

Here is an example of a custom figure environment that does not function as a float (despite the float caption type). I just hijacked the existing caption code, which is designed to work within float environments.

\documentclass{article}
\usepackage{xparse}% for LaTeX3's \NewDocumentEnvironment
\usepackage{graphicx}% for \includegraphics

\makeatletter
\NewDocumentEnvironment{myfigure}{ O{} m }
  {%
  \def\@captype{figure}% see source2e for using caption outside of float
  \includegraphics[#1]{#2}%
  }
  {}
\makeatother

\begin{document}

 Before before before
\begin{myfigure}[width=.3\textwidth]{Router_Diagram.pdf}
%\caption{Here is a caption.}
\end{myfigure} 
After after after

Before before before
\begin{myfigure}[width=.3\textwidth]{Router_Diagram.pdf}
\caption{Here is a caption.} % note that this adds a new line, but could be remedied by boxing the whole thing in the environment
\end{myfigure} 
After after after


\end{document}

enter image description here

  • the one line capt-of package could be used to define the caption (using the same code) but this does not answer the OPs question, the question is how to avoid starting a paragraph with the After.... text. – David Carlisle Feb 1 at 16:03
  • @DavidCarlisle I did my best to make sense of: "Is it possible to make the text after the figure follow immediately after the text from before the figure, on the same line?" That seems like the crux of the question, but it is phrased awkwardly. Also, my environment does not add a line break (start a paragraph). Where are you seeing that? – Jonathan Komar Feb 1 at 16:10
  • the word After in your example starts a paragraph for the same reason it does in the question, there is a blank line in the source before it. – David Carlisle Feb 1 at 16:14

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.