23

I have a beamer presentation with a custom style which creates a red bar along the bottom of each slide. When I change the geometry and then revert it with restoregeometry, the red bar is now shifted to the right. The aim is just to have the picture full width.

\documentclass{beamer}   
\mode<presentation>
 {
\usetheme{myslides}
 }

\begin{document}

\begin{frame}[fragile]
\frametitle{}

\begin{center}
\huge Introduction?
\end{center}
\end{frame}

\newgeometry{margin=0pt}

\begin{frame}[fragile, plain]
\frametitle{}
\includegraphics[width=\paperwidth, width=\paperwidth]{picture}
\end{frame}

\restoregeometry
\begin{frame}[fragile]
\frametitle{}
\begin{center}
\huge Next slide?
\end{center}
\end{frame}
\end{document}

How can I restore back to exactly the state it was in before the newgeometry command?

My question seems related to beamer: frame without decorations, with custom margin as well where there is a similar problem with \restoregeometry in one of the answers.

1
  • 1
    Why don't you make the changes local, as in this answer?
    – Jost
    Nov 7, 2013 at 13:03

4 Answers 4

31

Without having access to your beamer theme nor to the image, it is difficult to test. But if you know the size of your margins the following (dirty but simple) solution might work.

\vspace*{-6.5mm}    
\begin{frame}[plain]
    \hspace*{-19mm}
    \includegraphics[width=\paperwidth]{picture}
\end{frame} 

(to be used without any geometry resetting commands)


Or without manually fiddling around with the size of the margins:

\documentclass{beamer}

\makeatletter
\newlength\beamerleftmargin
\setlength\beamerleftmargin{\Gm@lmargin}
\makeatother

\begin{document}
     
\begin{frame}[plain]
    \hspace*{-\beamerleftmargin}%
    \includegraphics[width=\paperwidth]{example-image}
\end{frame} 

\end{document}

enter image description here

15
  • Thank you. I had to play with the exact size for \hspace*{-19mm} but with -7mm it worked perfectly.
    – Simd
    Nov 14, 2013 at 13:06
  • I've been struggling with this for a long time now, thanks for \Gm@lmargin. Jun 11, 2017 at 8:20
  • The answer below by Benjamin, to me, seems much more useful. If you end up here you might want to check that answer as well although it has by far less points. Oct 18, 2020 at 13:27
  • @Nobody-Knows-I-am-a-Dog Sure, if you want to mess up all following frames... Oct 18, 2020 at 13:41
  • @samcarter_is_at_topanswers.xyz How come? Would one not restrict the changes to a local scope? That way it should work. Or undoing the change explicitly if you want. Oct 18, 2020 at 15:43
14

A plain frame with a background image can be locally applied without need for changing and restoring geometry changes

\documentclass{beamer}   
\mode<presentation>
 {
\usetheme{Berkeley} %<-- We don't have `myslides` theme
 }

\begin{document}

\begin{frame}[fragile]
\frametitle{}

\begin{center}
\huge Introduction?
\end{center}
\end{frame}

{%<--- Start local changes
\setbeamertemplate{navigation symbols}{}
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{example-image}}
\begin{frame}[plain]
\end{frame}
}%<---- Finish local changes

\begin{frame}[fragile]
\frametitle{}
\begin{center}
\huge Next slide?
\end{center}
\end{frame}
\end{document}

enter image description here

10

A very simple solution using tikz:

\documentclass{beamer}

\usepackage{tikz}

\begin{document}

\begin{frame}[plain]
    \begin{tikzpicture}[remember picture,overlay]
        \node[at=(current page.center)] {
            \includegraphics[width=\paperwidth, height=\paperheight]{example-image}
        };
    \end{tikzpicture}
\end{frame}

\end{document}

[has to be compiled two times to get the coordinates right]

2
4

EDIT: I should have tested this in more detail before posting. It seems that the following frames have their geometry/layout modified... So please be aware that there might be some issues.

After looking at different answers and comments from different questions around this problem of beamer still having a left margin in plain frames, let me post the solution I just found, to get a really empty plain frame, no margins etc. in an easy automated generic way. In such a frame, one can do as wished, for example put a graphic that exactly takes the whole width of the frame, or center it with exactly the same left and right spaces, without having to cheat with horizontal offsets or whatever.

The problem I had was that \setbeamersize{text margin left=0pt} or the likes can't be used in a local way, it has to be in the preamble, it can't be in the body and also not in command or environment definitions.

The solution was to use \newgeometry, as used in the OPs question, from the geometry package, loaded by beamer, and restrain it locally as suggested in the comment above. And it needs no fancy stuff, no ad hoc lengths, etc.

It seems that it hasn't been posted like I am about to do, and I think it could be interesting to a wide audience (I looked long before finding it). And the only other answer I know of that needs no ad hoc ajustments, namely this one, uses little more beamer-hacking knowledge.

Solution for one isolated frame:

{\newgeometry{margin=0pt} %locally set margins to zero
 \setbeamertemplate{background canvas}[default] %not too sure, but may be needed if you have a background image
 \begin{frame}[plain]
 %frame content  that can really fill the whole page
 \end{frame}
}

And if you need this on a regular basis, define it as a new environment, e.g. emptyframe, in the preamble:

\newenvironment{emptyframe}
{
 % not too sure, but may be needed if you have a background image
 % that should not appear on this kind of frame:
 \setbeamertemplate{background canvas}[default] 
 % locally set margins to zero: (notice the use of \bgroup ... \egroup
 % to limit the scope of the geometry restriction
 % where curly brackets {} aren't possible)
 \bgroup \newgeometry{margin=0cm} 
 \begin{frame}[plain]
}
{
 \end{frame}
 \egroup
}

After that, in the body of the document, use it alternatively to a frame environment:

\begin{emptyframe}
% frame content that can really fill the whole page
\end{emptyframe}

Note 1: you might also need to turn off navigation symbols. To this effect, add \setbeamertemplate{navigation symbols}{} next to \setbeamertemplate{background canvas}[default].

Note 2: this solution is not limited to getting empty frames, it is (I think, didn't test) customizable up to the limits of \newgeometry.

2
  • This is awesome; it's by far one of the easiest ways to insert figures in beamer with \newcommand, without worrying about size or placement.
    – user9424
    Feb 1, 2018 at 12:11
  • There is a missing backslash before newgeometry in the isolated frame example.
    – rkta
    May 21, 2019 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .