4

For the sake of using captions I'd like to put my graphics into a \begin{figure} ... environment. Doing that a white space is added before and after the picture, table or whatever.

This answer is actually quite clear on how to avoid this.

But setting all lengths affecting float separation to zero has no effect:

\setlength{\textfloatsep}{0pt plus 0pt minus 0pt}
\setlength{\floatsep}{0pt plus 0pt minus 0pt}
\setlength{\intextsep}{0pt plus 0pt minus 0pt}

How can I insert a picture in using

\begin{figure}
\includegraphics ...
...

without any margins?


MWE:

\documentclass{beamer}

\beamersetrightmargin{0.1\paperwidth}
\beamersetleftmargin{0.1\paperwidth}

\setlength{\textfloatsep}{0pt plus 0pt minus 0pt}
\setlength{\floatsep}{0pt plus 0pt minus 0pt}
\setlength{\intextsep}{0pt plus 0pt minus 0pt}

\begin{document}

\begin{columns}

\column{.5\textwidth}
Some text.
\begin{figure}
\framebox[\textwidth][c]{\strut figure one}
\end{figure}
Some text.

\column{.5\textwidth}
Some text.
\framebox[\textwidth][c]{\strut figure two}
Some text.
\end{columns}

\end{document}

enter image description here


1 Answers1

9

In beamer figure is not a float. Its definition is

\newenvironment{figure}[1][]{%
  \def\@captype{figure}%
  \par\nobreak\begin{center}\nobreak}
  {\par\nobreak\end{center}}

and the space you get is inserted by the center environment. You can redefine the environment:

\makeatletter
\renewenvironment{figure}[1][]{%
  \def\@captype{figure}%
  \par\centering}
  {\par}
\makeatother
Ulrike Fischer
  • 327,261
  • Interesting. Took me quite a while to go from question to question until finding this solution. Is there a reason why the figure environment is defined in the other way by default? (Is it sensible)? And is there possibly an easier way (like a toggle) to fix this in the future? – clel Mar 12 '24 at 13:41
  • Also see my follow-up question: https://tex.stackexchange.com/questions/712936/how-to-set-the-spacing-between-figures-in-beamer-floats – clel Mar 12 '24 at 13:54
  • 1
    @clel floats in a presentation don't make much sense. You typically know where you want to place the figure. – Ulrike Fischer Mar 12 '24 at 13:58
  • If I have a column layout (or even without that) and want to place two figures on top of each other, I want to be able to modify the default space between them (as it is currently too much for my use case). This is similar to modifying the space between figure and caption. Probably they are not floats, then, but as a user (in this role), I don't care about the technical details. – clel Mar 12 '24 at 14:17