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

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}
  • Thanks a lot for your answer! Exactly what I was hoping for! – user36296 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}. – user4686 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! – user4686 May 20 '14 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.