How exactly does positioning in beamer+tikz work?
- where is the absolute origin (0,0) on a slide? Why when I specify (0,0) does it seem to move around the slide depending on the size of whats being plotted? Does it exist absolutely somewhere?
- Can I draw the absolute grid (as opposed to some grid) with absolute positioning information on slides to help me when trying to position items?
- Can someone help me make sense of the example below?
Im reading and rereading the tikz (especially chapter 13) and beamer documentation, but cant seem to figure out what is going on.
\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{tikz,ifthen}
\usetikzlibrary{calc, intersections,through,backgrounds}
\usepackage{pgfpages}
\usetheme[progressbar=frametitle]{metropolis}
\usepackage{amsmath,amssymb,amsthm,mathrsfs,bbm,bm}
\usepackage{graphicx,subcaption,float,enumerate}
\begin{document}
\begin{frame}{Slide}
\begin{tikzpicture}
\draw[help lines] (0,0) grid (0.5\textwidth,0.5\textheight);
\end{tikzpicture}
\end{frame}
\end{document}
When I remove the 0.5
, why is the grid off the slide in all dimensions?
Note: There is this related unanswered question. This question is not specifically about this MWE, just in general how to look at a slide, pick a point with my eye, and put something there exactly and absolutely in tikz.
Best Answer
If you use
remember picture, overlay
as options to atikzpicture
you can then usecurrent page
as a coordinate (well actually you use.north
or stuff like that, just like you can usenode.north
as the top of a node namednode
).The
remember picture
has the effect that the positioning of the picture is adapted to match the specified positions because thetikzpicture
is not guaranteed to be at the bottom left of the current page -- you use it somewhere in theframe
environment and it is there as far as LaTeX is concerned. TikZ stores that position in the .aux file and moves the picture accordingly on the second run. Therefore you need at least two runs with this approach to get correct positioning.overlay
just makes sure that your picture doesn't have a size as far as LaTeX's typesetting is concerned (it still introduces white space around the spot it is used in if used at the wrong place -- make sure to not start a new paragraph accidentally and put a%
after\end{tikzpicture}
to not introduce unwanted spaces).If you want to place arbitrary stuff on a specified coordinate on a frame, I'd use a
\node
in atikzpicture
which I know is on that slide. For a small template I created for myself I used the following approach:Put a
tikzpicture
in the beamer templatebackground
. In thattikzpicture
put a macro like\MyPlacedStuff
and after thetikzpicture
put\gdef\MyPlacedStuff{}
.In a
frame
you can now add stuff with\xdef\MyPlacedStuff{\unexpanded\expandafter{\MyPlacedStuff <stuff you want to place on the slide>}}
You should write a macro or two around point 2 to ease the process.
The following does that and adds the help lines if you use
\HelpLinestrue
outside of the frame (until you use\HelpLinesfalse
).\PlaceAt
takes the coordinates in multiples of\paperwidth
and\paperheight
as first argument in()
, optional arguments to a\node
in[]
, and finally the contents of the node in{}
. The first and last are mandatory, options to the node are optional.\AddToPlaced
takes only one argument, which should be able to contain anything you can add to atikzpicture
.Beware the
background
might already contain stuff which you hereby would overwrite. You'll have to sort that out if it conflicts. It seems to not conflict in your MWE.