0

According to Setting margins below and above figures does not have any effect in beamer, in beamer, figures are not floats. That is why How to change the spacing between figures/tables and text? doesn't work there.

The question is about removing all margins. However, I want to keep some margins, just modify them appropriately.

Is there a way how to do this in beamer?

MWE:

\documentclass{beamer}

\begin{document}

\begin{frame} \begin{figure}[h] \centering \includegraphics[width=0.4\linewidth]{example-image-a} \caption{Test} \end{figure}

\begin{figure}[h]
    \centering
    \includegraphics[width=0.4\linewidth]{example-image-a}
    \caption{Test}
\end{figure}

\end{frame}

\end{document}

enter image description here

clel
  • 325

1 Answers1

0

Beamer does not have floats. The figure environment is just a glorified center environment and thus is added to the page like any other normal text.

If you want to change the space, you could play around with some vertical space between the figures as needed:

\documentclass{beamer}

\begin{document}

\begin{frame} \begin{figure} \centering \includegraphics[width=0.4\linewidth]{example-image-a} \caption{Test} \end{figure} \vskip-0.5cm \begin{figure} \centering \includegraphics[width=0.4\linewidth]{example-image-a} \caption{Test} \end{figure} \end{frame}

\end{document}

enter image description here

Or not just not use a figure environment and place the images however you like:

\documentclass{beamer}

\usepackage{caption}

\begin{document}

\begin{frame} \centering \includegraphics[width=0.4\linewidth]{example-image-a} \captionof{figure}{Test}

    \includegraphics[width=0.4\linewidth]{example-image-a}
    \captionof{figure}{Test}

\end{frame}

\end{document}

  • What I am looking for is a generalized solution that works a bit like changing \floatsep (i.e. for all figures). I guess that means redefining the figure environment (as in the other question) and adding custom margins there? – clel Mar 12 '24 at 14:07
  • @clel You can certainly add some space to the figure environment, e.g. \AtBeginEnvironment{figure}{\vskip-0.5cm} \AfterEndEnvironment{figure}{\vskip-0.5cm} but be aware that this might lead to misplaced images at the top/bottom of a frame. – samcarter_is_at_topanswers.xyz Mar 12 '24 at 14:10
  • Then, I am looking for an even more robust solution, possibly. Similar to what changing \floatsep does with normal figures.

    Basically, I don't want to customize this for each frame individually (this is very time-consuming and might lead to inconsistencies in style). Also, doing this by removing margin space is not really what I want (as it can mean accidentally removing too much).

    – clel Mar 12 '24 at 14:13
  • 1
    @clel See https://tex.stackexchange.com/a/74215/36296 how to change the spacing around the center environment – samcarter_is_at_topanswers.xyz Mar 12 '24 at 14:24
  • Thanks! Since the center environment might also be used in other cases, I guess, it might not be robust in all cases to change its spacing (not sure, though).

    Probably, the best way is to redefine the figure environment like this:

    \makeatletter
    \renewenvironment{figure}[1][]{%
      \def\@captype{figure}%
      \par\centering}
      {\par}
    \makeatother
    

    And in that add some margins (that got previously removed by using \centering instead of center)?

    – clel Mar 12 '24 at 14:30
  • @clel Have fun aligning your new figures at the top and bottom! – samcarter_is_at_topanswers.xyz Mar 12 '24 at 14:32
  • Hm? You mean that will cause problems? Or are you frustrated by me seeking for an optimal solution for this small problem? Apart from that, possibly, one could also define a new mycenter environment with different margins and then redefine the figure environment using that. – clel Mar 12 '24 at 14:35
  • @clel I'm not frustrated, I just think that your approach to add margins to your new figure will cause more problems than just the space between figures or not using figures are all. – samcarter_is_at_topanswers.xyz Mar 12 '24 at 14:44
  • Right now, to me, that approach seemed to be the one causing the least problems while maintaining highest compatibility at the same time. But I saw the approach with the caption package in your answer. That is also something, I am doing right now in a similar way as a workaround (and it seems to also work with the figure environment). – clel Mar 12 '24 at 14:47