我是 LaTeX 新手。我目前正在用它写一份非常简单的学校实验报告。当我尝试通过更改
[width=6.0in]
参数
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}
我不知道图片的最大尺寸是多少,这样图片才不会被“推”到下一页。如果图片太大,我们知道它会被推到下一页。我不希望发生这种情况。
那么,如何确保当我尝试放大图片时,图片不会被推到下一页?
(位置优先。其下的图片应该尽可能大。)
更新:
采用该\MyFig{}{}{}
解决方案,以下代码片段
\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}
产生以下错误:
! 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
是 \MyFig{task1_nmos}{NMOS $I_{DS}$ vs. $V_{DS}$}{nmosfigure}
答案1
更新:
现在,标题已被预先框起来,其高度被测量,然后自动被考虑进去;语法\MyFig
很简单
\MyFig{<image file>}{<caption>}{<label>}
代码:
\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
根据页面上的可用空间缩放图形。它使用包中的minipage
和来提供标题。\captionof
capt-of
答案2
为什么你不这样修改你的代码以便图片的宽度取决于文本的宽度?
\begin{figure}
\centering
\includegraphics[width=\textwidth]{pmos_gamma}
\caption{$V_{BS}=0.1V, 0.3V, 0.5V, 0.7V$}
\label{pmos_gamma}
\end{figure}
如果您仍然收到一些过满的消息和/或不必要的情况,您可能想要将宽度修改为类似的width=0.9\textwidth
。
如果您的照片更多是风景自然,则上述答案适用(宽度大于长度)。如果您的照片更多的是肖像性质的,那么类似\includegraphics[width=\textheight]{pmos_gamma}
或 的内容\includegraphics[width=0.8\textheight]{pmos_gamma}
将适用。
请稍微调整参数以获得最佳效果。
当然,您可以编写一个宏来预先测量尺寸,然后使用某种 if-then 来动态应用尺寸。但在我看来,这有点矫枉过正。