I am trying to put some TikZ pictures into a Beamer slide to enhance readability. The position of the TikZ pictures on the slide will depend on how much text comes before. Since there will be many TikZ pictures, and each will have to be adjusted by the same amount if I change the text at the top of the slide, I tried to make a macro to avoid having to adjust the position of each TikZ picture manually each time I change the text..
Consider the following code:
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\pgfmathsetmacro{\yoff}{5}
\newcommand{\print}[1]{\pgfmathparse{#1}\pgfmathresult}
\begin{frame}
\frametitle{Testing}
\begin{itemize}
\item Test picture
\begin{picture}(0, 0)
\put(0,\print{8+\yoff}){
\tikz \draw[red,thick] (0,0) ellipse (5pt and 5pt);
}
\end{picture}
\end{itemize}
\end{frame}
\end{document}
Here I get the following error:
! Missing number, treated as zero.
\begingroupl.17 \end{frame}
However, putting the macro within the \frametitle of the slide works as expected (without errors):
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\pgfmathsetmacro{\yoff}{5}
\newcommand{\print}[1]{\pgfmathparse{#1}\pgfmathresult}
\begin{frame}
\frametitle{Testing \print{8+\yoff}}
\begin{itemize}
\item Test picture
\begin{picture}(0, 0)
\put(0,\yoff){
\tikz \draw[red,thick] (0,0) ellipse (5pt and 5pt);
}
\end{picture}
\end{itemize}
\end{frame}
\end{document}
\def\yoff{5}with\pgfmathsetmacro{\yoff}{5}I get the error message:! Illegal unit of measure (pt inserted)– Håkon Hægland Jan 15 '13 at 10:25\pgfmathsetmacro{\yoff}{5}sets yoff to5.0not5and that isn't a number according to primitive TeX number syntax (which has to be an integer literal) – David Carlisle Jan 15 '13 at 10:30\putaccepts decimal numbers like\put(1.3,2.5).. What if I define\def\yoff{5.5}.. How can I deal with this situation? – Håkon Hægland Jan 15 '13 at 10:48picturepackage (by Heiko Oberdiek) one can also use\put(<dimen>,<dimen>)– egreg Jan 15 '13 at 12:49\putneeds something that expands to a number, and later you say that 5.0 is not a number according to primitive TeX, next we use the strip@pt to create something like, e.g., 9.5.. Now suddenly\putaccepts a decimal.. What am I missing here? – Håkon Hægland Jan 15 '13 at 14:51\unitlengthso5.0is OK. So an addition method that uses (say)\defto store intermediate results would not work. So "number" there was rather loose and included decimal values. But in\numexprIt has to be what TeXBook calls<number>which is essentially an integer as used by latex counters etc. So there I switched meaning of number to that technical syntax production, sorry. – David Carlisle Jan 15 '13 at 15:14\put(0,\print{8+\yoff}), however I can define another variable say\ytestusing the following code on the line before\put:\pgfmathparse{8+\yoff} \pgfmathsetmacro{\ytest}{\pgfmathresult}, and then use\put(0,\ytest)which now works.. Maybe this is somehow related to the following post : store-pgfmathresult-in-a-variable ? – Håkon Hægland Jan 15 '13 at 16:30\printcommand does not just work via expansion it defines internal macros as part of its definition so it can not be used inline in \put. It is exactly the same as you can go \def\foo{3pt} \dimen@=\foo but you can not go \dimen@=\def\foo{3pt}\foo you can not have the definition inline in teh length setting, it has yo be first, or not there at al \dimen@=3pt – David Carlisle Jan 15 '13 at 18:15\printinline in\frametitle(but not in\put) ? – Håkon Hægland Jan 15 '13 at 18:40