2

I am trying to understand why modifying the right margin should change the position of a box of width equal to the paperwidth.

\documentclass{beamer}
%\setbeamersize{text margin right=0cm}
% Modifying the right margin makes the beamercolorbox move to the right althought the box still
% is of width paperwidth.
% The LINEND is moving as expected.

\setbeamercolor{bgcolor}{fg=black,bg=red}
\setbeamertemplate{frametitle}{\begin{beamercolorbox}[wd=\paperwidth]{bgcolor}Box\end{beamercolorbox}}

\begin{document}

\begin{frame}{Title}
LINESTART \hfill LINEEND
\end{frame}
\end{document}
2
  • 2
    Please tell us how you modify the right-hand margin.
    – Mico
    Oct 25, 2020 at 12:35
  • By uncommenting the second line in above example. Oct 25, 2020 at 13:03

2 Answers 2

2

\setbeamersize{text margin right=0cm} works as expected, but \begin{beamercolorbox}[wd=\paperwidth] ... automatically makes its contents centered. This is clearer when you change the ... part of \setbeamertemplate{frametitle}{...} to, for example

  • \begin{beamercolorbox}[wd=\dimexpr\paperwidth-1cm\relax] ... or
  • \leavevmode\rule{\dimexpr\paperwidth-1cm\relax}{1pt}.

From the user guide for beamer v3.59, sec. 12.5, documentation of key wd of beamercolorbox,

If the width is larger than the normal text width, as specified by the value of \textwidth, the width of the resulting box is reset to the width \textwidth, but intelligent negative skips are inserted at the left and right end of the box.

In your example, \paperwidth = <text margin left> + \textwidth + <text margin right>, in which <text margin left> = 1cm and <text margin right> is set to 0pt. Therefore \paperwidth > \textwidth.

6
  • I played around with the example and the content of beamercolorbox always is rendered left-bound with respect to the colored background of beamercolorbox. It never is centered. Do you mean that the beamercolorbox itself is centered? If yes, with respect to what is the beamercolorbox centered? I fail to understand the concept of "centered" when it is not clear with regard to what. Can I turn off these "intelligent skips"? How? I want the box to do what I ask without "intelligence" of its own :-) Oct 25, 2020 at 13:22
  • 1
    @Nobody-Knows-I-am-a-Dog "Do you mean that the beamercolorbox itself is centered?" Yes. You can think that \hspace{-x}{beamercolorbox}\hspace{-x} is inserted, where x = .5(\paperwidth-\textwidth). I've added a workaround to my answer. Oct 25, 2020 at 14:30
  • @muzhimuzhi-z What do you mean with "yes"? An object cannot be centered as such. It only can be centered WITH REGARD TO something else. That is why I added "IF YES, with respect to what is the beamercolorobox centered?" The page? The newly set left and right margin? The original old margins? All of this leads to different positions! I am sorry but I really do not understand the concept of "centered" without a reference frame. It simply is not defined without a reference frame. Oct 25, 2020 at 14:46
  • 1
    @Nobody-Knows-I-am-a-Dog Perhaps I used a bad word, and let's directly learn from the doc. Suppose you have \begin{beamercolorbox}[wd=<dimen>] contents\end{beamercolorbox}. Case 1: <dimen> <= \textwidth, then the width of colorbox is <dimen>. Case 2: <dimen> > \textwidth, then the width of colorbox is always \textwidth. The final output is something like \hskip\x\hbox to <dimen>{<contents of beamercolorbox>}\hskip\x, where \x = .5(\textwidth-<dimen>). Oct 25, 2020 at 15:27
  • @Nobody-Knows-I-am-a-Dog In saying "centered", wrap the whole \hskip\x\hbox to <dimen>{...}\hskip\x in another \hbox, then the inner \hbox is centered with regard to the outer \hbox. Oct 25, 2020 at 15:30
-1

I have the following solution to my problem. For some reason I still do not completely understand, beamercolorbox behaves differently than my understanding of the manual. However, experimenting with a few cases led me to a correction of the position, which can be made after changing the beamer size. Placing these corrections into my own beamerFix package is my current solution for slide generation. May the idea be helpful for others coming here - and maybe a better fix will be found.

\documentclass[aspectratio=169]{beamer}

\makeatletter
\newlength\beamerFix@deltaMargin
\setlength\beamerFix@deltaMargin{\dimexpr 0.5\beamer@leftmargin - 0.5\beamer@rightmargin}

\setbeamersize{text margin left=0.4cm, text margin right=0.4cm}

\addtolength\beamerFix@deltaMargin{\dimexpr 0.5\beamer@rightmargin - 0.5\beamer@leftmargin}
\makeatother

\setbeamercolor{bgcolor}{fg=black,bg=red}

\makeatletter
\setbeamertemplate{frametitle}{%
  \nointerlineskip\ifdim\beamerFix@deltaMargin>0cm{}\else{\hspace*{\beamerFix@deltaMargin}}\fi%
  \begin{beamercolorbox}[wd=\paperwidth]{bgcolor}Box \hfill \insertframetitle \hfill End\end{beamercolorbox}%
}
\makeatother

\begin{document}
\begin{frame}{Title}

Start \hfill End

\end{frame}
\end{document}

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.