# Inserted Picture Position & Picture Size

I am a newbie in LaTeX. I am currently using it writing a very simple school lab report. I encounter a problem when I try to enlarge the inserted pictures by changing the

[width=6.0in]


parameter in

The graph now becomes Figure~\ref{pmos_gamma}.
\begin{figure}
\centering
\includegraphics[width=6.0in]{pmos_gamma}
\caption{$V_{BS}=0.1V, 0.3V, 0.5V, 0.7V$}
\label{pmos_gamma}
\end{figure}


I cannot know the maximum size of a picture that will not make itself "pushed" to the next page. If the picture is too big, as we know it will be pushed down to next page. I don't wish that to happen.

So how can I ensure the picture will NOT be pushed to the next page while I am trying to enlarge the picture?

(Position highest priority. Under that the picture should be as large as possible.)

Update:

Adopting the \MyFig{}{}{} solution, the following code snippet

\title{blabla}
\author{
blabla
}
\date{\today}

\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx} % for graphics
\usepackage{capt-of}

\newcommand\MyFig[3]{%
\par\medskip\noindent%
\setbox0=\vbox{\captionof{figure}{#1}}%
\begin{minipage}{\textwidth}
\centering
\includegraphics[%
height=\dimexpr\pagegoal-\pagetotal-\abovecaptionskip-\ht0-1\bigskipamount-\medskipamount\relax,
width=\textwidth,keepaspectratio]{#1}
\captionof{figure}{#2}
\label{#3}%
\end{minipage}\par\bigskip%
}

\begin{document}
\maketitle

\begin{abstract}
blabla
\end{abstract}

\section{Introduction}
blabla

\paragraph{Outline}
blabla

\paragraph{2.1 $V_{t0}$}
After the circuit has been set up in \textit{LTSpice} as instructed, the simulations were run. The family of $I-V$ curves generated are shown in Figure~\ref{nmosfigure}.
\MyFig{task1_nmos}{NMOS $I_{DS}$ vs. $V_{DS}$}{nmosfigure}

\end{document}


produces the following errors:

! Missing $inserted. <inserted text>$
l.47 ...s}{NMOS $I_{DS}$ vs. $V_{DS}$}{nmosfigure}
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
! Extra }, or forgotten $. \sbox ...hbox {\color@setgroup #2\color@endgroup } l.47 ...s}{NMOS$I_{DS}$vs.$V_{DS}$}{nmosfigure} I've deleted a group-closing symbol because it seems to be spurious, as in $x}$'. But perhaps the } is legitimate and you forgot something else, as in \hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing I$}'. ! Missing$ inserted.
<inserted text>
$l.47 ...s}{NMOS$I_{DS}$vs.$V_{DS}$}{nmosfigure} I've inserted a begin-math/end-math symbol since I think you left one out. Proceed, with fingers crossed. ! Missing } inserted. <inserted text> } l.47 ...s}{NMOS$I_{DS}$vs.$V_{DS}$}{nmosfigure} I've inserted something that you may have forgotten. (See the <inserted text> above.) With luck, this will get me unwedged. But if you really didn't forget anything, try typing 2' now; then my insertion and my current dilemma will both disappear. ! I can't write on file report.pdf'. Please type another file name for output ! Emergency stop. <argument> ...stobj \GPT@objref }}}\fi \pdfximage \GPT@RuleAttr \ifx \GPT@pa... l.47 ...s}{NMOS$I_{DS}$vs.$V_{DS}$}{nmosfigure} *** (job aborted, file error in nonstop mode) Here is how much of TeX's memory you used: 1654 strings out of 494045 22800 string characters out of 3148364 80363 words of memory out of 3000000 4970 multiletter control sequences out of 15000+200000 9456 words of font info for 33 fonts, out of 3000000 for 9000 715 hyphenation exceptions out of 8191 27i,6n,32p,370b,199s stack positions out of 5000i,500n,10000p,200000b,50000s ! ==> Fatal error occurred, no output PDF file produced!  Line 47 is \MyFig{task1_nmos}{NMOS$I_{DS}$vs.$V_{DS}$}{nmosfigure} ## 2 Answers ## Update: Now the caption is previously boxed, its height measured and then taken into account automatically; the syntax for \MyFig is simply \MyFig{<image file>}{<caption>}{<label>}  The code: \documentclass{article} \usepackage{graphicx} \usepackage{lipsum} \usepackage{capt-of} \newcommand\MyFig[3]{% \par\medskip\noindent% \setbox0=\vbox{\captionof{figure}{#2}}% \begin{minipage}{\textwidth} \centering \includegraphics[% height=\dimexpr\pagegoal-\pagetotal-\abovecaptionskip-\ht0-1\bigskipamount-\medskipamount\relax, width=\textwidth,keepaspectratio]{#1} \captionof{figure}{#2} \label{#3}% \end{minipage}\par\bigskip% } \begin{document} \lipsum[1-3] \MyFig{example-image-a}{adasf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf}{fig:testa} \lipsum[1] \MyFig{example-image-b}{adasf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgsdg sdfgsf sadgs}{fig:testb} \lipsum[1-5] \MyFig{example-image-c}{adasf sadgsdg sdfgsf}{fig:testc} \end{document}  \MyFig scales the figure accordingly to the available space on the page. It uses a minipage and \captionof from the capt-of package to provide a caption. • But that still needs the caption to be manually adjusted? Does it? If that is what you meant by, taking care of the caption height. – Masroor Sep 10 '13 at 3:45 • Thanks! It seems promising. As a newbie, I find it even difficult to apply this to my code. May I ask whether you could apply this to my code given in the question? Just one demo on my code will do. Thanks! – Sibbs Gambling Sep 10 '13 at 3:46 • @MMA you need to give as optional argument the number of lines spanned by the caption. – Gonzalo Medina Sep 10 '13 at 3:47 • @perfectionm1ng my example code shows how to use the macro. Copy the definition of \MyFig in the preamble of your document and then, instead of \begin{figure} \centering \includegraphics[width=\textwidth]{pmos_gamma} \caption{$V_{BS}=0.1V, 0.3V, 0.5V, 0.7V$} \label{pmos_gamma} \end{figure} simply use \MyFig{pmos_gamma}{$V_{BS}=0.1V, 0.3V, 0.5V, 0.7V$}{pmos_gamma} (no need for the optional argument here, since the caption only spans one line). – Gonzalo Medina Sep 10 '13 at 3:49 • @MMA now, in my updated answer, no manual calculations are needed. – Gonzalo Medina Sep 10 '13 at 4:12 Why don't you modify your code like this so that the width of the picture is dependent on text width? \begin{figure} \centering \includegraphics[width=\textwidth]{pmos_gamma} \caption{$V_{BS}=0.1V, 0.3V, 0.5V, 0.7V\$}
\label{pmos_gamma}
\end{figure}


If you still get some overfull message and/or unwanted situation you will want to modify the width to something like width=0.9\textwidth.

The above answer is applicable if your picture is more of a landscape nature (wider than longer). If your picture is more of portrait nature, then something like \includegraphics[width=\textheight]{pmos_gamma} or \includegraphics[width=0.8\textheight]{pmos_gamma}` will be applicable.