# Calculate metric length in LaTeX (e.g. for TikZ)

I would like to calculate the length of elements on a LaTeX beamer frame (128mm*96mm) equivalent to those on a PowerPoint slide (254mm*190.5mm), i.e. apply the factor 128/254 to a value given in mm.

Therefor I would like to implement a function \def\pptsize #1{#1/254*128} which then can be used for instance in TikZ point definitions like \draw (0,0) -- (0,\pptsize{10cm});. Any ideas how to do so?

• \begin{tikzpicture}[scale=128/254] .... – user121799 May 28 '19 at 17:05

You can use xfp:

\documentclass{article}
\usepackage{xfp}

\NewExpandableDocumentCommand{\pptsize}{m}{\fpeval{#1*128/254}pt}

\begin{document}

\pptsize{10cm}

\end{document}


This prints

143.3839667679335pt

If you want to rescale all coordinates in a tikzpicture, you can just use scale. Since you seem to be loading tikz you can use its commands to convert lengths, i.e. there is no need to load extra packages, but you really do not have to do that by hand.

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Convert coordinates $\to$ use scale}
\begin{tikzpicture}[scale=128/254]
\draw (0,0) -- (10,0);
\end{tikzpicture}

10cm get converted to
\pgfmathparse{10*128/254}\pgfmathprintnumber{\pgfmathresult}cm
\end{frame}
\end{document}


• Thanks, this works and might be the easier solution in my case. Unfortunately (but pretty obvious), this changes \pageheight and \pagewidht which I therefore "restore" using \def\w{\paperwidth*1.984375}. Interestingly, the scaling does not work for the included image in \node at (0,0) {\includegraphics[width=3.94cm]{logo.pdf}} where I have to use width=1.9855cm instead... – F1iX May 29 '19 at 16:41
• @F1iX AFAIK this does not change \paperheight and \pagewidth. If you add \begin{tikzpicture}[scale=128/254,nodes={transform shape}], the nodes will be transformed, i.e. scaled, as well. – user121799 May 29 '19 at 18:03
• thanks for the hint, nodes={transform shape} works for scaling the image! Indeed it does not "change" \paperheight, but scales it, so the line \draw (0,0) -- (\paperwidth, \paperheight) covers only part of the slide. – F1iX Jun 3 '19 at 7:13
• @F1iX Yes, of course. If you use \tikx[remember picture,overlay]{\draw (current page.south west) -- (current page.north east);} you'll get a diagonal regardless of the scaling you may want to add. – user121799 Jun 3 '19 at 11:04
• Thanks for your patience! Yet another issue: \draw[line widht=4pt] does not get scaled either :D – F1iX Jun 3 '19 at 16:28