68

I have a figure in my paper (I am using IEEEtran package). After this figure there exists a space between the figure and the text. How can I reduce the size of this white space. To be specific the space is between the caption of the figure and the text of my paper. Any suggestions?

Werner
  • 603,163
sheet_ethics
  • 2,921

5 Answers5

67

This depends on the location of the float - if the float is at the top of the page, the gap between the caption and the text is \textfloatsep, while the gap for a float in the middle of the page is given by \intextsep.

From the layouts package documentation it is possible to see the lengths in terms of page/document float elements (p 21 onward):

enter image description here

Default for ieeetran are

  • \textfloatsep: 1.7\baselineskip plus 0.2\baselineskip minus 0.5\baselineskip
  • \intextsep: \baselineskip plus 0.2\baselineskip minus 0.2\baselineskip

and therefore depends on the choice of the default font (since that sets \baselineskip). The default pt-form is therefore

  • \textfloatsep: 20.4pt plus 2.4pt minus 4.8pt
  • \intextsep: 12.0pt plus 2.4pt minus 2.4pt

in the 10pt font size. The above includes some stretch/shrink. You can modify them using \setlength. For example,

\setlength{\textfloatsep}{\baselineskip plus 0.2\baselineskip minus 0.2\baselineskip}

would allow for between (roughly) 10pt and 15pt gap between the float and the text. Something like

\setlength{\textfloatsep}{5pt}

would fix the distance to 5pt (without stretch/shrink).

Werner
  • 603,163
  • I'm having a huge space between the end of a paragraph and the beginning of the next one, I don't know the reason, I'm using IEEE trans template – Tak Jul 30 '13 at 03:42
  • @user1460166: What do you have around these paragraphs? What float specifiers do you use for any floats around it? – Werner Jul 30 '13 at 03:52
  • I have a float after the end of the paragraph \begin{figure}[t] \begin{figure}[t] \centering { \begin{tikzpicture}[remember picture] \node[mynode] (image2) {\includegraphics[width=\linewidth]{avghist}}; \end{tikzpicture}} \begin{tikzpicture}[remember picture,overlay] \end{tikzpicture} \caption{} \label{} \end{figure} \begin{figure}[pht] {\includegraphics[width=\linewidth]{squash3}}\caption{AA} \label{} \end{figure} \begin{table}[pht] \begin{tabularx}{\linewidth}{@{}>{\hsize=0.8\hsize}X 2{>{\hsize=1.1\hsize}X}@{}} \toprule \bottomrule \end{tabularx} \caption{AAA} \label{} \end{table*} – Tak Jul 30 '13 at 03:58
  • @user1460166: Do you really have 2 figures (nested)? It's difficult to gauge what else might be the problem. – Werner Jul 30 '13 at 04:16
  • I have two figures then a table – Tak Jul 30 '13 at 04:20
  • @user1460166: If that's it after the paragraph, how about trying to add \raggedbottom to your document. If you're using the twocolumn document option (which I'm guessing you are), the default is \flushbottom. – Werner Jul 30 '13 at 04:25
  • it worked but now instead of having couple of medium white spaces in this page I have one large white space, I think its something related to [H], but I can't figure out the solution – Tak Jul 30 '13 at 04:47
  • @user1460166: Yes, if you're using [H], the it's actually not a float. However, you don't mention that in some of the code snippets you posted. I think you should ask a new question and give all the details necessary to solve the problem. – Werner Jul 30 '13 at 04:54
  • I've asked a new question found here if you could assist me, thanks http://tex.stackexchange.com/questions/125991/white-space-in-file – Tak Jul 30 '13 at 05:08
  • Can I change these parameter such as \textfloatsep onlyt locally in one section or from a certain point? I want to try to get some floats to fit together in my appendix but I don't want to affect the nice look of the main text. – Marten Dec 11 '20 at 18:42
  • @Kvothe: Yes, sure. I'd store the length, then change it, then restore it. You may have to leave about a page or so of leeway for the changes to have an effect, as the lengths are considered when building a page, so not immediately surrounding a float construction. Alternatively, if you want to keep certain figures together, you can put them in the same float. Yes, two \includegraphics with two \captions in the same figure environment. Then you can space them out with \vspace{\floatsep} (or portions thereof). All kinds of possibilities. :) – Werner Dec 11 '20 at 22:27
  • Can the space between figure and its caption could be removed as well? – alper May 30 '22 at 16:35
  • @alper: Adjustments like that can be done via the caption package. For example, look at the length abovecaptionskip and belowcaptionskip in the caption documentation. – Werner May 31 '22 at 15:46
31

If you do not want to modify the standard template and just want a quick fix for this, you may add the following command to your document preamble:

\newcommand{\squeezeup}{\vspace{-2.5mm}}

Then, you can use the command \squeezeup throughout your document for reducing the free space after/before figures, formulas, etc., as needed.

Ali
  • 1,824
20

Werner's answer is obviously a good one. However, I encountered a gotcha.

Using a setting like he suggested:

\setlength{\textfloatsep}{\baselineskip plus 0.2\baselineskip minus 0.5\baselineskip}

produced a cryptic error:

Package calc Error: 'p' invalid at this point...0.2\baselineskip minus 0.5\baselineskip}

After some playing around, I found out that it stumbles over the plus ... minus construction in combination with the \baseline command. What works is to multiply the lone \baseline by 1:

\setlength{\textfloatsep}{1\baselineskip plus 0.2\baselineskip minus 0.5\baselineskip}

Using lengths like 5pt instead of the baseline command is unproblematic.

rumtscho
  • 989
8

You can use etoolbox package. Just set a \vskip with a negative value at the start (\BeforeBeginEnvironment or \AtBeginEnvironment) and at the end (\AfterEndEnvironment) of the environment figure.

MWE:

\documentclass{IEEEtran}

\usepackage{lipsum}

\usepackage{etoolbox}

\BeforeBeginEnvironment{figure}{\vskip-2ex}
\AfterEndEnvironment{figure}{\vskip-1ex}

\begin{document}

  \lipsum[1]

  \begin{figure}[h]
    \includegraphics{your_figure}
    \caption{text}
  \end{figure}

  \lipsum[1]

\end{document}
azetina
  • 28,884
1

Try this code, you can use \vspace{-10mm} in the figure code:

\begin{figure} 
    \centering
    \subfloat[\label{fig_2a}]{%
        \includegraphics[width=0.45\linewidth]{Figures/Coss.eps}}
    \hfill
    \subfloat[\label{fig_2b}]{%
        \includegraphics[width=0.45\linewidth]{Figures/Energy.pdf}}
    \\
    \caption{Nonlinear output capacitance characteristics of the MOSFETs  } \label{fig_2}
    \vspace{-10mm}%Put here to reduce too much white space after your table 
\end{figure}