5

I am trying to put two images into my latex document. I want the format to be

2 (a) Text text

Image Image

Text text

When I do the following

%2a
\item Here are the histograms of M and A values. \\
\includegraphics[scale=.4]{2a hist M values.jpeg} 
\includegraphics[scale=.4]{2a hist a values.jpeg}
I would not say either of these are normally distributed. 

I get what I want, but the second image overflows off the page

%2a
\item Here are the histograms of M and A values. 
\begin{figure}[h!]
\includegraphics[scale=.4]{2a hist M values.jpeg} 
\includegraphics[scale=.4]{2a hist a values.jpeg}
\end{figure}
I would not say either of these are normally distributed. 

This formats the images great but the text continues as if the images are being placed at the end of the chapter or something. The text basically continues right after the first sentence when I want it to continue after the images.

Can anyone help me with this?

  • Welcome to TeX.SX! Just a thought, try adding \usepackage{float} to your preamble and then do \begin{figure}[H] instead of \begin{figure}[h!]. That being said, though, a complete minimal working example (MWE), starting with \documentclass{...} and ending with \end{document}, would probably be useful for us to better help you. – Adam Liter Nov 4 '13 at 7:12
5

If you don't need captions, you can omit the figure environment altogether. Further, the figures can be aligned with the help of minipages.

\documentclass{article}
\usepackage{graphicx}
\usepackage{showframe}   %% for demo of grids, remove in your file
\begin{document}
\begin{enumerate}
\item Here are the histograms of M and A values.\par
\begin{minipage}{.45\linewidth}
\includegraphics[width=\linewidth]{example-image-a}
\end{minipage}%
\hfill
\begin{minipage}{.45\linewidth}
\includegraphics[width=\linewidth]{example-image-b}
\end{minipage}
\par
I would not say either of these are normally distributed. 
\end{enumerate}
\end{document}

enter image description here

If you want captions, you can use either caption or capt-of package which provide \captionof macro.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}     %% provides \captionof command. capt-of package does this too.
\usepackage{showframe}   %% for demo of grids, remove in your file
\begin{document}
\begin{enumerate}
\item Here are the histograms of M and A values.\par
\begin{minipage}{.45\linewidth}
\includegraphics[width=\linewidth]{example-image-a}
\captionof{figure}{some figure}
\end{minipage}%
\hfill
\begin{minipage}{.45\linewidth}
\includegraphics[width=\linewidth]{example-image-b}
\captionof{figure}{Some other figure}
\end{minipage}
\par
I would not say either of these are normally distributed.
\end{enumerate}
\end{document}

enter image description here

0

To explain a bit more about what's going on, LaTeX has internal parameters that are used to determine what good float positions are. Without any extra packages, float options include:

  • t - top of the page
  • b - bottom of the page
  • p - separate page for floats
  • h - here, if possible
  • ! - this overrides LaTeX's internal parameters

So, one might write \begin{figure}[htbp] to allow the figure float to be positioned in any of these places (i.e., here, at the top of the page, at the bottom of a page, or on a separate, special page for floats).

Now, \begin{figure}[h] should only place the figure here. But, since LaTeX internally determines good float positions, it will only place it here if it is a good place for floats. Using ! should supposedly override this. That is to say, \begin{figure}[h!] should override LaTeX's internal parameters and definitely place the float here. (In your case, it doesn't seem to override this; we'll return to this below. First, a bit about float.)

Now, there is also another option, H, from the float package, which, according to the LaTeX wikikbook, is "somewhat equivalent to h!".

According to the float documentation (pp. 3-4), the H placement specifier will always place the float here, no matter what. It is in this sense that it is sort of equivalent to h!.

However, the following code still produces your undesired result:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{enumerate}
\item Here are the histograms of M and A values.
\begin{figure}[h!]
\includegraphics[width=.45\linewidth]{example-image-a}
\includegraphics[width=.45\linewidth]{example-image-b}
\end{figure}
I would not say either of these are normally distributed. 
\end{enumerate}
\end{document}

enter image description here

On the other hand, using the H placement specifier produces the desired result:

\documentclass{article}
\usepackage{graphicx}
\usepackage{float}
\begin{document}
\begin{enumerate}
\item Here are the histograms of M and A values.
\begin{figure}[H]
\includegraphics[width=.45\linewidth]{example-image-a}
\includegraphics[width=.45\linewidth]{example-image-b}
\end{figure}
I would not say either of these are normally distributed. 
\end{enumerate}
\end{document}

enter image description here

The answer to this seeming puzzle, I think, lies in how the float is being treated internally. In the former case, where h! is used, LaTeX still treats the thing as a float. On the other hand, when H from float is used, my suspicion is that the thing is being put inside of a minipage, just as in @HarishKumar's answer. (Though the float documentation does not explicitly say what is going on, source for this suspicion comes from @DavidCarlisle's answer, where he says that "H makes the environment essentially not a float at all it is more or less the same as using minipage".)

So, in the former case, the thing is still treated as a float, but it is not an actual float in the latter case. In the latter case, because a minipage (or minipage-like thing) is occurring between "Here are the histograms of M and A values" and "I would not say either of these are normally distributed", then a paragraph break is being forced to occur.

On the other hand, since, in the former case, the thing is a just a float, then no paragraph breaking is happening. And, since there is no line-break in the raw .tex file, then "Here are the histograms of M and A values" and "I would not say either of these are normally distributed" are being treated as part of the same paragraph.

Note that you can achieve the desired result with the following code:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{enumerate}
\item Here are the histograms of M and A values.

\begin{figure}[h!]
\includegraphics[width=.45\linewidth]{example-image-a}
\includegraphics[width=.45\linewidth]{example-image-b}
\end{figure}

I would not say either of these are normally distributed. 
\end{enumerate}
\end{document}

Or, as @HarishKumar did in his answer, you can use the TeX primitive \par, which is just equivalent to a blank line in the raw .tex file.

To sum up, the undesired result you noted in your OP results from the fact that h!, unlike H of float, causes the thing to still be treated by LaTeX as a legitimate float, rather than, say, a minipage, and it also results from the fact that in the code in your OP, there is no paragraph breaking that occurs.

You can achieve the desired result by using H of float, using actual minipage environments like @HarishKumar did in his answer, or by continuing to use h! but actually breaking the two lines of text into separate paragraphs either with a line break or with \par.

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.