5

I'd like to have a rule that has for example the width of \paperwidth-\leftmargin-\rightmargin. I tried to use \dimexpr, but apparently I do something wrong, because it does not work.

\documentclass[t]{beamer}

%\usepackage{geometry}
\geometry{paperwidth=250mm,paperheight=190.5mm,left=0mm,right=0mm,top=0mm,bottom=0mm} 
\setbeamersize{text margin left=10mm,text margin right=60mm}

  \begin{document}
    \begin{frame}
        \rule{\dimexpr\paperwidth-\leftmargin-\rightmargin\relax}{50mm}% 180mm = 250mm - 10mm - 60mm
    \end{frame}
  \end{document}

enter image description here

1 Answers1

7

The lengths you are looking for are stored in macros \Gm@lmargin (distance between left margin of paper and left border of text area) and \Gm@rmargin (distance between right border of text area and right margin of paper), so \paperwidth=\Gm@lmargin+\textwidth+\Gm@rmargin. Since the \Gm@... are macros, you can define some lengths first to easily use them in \dimexpr (see remark at the end):

\documentclass[t]{beamer}
\usepackage{lipsum}
\usepackage{geometry}
\geometry{paperwidth=250mm,paperheight=190.5mm,left=0mm,right=0mm,top=0mm,bottom=0mm} 
\setbeamersize{text margin left=10mm,text margin right=60mm}

\makeatletter
\newlength\beamerleftmargin
\newlength\beamerrightmargin
\setlength\beamerleftmargin{\Gm@lmargin}
\setlength\beamerrightmargin{\Gm@rmargin}
\makeatother   

\begin{document}

\begin{frame}
\textcolor{blue}{\rule{\textwidth}{3pt}}

\textcolor{red}{\rule{\dimexpr\paperwidth-\beamerleftmargin-\beamerrightmargin\relax}{3pt}}% 180mm = 250mm - 10mm - 60mm
\end{frame}

\end{document}

enter image description here

If a sidebar is used by the theme, some other horizontal lengths will have to be taken into account: \beamer@leftsidebar, \beamer@rightsidebar store the (horizontal) sizes of the side bars, and \beamer@leftmargin, \beamer@rightmarginstore the distance between sidebar and text.

As jfbu has noticed in his comment it is not mandatory to define two new length registers and one could do

\def\beamerleftmargin{\dimexpr\Gm@lmargin\relax}
\def\beamerrightmargin{\dimexpr\Gm@rmargin\relax}
Gonzalo Medina
  • 505,128
  • Thanks a lot for your answer! Exactly what I was hoping for! – samcarter_is_at_topanswers.xyz May 20 '14 at 14:12
  • @jfbu Thanks for the comment. I know that it was not strictly necessary to define the new length registers, but doing so, simplifies the writing of calculations (as you've observed), so I decided to define the lengths. Perhaps I should change the redaction so it's clear that it's not required to define them. I'll add some remark about this. – Gonzalo Medina May 20 '14 at 16:05
  • your way is to be preferred I agree. However if the macros were changing, one could not use once and for all \setlength, on the other hand one could do with a \def\mymacro{\th@priv@tem@cr@w@thm@ny@@@s}. –  May 20 '14 at 16:08
  • @jfbu I've added a remark at the end of my answer (using almost verbatim) your comment. Thanks. – Gonzalo Medina May 20 '14 at 16:12
  • @GonzaloMedina I will suppress my comment now that it has become team work ;-)! an alternative having the advantages in terms of syntax of your method with lengths is \def\beamerleftmargin{\dimexpr\Gm@lmargin\relax}. It allows situations where the initial thing could change, and we want the current value (without having to bother with \makeatletter etc). I should have formulated this way from the start! –  May 20 '14 at 16:25
  • @jfbu No, please leave it; it's really useful (and I've linked it in my answer). – Gonzalo Medina May 20 '14 at 16:26
  • @jfbu Ah, too late! – Gonzalo Medina May 20 '14 at 16:26
  • argh... I already suppressed it! –  May 20 '14 at 16:27
  • @GonzaloMedina apologies for suppressing my earlier comment you linked too. The only extra thing compared to your text was to say that inside \dimexpr..\relax one is allowed to use any expandable macro. For example with \def\A{12}\def\B{3pt} then \dimexpr\A\B\relax can correctly be used to specify 123pt where TeX expects a dimension (or inside another \dimexpr .. \relax) –  May 20 '14 at 16:33
  • @jfbu No worries! I edited my answer and used instead other of your comments (please, don't delete it, as it's now linked to in my answer ;) ) since it gives a better option. – Gonzalo Medina May 20 '14 at 16:35