[Tex/LaTex] Inserted Picture Position & Picture Size

graphicspositioning

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}
\linespread{1.25}

\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

\section{Task 1}\label{task1}
\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}

Best Answer

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}

enter image description here

\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.

Related Question