Beamer:在标题内的 beamercolorbox 中垂直对齐子部分

Beamer:在标题内的 beamercolorbox 中垂直对齐子部分

我想自定义我的 beamer 演示文稿。不幸的是,我的标题有问题。我更改了字体(这里我使用了标准字体,所以你可以试试),这导致部分标题内容被框架标题遮挡(使用新字体排版的内容空间不够)。所以,我决定让标题对提供的内容更具响应性。我让它的高度取决于部分的数量和用于排版部分标题的字体(我知道代码不是很好,但我不太了解 TeX/LaTeX)。

如果我的节和子节数量相等,那么一切都会正常。如果子节比节少,我希望子节居中或与框顶部对齐。不幸的是,它们与框底部对齐,这看起来很奇怪(见屏幕截图)。您有什么想法可以解决此问题吗? 最佳情况

问题情况

下面我提供了 MWE,如果需要,请随意完全重写它。

预先感谢您的任何帮助。

平均能量损失

\documentclass[final]{beamer}

\usepackage{graphicx,xcolor}
\usepackage{xltxtra}
\usepackage{polyglossia}
\setdefaultlanguage{english}

\usepackage{etoolbox}
\usepackage{calc}
\usepackage{ifthen}

\usepackage{beamerthemeshadow}

\useinnertheme{rounded}

% =================================================== %
% CUSTOMIZATIONS
% =================================================== %
\definecolor{MyShade1}{RGB}{240, 240, 240}
\definecolor{MyShade2}{RGB}{225, 225, 225}
\definecolor{Fg}{RGB}{0, 0, 0}
\definecolor{Bg}{RGB}{255, 255, 255}
\setbeamercolor*{palette primary}{bg=MyShade1,fg=Fg}
\setbeamercolor*{palette quaternary}{bg=MyShade2,fg=Fg}
\setbeamercolor*{normal text}{fg=Fg,bg=Bg}

\usepackage{fontspec}
\setmainfont{Roboto}
\newfontfamily\npmedium{Roboto Medium}
\setbeamerfont{section in head/foot}{family=\npmedium, size*={6pt}{7pt}}
\setbeamerfont{subsection in head/foot}{family=\npmedium, size*={6pt}{7pt}}
\setbeamerfont{headline highlight}{family=\npmedium, size*={6pt}{7pt}}

% MY HEADER => PROBLEMATIC PART - START

\makeatletter

\newlength{\@myheight}%  height of 1 section title
\setlength{\@myheight}{1em}%
\newlength{\@pusher}%  push down frame title (for some reason it occludes the header)
\setlength{\@pusher}{0.5mm}%
\newcount\@secnum%  max number of sections in the presentation
\@secnum=4%
\multiply\@myheight by\@secnum%
\advance\@myheight by -0.5em%

\setbeamertemplate{headline}{
    \leavevmode%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@myheight]{section in head/foot}%
        \insertsectionnavigation{0.5\paperwidth}
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@myheight]{subsection in head/foot}%
        \insertsubsectionnavigation{0.5\paperwidth}
    \end{beamercolorbox}%
}
\addtobeamertemplate{frametitle}{\vskip + \@pusher}{}

\makeatother

% MY HEADER => PROBLEMATIC PART - END

\title{MWE}
\author{Tester}
\institute{n/a}
\date{\today}

\begin{document}

\section{Section 1}
\subsection{SubSection 1.1}
\begin{frame}{SubSection 1.1}
    SubSection 1.1
\end{frame}

\subsection{SubSection 1.2}
\begin{frame}{SubSection 1.2}
    SubSection 1.2
\end{frame}

\subsection{SubSection 1.3}
\begin{frame}{SubSection 1.3}
    SubSection 1.3
\end{frame}

\subsection{SubSection 1.4}
\begin{frame}{SubSection 1.4}
    SubSection 1.4
\end{frame}

\section{Section 2}
\subsection{SubSection 2.1}
\begin{frame}{SubSection 2.1}
    SubSection 2.1
\end{frame}

\subsection{SubSection 2.2}
\begin{frame}{SubSection 2.2}
    SubSection 2.2
\end{frame}

\section{Section 3}
\subsection{SubSection 3.1}
\begin{frame}{SubSection 3.1}
    SubSection 3.1
\end{frame}

\section{Section 4}
\subsection{SubSection 4.1}
\begin{frame}{SubSection 4.1}
    SubSection 4.1
\end{frame}

\end{document}

编辑:基本主题中的标题无响应(=原始问题)

\documentclass[final]{beamer}

\usepackage{graphicx,xcolor}
\usepackage{xltxtra}
\usepackage{polyglossia}
\setdefaultlanguage{english}

\usepackage{etoolbox}
\usepackage{calc}
\usepackage{ifthen}

\usepackage{beamerthemeshadow}

\useinnertheme{rounded}

% =================================================== %
% CUSTOMIZATIONS
% =================================================== %
\definecolor{MyShade1}{RGB}{240, 240, 240}
\definecolor{MyShade2}{RGB}{225, 225, 225}
\definecolor{Fg}{RGB}{0, 0, 0}
\definecolor{Bg}{RGB}{255, 255, 255}
\setbeamercolor*{palette primary}{bg=MyShade1,fg=Fg}
\setbeamercolor*{palette quaternary}{bg=MyShade2,fg=Fg}
\setbeamercolor*{normal text}{fg=Fg,bg=Bg}

% Font changes producing the occlusion effect
\usepackage{fontspec}
\setmainfont{Roboto}
\newfontfamily\npregular{Roboto}
\newfontfamily\npmedium{Roboto Medium}
\newfontfamily\npblack{Roboto Black}
\setbeamerfont{section in head/foot}{family=\npmedium, size*={8pt}{9pt}}
\setbeamerfont{subsection in head/foot}{family=\npmedium, size*={8pt}{9pt}}
\setbeamerfont{headline highlight}{family=\npmedium, size*={8pt}{9pt}}
\setbeamerfont{normal text}{family=\npregular, size*={11pt}{13pt}}
\setbeamerfont{frametext}{family=\npregular, size*={11pt}{13pt}}

% % Baseline changes producing the occlusion effect
% \setbeamerfont{section in head/foot}{size*={6pt}{9pt}}
% \setbeamerfont{subsection in head/foot}{size*={6pt}{9pt}}
% \setbeamerfont{headline highlight}{size*={6pt}{9pt}}
% % Default font size changes producing the occlusion effect
% \setbeamerfont{section in head/foot}{size*={8pt}{8pt}}
% \setbeamerfont{subsection in head/foot}{size*={8pt}{8pt}}
% \setbeamerfont{headline highlight}{size*={8pt}{8pt}}

\title[MWE and Me]{MWE}
\author{Tester}
\institute{n/a}
\date{\today}

\setbeamertemplate{navigation symbols}{}

\begin{document}

\begin{frame}
    \maketitle
\end{frame}

\section{Section 1}
\subsection{SubSection 1.1}
\begin{frame}{SubSection 1.1}
    SubSection 1.1
\end{frame}

\subsection{SubSection 1.2}
\begin{frame}{SubSection 1.2}
    SubSection 1.2
\end{frame}

\subsection{SubSection 1.3}
\begin{frame}{SubSection 1.3}
    SubSection 1.3
\end{frame}

\subsection{SubSection 1.4}
\begin{frame}{SubSection 1.4}
    SubSection 1.4
\end{frame}

\section{Section 2}
\subsection{SubSection 2.1}
\begin{frame}{SubSection 2.1}
    SubSection 2.1
\end{frame}

\subsection{SubSection 2.2}
\begin{frame}{SubSection 2.2}
    SubSection 2.2
\end{frame}

\section{Section 3}
\subsection{SubSection 3.1}
\begin{frame}{SubSection 3.1}
    SubSection 3.1
\end{frame}

\section{Section 4}
\subsection{SubSection 4.1}
\begin{frame}{SubSection 4.1}
    SubSection 4.1
\end{frame}

\end{document}

任何字体变化(使用更高/更粗的字体、更大的尺寸或默认字体的基线 => 尝试不同的注释替代方案)都会产生遮挡效果,因为标题没有响应。下面是一些例子。

不同的字体: 在此处输入图片描述 在此处输入图片描述

更大的基线: 在此处输入图片描述 在此处输入图片描述

较大字体(标准基线): 在此处输入图片描述 在此处输入图片描述

答案1

自提交以来https://github.com/josephwright/beamer/commit/5e32665a0382d91e3ebddc5080c717f962a8e0fasection in head/foot(应包含在 beamer 3.71 或更新版本中),beamer在创建标题时会自动考虑字体的字体大小。

因此,无需任何人工干预,您的示例

% !TeX TS-program = lualatex

\documentclass[final]{beamer}

\usepackage{graphicx,xcolor}
\usepackage{xltxtra}
\usepackage{polyglossia}
\setdefaultlanguage{english}

\usepackage{etoolbox}
\usepackage{calc}
\usepackage{ifthen}

\usepackage{beamerthemeshadow}

\useinnertheme{rounded}

% =================================================== %
% CUSTOMIZATIONS
% =================================================== %
\definecolor{MyShade1}{RGB}{240, 240, 240}
\definecolor{MyShade2}{RGB}{225, 225, 225}
\definecolor{Fg}{RGB}{0, 0, 0}
\definecolor{Bg}{RGB}{255, 255, 255}
\setbeamercolor*{palette primary}{bg=MyShade1,fg=Fg}
\setbeamercolor*{palette quaternary}{bg=MyShade2,fg=Fg}
\setbeamercolor*{normal text}{fg=Fg,bg=Bg}

% Font changes producing the occlusion effect
\usepackage{fontspec}
\setmainfont{Roboto}
\newfontfamily\npregular{Roboto}
\newfontfamily\npmedium{Roboto Medium}
\newfontfamily\npblack{Roboto Black}
\setbeamerfont{section in head/foot}{family=\npmedium, size*={8pt}{9pt}}
\setbeamerfont{subsection in head/foot}{family=\npmedium, size*={8pt}{9pt}}
\setbeamerfont{headline highlight}{family=\npmedium, size*={8pt}{9pt}}
\setbeamerfont{normal text}{family=\npregular, size*={11pt}{13pt}}
\setbeamerfont{frametext}{family=\npregular, size*={11pt}{13pt}}

 % Baseline changes producing the occlusion effect
% \setbeamerfont{section in head/foot}{size*={6pt}{9pt}}
% \setbeamerfont{subsection in head/foot}{size*={6pt}{9pt}}
% \setbeamerfont{headline highlight}{size*={6pt}{9pt}}
% % Default font size changes producing the occlusion effect
 \setbeamerfont{section in head/foot}{size*={8pt}{8pt}}
 \setbeamerfont{subsection in head/foot}{size*={8pt}{8pt}}
 \setbeamerfont{headline highlight}{size*={8pt}{8pt}}

\title[MWE and Me]{MWE}
\author{Tester}
\institute{n/a}
\date{\today}

\setbeamertemplate{navigation symbols}{}

\begin{document}

\begin{frame}
    \maketitle
\end{frame}

\section{Section 1}
\subsection{SubSection 1.1}
\begin{frame}{SubSection 1.1}
    SubSection 1.1
\end{frame}

\subsection{SubSection 1.2}
\begin{frame}{SubSection 1.2}
    SubSection 1.2
\end{frame}

\subsection{SubSection 1.3}
\begin{frame}{SubSection 1.3}
    SubSection 1.3
\end{frame}

\subsection{SubSection 1.4}
\begin{frame}{SubSection 1.4}
    SubSection 1.4
\end{frame}

\section{Section 2}
\subsection{SubSection 2.1}
\begin{frame}{SubSection 2.1}
    SubSection 2.1
\end{frame}

\subsection{SubSection 2.2}
\begin{frame}{SubSection 2.2}
    SubSection 2.2
\end{frame}

\section{Section 3}
\subsection{SubSection 3.1}
\begin{frame}{SubSection 3.1}
    SubSection 3.1
\end{frame}

\section{Section 4}
\subsection{SubSection 4.1}
\begin{frame}{SubSection 4.1}
    SubSection 4.1
\end{frame}

\end{document}

将产生以下结果:

在此处输入图片描述

相关内容