各种场景下frametitle的垂直间距

各种场景下frametitle的垂直间距

有时,我的 frametitle 需要换行,有时还有 framesubtitle。我试图控制这些情况下的垂直间距。使用 framesubtitle 很容易(只需检查它是否为空并根据需要调整空间)。但是,我如何确定 frametitle 文本需要多少行(或垂直空间)?

\documentclass[xcolor={dvipsnames},aspectratio=1610]{beamer}
\usepackage{tabularx} % to define table width
\usepackage{calc}     % to add and subtract lengths

\newdimen\leftlogosize
\newdimen\rightlogosize
\def\leftlogo{Physics_Logo.png}
\def\rightlogo{SanJac_Logo.png}
\newdimen\logolength
\leftlogosize=1.2cm
\rightlogosize=1.2cm
\logolength=1.5cm

\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{Z}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}

\makeatletter
\setbeamertemplate{frametitle}{%
  \nointerlineskip%
  \vskip 0.2cm%
  \begin{beamercolorbox}[wd=\paperwidth,vmode]{frametitle}%
    \begin{tabularx}{\paperwidth}{L{\logolength} @{\hskip 0pt}Z @{\hskip 0pt} R{\logolength}}
      \includegraphics[height=\leftlogosize]{\leftlogo} &%
      \vbox{}\vskip-1ex%
      \ifx\insertframesubtitle\@empty%
        \vskip-1cm%
        \usebeamerfont*{frametitle}\centering\insertframetitle\strut\par%
      \else%
        \vskip-1cm%
        \usebeamerfont*{frametitle}\centering\insertframetitle\strut\par%
        \par{\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\centering\insertframesubtitle}\strut\par}%
      \fi%
      \vskip -2ex%
      \centering\noindent\rule{\paperwidth-\logolength-\logolength-24pt}{.5pt} &% the 24 pt is for the default tabularx spacing for the logos
      \hfill%
      \includegraphics[height=\rightlogosize]{\rightlogo} \\% 
    \end{tabularx}%
  \end{beamercolorbox}%
}
\makeatother

\begin{document}

\begin{frame}
  \frametitle{Title}
\end{frame}

\begin{frame}
  \frametitle{Title \\ with a line break}
\end{frame}

\begin{frame}
  \frametitle{Title}
  \framesubtitle{\Large with a sub title}
\end{frame}

\begin{frame}
  \frametitle{Title \\ with a line break}
  \framesubtitle{\Large with a sub title}
\end{frame}

\end{document}

相关内容