89

I am making a presentation using beamer, and I want to be able to position a certain image the way I want in a frame. I am not sure how to do that. Is there some way you can specify coordinates in the frame and then set an image there?

Is there a better way to place images in various places with the beamer class?

1

3 Answers 3

64

When I used such an application, I used either TikZ (my favorite), or, before knowing of TikZ, I used the textpos package.

I will briefly discuss both solutions.

TikZ

I suggest to use a TikZ \node with overlay option.

NOTE: there are two ways to use TikZ here: one with RELATIVE positioning (the approach discussed below) and one with ABSOLUTE positioning (please refer to the TikZ manual for such a task).

The overlay means that it has no bounding box, i.e. it won't affect the existing layout. I wrote a short-cut macro around to simplify the generation of such a node. To use it, place the following code into you beamer document:

\tikzset{
  every overlay node/.style={
    draw=black,fill=white,rounded corners,anchor=north west,
  },
}
% Usage:
% \tikzoverlay at (-1cm,-5cm) {content};
% or
% \tikzoverlay[text width=5cm] at (-1cm,-5cm) {content};
\def\tikzoverlay{%
   \tikz[baseline,overlay]\node[every overlay node]
}%

So, the basic idea is a \node[overlay] which aligns well within the usual text (the baseline option). You will need to use the at (<x>,<y>) positioning to actually place it. The placement will be relative to the embedding text. Keep in mind that you may hide text with this thing (which is the purpose of the every overlay node style as you guessed correctly). Note that text later in the document is always typeset after earlier text passages. In other words: make sure the \tikzoverlay command comes after things you want to hide.

An example could be

Here is the text which will probably be hidden by the overlay.
\tikzoverlay[text width=6cm] at (9.3cm,5cm) {
  \begin{itemize}
  \item \emph{Derive subclass} from \texttt{GetOptWrapper}
  \item one \emph{variable definition} per option
  \item \emph{Default Values}
  \end{itemize}
};

You can safely combine this with beamer's \only<2> methods.

textpos

The second promised approach uses the textpos package. Since I think that this approach is weaker and less configurable than the one above, I simply copy-paste from my personal notes:

According to my old notes, the general usage is:

\usepackage{textpos}
\setlength{\TPHorizModule}{1cm} % horizontal unit
\setlength{\TPVertModule}{1cm} % vertical unit
...
\begin{textblock}{WIDTH}(OFFSET_X,OFFSET_Y)
CONTENT
\end{textblock}
...

Example with the package configuration above:

\definecolor{boxcol}{gray}{0.89}
\begin{textblock}{3}(8,-3)
\fcolorbox{black}{boxcol}{%
\begin{minipage}{\textwidth}
\setlength{\parindent}{0pt}%
\setlength{\parskip}{0.1cm}%
A notice that was put in the page using coordinates
\end{minipage}
}%
\end{textblock}%
2
  • 2
    If you use textpos with beamer, you likely want the overlay option, as in \usepackage[absolute,overlay]{textpos}.
    – Jed
    Mar 2, 2012 at 20:59
  • How do the commands work with only the title page i.e. you want to have the logo only on the title page not on other pages? I am using the ready commands such as \maketitle should I use \begin{titlepage} and configure the titlepage like here?
    – hhh
    Jan 15, 2020 at 8:02
54

Solution without defining new variables or calling extra packages (other than Tikz):

For example, to put a figure in the top right corner, you can use:

\begin{tikzpicture}[remember picture,overlay]
    \node[xshift=-2cm,yshift=-2cm] at (current page.north east) {\includegraphics{photo.png}};
\end{tikzpicture}

The key is in the combination of current page.north east (which sets the anchor) and xshift={...},yshift={...} (which moves the node from that anchor). Notice that you can use any other anchor like current page.north west, current page.south west, current page.center, etc.

For more information, see Section 17.13.2 of the Tikz manual (it's just one page long).

3
  • Where do you place this tikz command in Title page of beamer document? I could not get it working inside author -command, other?
    – hhh
    Jan 15, 2020 at 8:01
  • @hhh for the title slide, follow this.
    – luchonacho
    Jan 15, 2020 at 8:22
  • 1
    Thank you, this was the answer that worked best for me. It was much less clear how to modify the accepted answer to get good control over the position (it seemed to interact poorly with slide content).
    – MRule
    Jun 17, 2022 at 12:21
5

The following code snipped uses remember picture for positioning.

\usetikzlibrary{calc}

\begin{frame}
\tikz[overlay,remember picture]
\node[anchor=north east] at ($(current page.north east)+(0,-1)$) {
  Top-right float content.
};

Regular content.
\end{frame}

It also uses the calc tikz library to specify an offset from the top left corner for positioning of the node, relative to the upper right corner. This will likely be a popular use case for positioning logos. X is right, and Y is up, so you will want negative offsets.

2
  • The \tikz macro and the tikzpicture environment are strictly equivalent... Jun 26, 2015 at 14:54
  • Thanks, I wasn't aware of that. In my case, I needed to nest another (sourced) tikzpicture, and I didn't want to stack a tikzpicture inside a tikzpicture, but apparently that would have worked reasonably well (I believe I have some errors because of that...) Also, I didn't get newlines working (as usual with tikz nodes) without specifying a node width. Jun 26, 2015 at 14:59

You must log in to answer this question.