TransWikia.com

How to center title including figure vertically in Beamer?

TeX - LaTeX Asked by Eenoku on December 25, 2020

I started using rather large Beamer-based template. Everything is good except title vertical align – for default font size it looks ok:

enter image description here

But when I change the fontsize to, e.g. 9pt like this:

documentclass[lualatex,hyperref={pdfencoding=auto},9pt]{beamer}

The gets shifted upwards

enter image description here

As far as I found out, the vertical alignment is set up with this code:

    setbeamertemplate{frametitle}
    {   
        nointerlineskip
        begin{beamercolorbox}[sep=0.3cm,ht=1.8em,wd=paperwidth]{frametitle}
            vbox{}vskip-2ex
            strutinsertframetitlestrut
            hfill
            raisebox{-0.25height}{includegraphics[height=1.35em]{proj@TightSignFileName}}
            vskip-0.8ex%
        end{beamercolorbox}
    }  

Is there any way, how to do the vertical alignment “dynamically”, so that the whole title would be positioned in the middle, no matter the font size?

I’ve tried valign from adjustbox package as mentioned in How to vertically center text with an image in the same row of a table , but it doesn’t seem to work really well in this case:

enter image description here

    setbeamertemplate{frametitle}
    {   
        nointerlineskip
        begin{beamercolorbox}[sep=0.3cm,ht=1.8em,wd=paperwidth]{frametitle}
            vbox{}vskip-2ex
            strutinsertframetitlestrut
            hfill
            includegraphics[valign=m,height=1.35em]{vsb@TightSignFileName}
            vskip-0.8ex%
        end{beamercolorbox}
    } 

Download link

Due to the large number of necessary files and images I uploaded complete MWE onto this link:

https://gofile.io/?c=2d0D8O

One Answer

You could bracket your code in:

vspace*{fill}
  % Your stuff here
vspace*{fill}

This adds vertical space (vspace) unconditionally (*), the space to be added is "as long as will fit" (fill). Both fill fight for space, each gets half. If you want uneven space top/bottom, use stretch{n}:

vspace*{stretch{2}}
  % Your stuff here
vspace*{stretch{3}}

This will give 2/5 of the space above. Can use the same idea horizontally, BTW.

Answered by vonbrand on December 25, 2020

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