Search code examples
latexbeamer

how to use \hspace in beamer frametitle


I would like to adjust my title some mm to the right, but when I try this:

\addtobeamertemplate{frametitle}{\hspace{5mm}}

my title just gets shifted downwards. I don't understand why: enter image description here

I've also tried to use this:

\setbeamertemplate{frametitle}{\hspace{4mm}\insertframetitle}

but then my whole title is per default shifted a huge amount to the right:

second approach


Solution

  • Your approach to append space at the begin of the frametitle template won't work because the frametitle is normally set in a beamercolorbox which spans the whole page. If you add space in front of it, it will no longer fit in the line and thus latex will add a line break before it. Best approach would be to redefine the template to make the box smaller.

    Assuming you use the default frametitle template (adjust the position by changing the line I marked with <- change value here):

    \documentclass{beamer}
    
    \makeatletter
    \setbeamertemplate{frametitle}{%
      \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
      \@tempdima=\textwidth%
      \advance\@tempdima by\beamer@leftmargin%
      \advance\@tempdima by\beamer@rightmargin%
      \advance\@tempdima by-4cm% <- change value here
      \hfill%
      \begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{frametitle}
        \usebeamerfont{frametitle}%
        \vbox{}\vskip-1ex%
        \if@tempswa\else\csname beamer@fteleft\endcsname\fi%
        \strut\insertframetitle\strut\par%
        {%
          \ifx\insertframesubtitle\@empty%
          \else%
          {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\strut\insertframesubtitle\strut\par}%
          \fi
        }%
        \vskip-1ex%
        \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
      \end{beamercolorbox}%
    }
    \makeatother
    
    \begin{document}
        
    \begin{frame}
      \frametitle{title}
        abc
    \end{frame} 
        
    \end{document}
    

    enter image description here