32

I want to fix my figure in slide (latex frame) as per my wish with x,y position specification.

3 Answers 3

28

You could use the textpos package for absolute positioning of figures or text boxes.

Here's an example:

\documentclass[demo]{beamer}
\usepackage[absolute,overlay]{textpos}
  \setlength{\TPHorizModule}{1mm}
  \setlength{\TPVertModule}{1mm}
\begin{document}
 \begin{frame}
   \begin{textblock}{20}(40,20)
      \includegraphics{file}
    \end{textblock}
 \end{frame}
\end{document}

with the syntax \begin{textblock}{*width*}(*x-position,y-position*)

4
  • 4
    \begin{picture}(50,50) \put(250,0){\hbox{\includegraphics[scale=0.3]{figs/set}}} \end{picture} This works simply to locate picture... Kindly give your suggestion over this code with your code. Oct 25, 2011 at 14:11
  • @PalaniKannan: good! You could make an answer from that code in your comment.
    – Stefan Kottwitz
    Oct 25, 2011 at 14:13
  • @PalaniKannan: with textpos you could use a grid, relative positioning, and positioning on the background, For a simple single placement a picture environment is also fine.
    – Stefan Kottwitz
    Oct 25, 2011 at 14:17
  • with this solution I could only place one image in the document, the second would not appear
    – anydoby
    Jan 30 at 14:58
17

As far as I remember,

\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{calc}

...

\begin{tikzpicture}[remember picture,overlay]
  \node[anchor=south west,inner sep=0pt] at ($(current page.south west)+(2cm,5cm)$) {
     \includegraphics{imgfile}
  };
\end{tikzpicture}

should place imgfile.pdf at x=2cm and y=5cm from the lower left page corner.

4
  • 1
    A more convenient and flexible macro for absolute positioning is given here: tex.stackexchange.com/a/311031 .
    – AlexG
    Jun 28, 2016 at 8:24
  • When I run this, I get " ! LaTeX Error: Cannot determine size of graphic in img.png (no BoundingBox). "
    – user43326
    Aug 16, 2018 at 14:46
  • Something must be wrong with your img.png. Try example-image.
    – AlexG
    Aug 16, 2018 at 14:56
  • Actually the code works if I compile with pdflatex, but it doesn't if I try to compile with latex. So presumably the issue is not with the image file.
    – user43326
    Aug 16, 2018 at 17:11
15

As suggested by @PalaniKannan you could do the following:

\begin{picture}(50,50)
\put(200,-300){\hbox{\includegraphics[scale=0.3]{file}}}
\end{picture}

This will place the image at position "200 right and 300 down" relative to the top left corner of the current page.

Also have a look at this wiki page.

5
  • 1
    I'd rather recommend {50,100} for the start position and [width=0.66\textwidth,height=0.5\textheight,keepaspectratio] for the scaling, but the picture environment is the way to go for simple things.
    – stefanct
    Aug 6, 2018 at 14:12
  • 1
    This code is useless for absolute positioning, because the picture environment is placed at the current position.
    – AlexG
    Aug 17, 2018 at 14:42
  • @AlexG it can work for uses by putting it as the first command in the slide and using a size (0,0) environment (so that it does not move stuff coming after it). The actual size is then set by \includegraphics and the position by \put. I used this before the \titlepage command and it worked for me.
    – fqq
    Dec 11, 2019 at 16:35
  • 1
    @fqq OP asked for absolute positioning, which means relative to the paper edges. In the way you suggest, even with a zero-size picture, (200,-300) would still be relative to the reference point of picture at the time of its use, which is, at best, the upper left corner of the text area.
    – AlexG
    Dec 11, 2019 at 16:56
  • Yes, I agree, indeed (0,0) does not put the figure in the upper left corner of the page. Your answer gives absolute positioning, this is a less reliable hack with (slightly) simpler code.
    – fqq
    Dec 11, 2019 at 17:13

You must log in to answer this question.

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