TransWikia.com

Weird behavior when using expl3 and beamer

TeX - LaTeX Asked by Alan Xiang on August 17, 2021

I am trying to create a beamer template where everything is top-aligned by default. For those slides without a title, I would like to add a top margin automatically. The CASE 2 in the MWE below is what I come up with. Unfortunately, it fails to increase top margin. In comparison, I included CASE 1, which works properly in terms of adding margin only. I am not sure why putting the minipage inside some if block will change the output.

Output of CASE 1:

enter image description here

Output of CASE 2:

enter image description here

documentclass[t]{beamer}
usepackage{expl3}

ExplSyntaxOn
% CASE 1:
% works normally
setbeamertemplate{headline}{
  begin{minipage}[t][1cm][t]{0.8paperwidth}
  abcpar
  defpar
  ghipar
  end{minipage}  
}

% CASE 2:
% not working
setbeamertemplate{headline}{
  % get frame number
  tl_set:Nx l_tmpa_tl {insertframenumber}
  % do not add margin to the title page
  tl_if_eq:NnF l_tmpa_tl {1} {
    cs_if_exist:NT insertframetitle {
      hcoffin_set:Nn l_tmpa_coffin {insertframetitle}
      dim_compare:nNnT {coffin_wd:N l_tmpa_coffin} < {0.1pt} {
        % add spacing when there is no title
        begin{minipage}[t][1cm][t]{0.8paperwidth}
        abcpar
        defpar
        ghipar
        end{minipage}  
      }
    }
  }
}


ExplSyntaxOff
begin{document}

maketitle

begin{frame}{title}
conten...
end{frame}

begin{frame}
content...
end{frame}

end{document}


One Answer

This wasn't created by me, I just adapted it to fit this use case. If you think this deserves an upvote, you should really upvote the original answer by @samcarter.

The following reuses ideas from @samcarter (but patches the environment, like proposed there).

We patch beamer's internals to add a noframetitle template that gets evoked when there is no frametitle in a frame. This noframetitle template will add some white space. You can modify that template to your liking, I just put a rule there with width 0pt (so it is invisible), the height I got from trial-and-error to match the spacing of a frame with a title.

documentclass[t]{beamer}

makeatletter
patchcmdendbeamer@frameslide
  {setboxbeamer@frametitlebox=boxvoidb@x}
  {%
    % no change for title page
    ifnumc@framenumber=1
      setboxbeamer@frametitlebox=boxvoidb@x
    else
      setboxbeamer@frametitlebox=vbox{%
        vbox{}%
        {parskip0ptusebeamertemplate***{noframetitle}vskip0.25em}%
      }%
    fi
  }
  {}
  {GenericError{}{Error: Failed to patch beamer's frameslide}{}{}}
makeatother
setbeamertemplate{noframetitle}{rule{0pt}{6.7mm}}

begin{document}

maketitle

begin{frame}{title}
  contentldots
end{frame}

begin{frame}
  contentldots
end{frame}

end{document}

enter image description here

enter image description here

enter image description here

Correct answer by Skillmon on August 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP