# How can I avoid blank spaces when I insert a pdf figure?

in the following piece of latex code, I would like to place a pdf figure called sharpideq2 at page 1 among the text rows, avoiding blank space. What I get instead is the figure placed alone in the middle of page 2. The figure can only be saved in pdf and occupies the middle of one pdf page. Could you help me?

\documentclass[11 pt,a4paper,oneside,openany, notitlepage]{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{amsmath, amssymb, graphics}
\usepackage{amsthm}
\usepackage{amsfonts}
\marginparwidth 0pt
\oddsidemargin 0pt
\evensidemargin 0pt
\marginparsep 0pt
\linespread{1.5}
\topmargin 0pt
\textwidth 6.5in
\textheight 8.5 in
\usepackage{epsfig}
\usepackage{geometry}
\usepackage{morefloats}
\usepackage{bbm}
\usepackage{color}
\usepackage{enumerate}
\usepackage{bigints}
\usepackage{float}

\begin{document}
... which implies that
\label{sharpideq1} \begin{aligned} \mathbb{P}(G_{\cdot 1}=g_{\bullet,1}|W_1=w_1,N=n) \times ... & \times \mathbb{P}(G_{\cdot N}=g_{\bullet,N}|W_N=w_N,N=n) \\ & \leq \prod_{j=1}^{N} \mathbb{P}(S_{\theta_u}^{(j)} \cap \tilde{K}^{(b,j)}\neq \emptyset|W_j=w_j,N=n) \end{aligned}
\colorbox{yellow}{Since $\epsilon_{\cdot j}$ are independently distributed across $j$ under Assumption 1}, \colorbox{yellow}{$G_{\cdot j}$ and $S^{(j)}_{\theta_u}$ are}
\colorbox{yellow}{independently distributed across $j$ conditioned on $W_j,N$}. Thus,
$$\label{sharpideq2} \mathbb{P}(G=g|X=x,N=n)=\mathbb{P}(G_{\cdot 1}=g_{\bullet,1}|W_1=w_1,N=n) \times ... \times \mathbb{P}(G_{\cdot N}=g_{\bullet,N}|W_N=w_N,N=n)$$
as illustrated in this example
% \begin{figure}[H]
% \begin{center}
% \centerline{\includegraphics[scale=0.6]{sharpideq2.pdf}}
% \end{center}
% \caption{Blah blah}
% \end{figure}
For the same reason
$$\label{sharpideq3} \mathbb{P}(S_{\theta_u} \cap K^b \neq \emptyset| X=x,N=n)=\prod_{j=1}^{N} \mathbb{P}(S_{\theta_u}^{(j)} \cap \tilde{K}^{(b,j)}\neq \emptyset|W_j=w_j,N=n)$$

\end{document}

• Do not use the figure-environment. It lets your image float. – Johannes_B Apr 17 '14 at 12:10
• Without the figure environment I get errors and the blank space – user49271 Apr 17 '14 at 12:13
• You can set a caption using package capt-of. Furthermore, if leaving out the figure-environment, put everything inside of a minipage. This prevents a pagebreak. When using a figure-env, use \centering instead of the center-env. – Johannes_B Apr 17 '14 at 12:15
• Another advice, you can make your margins visible using package showframe or option showframe to package geometry. Setting the margins with geometry is recommended, by the way. – Johannes_B Apr 17 '14 at 12:16
• Sorry, i don't have time right now. Maybe someone else can. But first another hint: Open your pdf in a pdf viewer? Is there whitespace around it? Crop it externally (pdfcrop) or internally using options of inlcudegraphics. – Johannes_B Apr 17 '14 at 12:28

## 1 Answer

Use \usepackage{capt-of} and then:

as illustrated in this example
\begin{center}
\includegraphics[scale=0.6]{sharpideq2.pdf}

\captionof{figure}{Blah blah}
\end{center}
For the same reason


\documentclass[11 pt,a4paper,oneside,openany, notitlepage]{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{amsmath, amssymb}
\usepackage{amsthm}
\usepackage{amsfonts}
\marginparwidth 0pt
\oddsidemargin 0pt
\evensidemargin 0pt
\marginparsep 0pt
\linespread{1.5}
\topmargin 0pt
\textwidth 6.5in
\textheight 8.5 in
\usepackage{geometry}
\usepackage{morefloats}
\usepackage{bbm}
\usepackage{enumerate}
\usepackage{bigints}
\usepackage{float}
\usepackage{capt-of}

\begin{document}
... which implies that
\label{sharpideq1} \begin{aligned} \mathbb{P}(G_{\cdot 1}=g_{\bullet,1}|W_1=w_1,N=n) \times ... & \times \mathbb{P}(G_{\cdot N}=g_{\bullet,N}|W_N=w_N,N=n) \\ & \leq \prod_{j=1}^{N} \mathbb{P}(S_{\theta_u}^{(j)} \cap \tilde{K}^{(b,j)}\neq \emptyset|W_j=w_j,N=n) \end{aligned}
\colorbox{yellow}{Since $\epsilon_{\cdot j}$ are independently distributed across $j$ under Assumption 1}, \colorbox{yellow}{$G_{\cdot j}$ and $S^{(j)}_{\theta_u}$ are}
\colorbox{yellow}{independently distributed across $j$ conditioned on $W_j,N$}. Thus,
$$\label{sharpideq2} \mathbb{P}(G=g|X=x,N=n)=\mathbb{P}(G_{\cdot 1}=g_{\bullet,1}|W_1=w_1,N=n) \times ... \times \mathbb{P}(G_{\cdot N}=g_{\bullet,N}|W_N=w_N,N=n)$$
as illustrated in this example
\begin{center}
\rule{3cm}{4cm}

\captionof{figure}{zzzz}
\end{center}
For the same reason
$$\label{sharpideq3} \mathbb{P}(S_{\theta_u} \cap K^b \neq \emptyset| X=x,N=n)=\prod_{j=1}^{N} \mathbb{P}(S_{\theta_u}^{(j)} \cap \tilde{K}^{(b,j)}\neq \emptyset|W_j=w_j,N=n)$$

\end{document}


Unrelated comments on your preamble:

\documentclass[11 pt,a4paper,oneside,openany, notitlepage]{article}


11 pt works by accident but it's better to use 11pt this isn't a length specification (where spaces can be used around the unit) it is the name of an option.

\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{amsmath, amssymb, graphics}


You have already loaded graphicx so graphics does nothing here.

\usepackage{amsthm}
\usepackage{amsfonts}


You have already loaded amssymb so amsfonts does nothing here

\marginparwidth 0pt
\oddsidemargin 0pt
\evensidemargin 0pt
\marginparsep 0pt
\linespread{1.5}
\topmargin 0pt
\textwidth 6.5in
\textheight 8.5 in


These are TeX primitive settings but it is better to use the geometry package which you define later (and it's a bit unusual to explicitly specify a4paper in the document class options but then set the size of the text block in inches.)

\usepackage{epsfig}


Do not use this package unless you are using fragments using the \epsfig command popular with LaTeX2.09 in the 1980's.

\usepackage{geometry}


This package is loaded but not used (see above)

• It doesn't work – user49271 Apr 17 '14 at 12:58
• @user49271 "it doesn't work" isn't a useful comment: It does what it is designed to do if used correctly. If it didn't do what you want then you need to say (a) what it did (b) what you want and (c) what exact document you used. (unless you mean the error about the extra } in the initial version of this post :-) – David Carlisle Apr 17 '14 at 13:03
• Yes, sorry: it does not display any error but it places the figure alone in the middle of page 2 without avoiding the blank spaces. I'm using \documentclass[11 pt,a4paper,oneside,openany, notitlepage]{article} – user49271 Apr 17 '14 at 13:06
• @user49271 The figure may come on page 2 (impossible to tell as you have not provided a working example) but it will not move if entered as above so it will be between as illustrated in this example and For the same reason where the page break happens depends on code that you have not shown, so I can not comment. – David Carlisle Apr 17 '14 at 13:17
• @user49271 see picture added to answer – David Carlisle Apr 17 '14 at 13:22