我想在使用 Palo Alto 主题的 beamer 演示文稿中插入一个额外的(除左上角之外的)徽标,以便仅当有足够剩余空间时它才会出现在导航栏中。
实现这一结果的最佳方法是什么?
到目前为止,我已经能够将它放置在所需的位置,但不知道如何让它“消失”,而不是在没有足够空间时被丑陋地切割。
这是一个最小的工作示例(似乎我的发行版中没有 mwe 包,所以我只创建了一个红色方形图像)。
\documentclass{beamer}
\usetheme[hideothersubsections]{PaloAlto}
\usecolortheme{seahorse}
\setbeamercovered{transparent}
\makeatletter
\setbeamertemplate{sidebar \beamer@sidebarside}
{
\beamer@tempdim=\beamer@sidebarwidth%
\advance\beamer@tempdim by -6pt%
{\usebeamerfont{title in sidebar}%
\vskip1.5em%
\hskip3pt%
\usebeamercolor[fg]{title in sidebar}%
\insertshorttitle[width=\beamer@tempdim,center,respectlinebreaks]\par%
\vskip1.25em%
}%
{%
\hskip3pt%
\usebeamercolor[fg]{author in sidebar}%
\usebeamerfont{author in sidebar}%
\insertshortauthor[width=\beamer@tempdim,center,respectlinebreaks]\par%
\vskip1.25em%
}%
\insertverticalnavigation{\beamer@sidebarwidth}%
\vfill
\ifx\beamer@sidebarside\beamer@lefttext%
\else%
\usebeamercolor{normal text}%
\llap{\usebeamertemplate***{navigation symbols}\hskip0.1cm}%
\vskip2pt%
\fi%
\hskip8pt
\includegraphics[height=1cm,keepaspectratio]{example-logo}~%
\vskip2pt
}
\makeatother
\logo{\includegraphics[height=0.7cm,keepaspectratio]{example-logo}}
\begin{document}
\section{Section1}
\frame{Test Frame 1}
\section{Section 2}
\subsection{Subsection1 is a very long-titled subsection}
\subsection{Subsection2 is a very long-titled subsection}
\subsection{Subsection3 is a very long-titled subsection}
\subsection{Subsection4 is a very long-titled subsection}
\subsection{Subsection5 is a very long-titled subsection}
\subsection{Subsection6 is a very long-titled subsection}
\subsection{Subsection7 is a very long-titled subsection}
\subsection{Subsection8 is a very long-titled subsection}
\subsection{Subsection9 is a very long-titled subsection}
\frame{test Frame 2}
\end{document}
如下图所示,虽然在第一帧中左下角的徽标显示得很好,但在第二帧中,徽标的一部分超出了框架。我希望当这种情况发生时,徽标不会显示出来。
答案1
以下是使用蒂克兹测量图片的高度,并且只有在有足够空间时才插入它:
代码
\documentclass{beamer}
\usepackage{tikz}
\usepackage{xifthen}
\usetheme[hideothersubsections]{PaloAlto}
\usecolortheme{seahorse}
\setbeamercovered{transparent}
\newcommand{\insertpic}[2][scale=1]% [options], picname
{ \begin{tikzpicture}[remember picture,overlay]
\path (navenddummy);
\pgfgetlastxy{\xnav}{\ynav}
\vphantom{\hphantom{
\node[inner sep=0pt,above right] (pictopdummy) {\includegraphics[#1]{#2}};
}}
\path (pictopdummy.north);
\pgfgetlastxy{\xpic}{\ypic}
\pgfmathtruncatemacro{\picornot}{\ypic < \ynav ? 1 : 0}
\ifthenelse{\picornot=1}
{\node[inner sep=0pt,above right] {\includegraphics[#1]{#2}};}
{}
%\node[inner sep=1pt,circle,fill=red] at (navenddummy) {};
%\node[inner sep=1pt,circle,fill=blue] at (pictopdummy.north) {};
\end{tikzpicture}
}
\makeatletter
\setbeamertemplate{sidebar \beamer@sidebarside}
{
\beamer@tempdim=\beamer@sidebarwidth%
\advance\beamer@tempdim by -6pt%
{\usebeamerfont{title in sidebar}%
\vskip1.5em%
\hskip3pt%
\usebeamercolor[fg]{title in sidebar}%
\insertshorttitle[width=\beamer@tempdim,center,respectlinebreaks]\par%
\vskip1.25em%
}%
{%
\hskip3pt%
\usebeamercolor[fg]{author in sidebar}%
\usebeamerfont{author in sidebar}%
\insertshortauthor[width=\beamer@tempdim,center,respectlinebreaks]\par%
\vskip1.25em%
}%
\insertverticalnavigation{\beamer@sidebarwidth}%
%=================
\begin{tikzpicture}[overlay,remember picture]
\coordinate (navenddummy);
\end{tikzpicture}
%=================
\vfill
\ifx\beamer@sidebarside\beamer@lefttext%
\else%
\usebeamercolor{normal text}%
\llap{\usebeamertemplate***{navigation symbols}\hskip0.1cm}%
\vskip2pt%
\fi%
\hskip8pt
%=================
\insertpic[height=0.7cm,keepaspectratio]{book.png}~
%=================
\vskip2pt
}
\makeatother
\logo{\includegraphics[height=0.7cm,keepaspectratio]{book.png}}
\begin{document}
\section{Section1}
\frame{Test Frame 1}
\frame{test Frame 2}
\section{Section 2}
\subsection{Subsection1 is a very long-titled subsection}
\subsection{Subsection2 is a very long-titled subsection}
\subsection{Subsection3 is a very long-titled subsection}
\subsection{Subsection4 is a very long-titled subsection}
\subsection{Subsection5 is a very long-titled subsection}
\subsection{Subsection6 is a very long-titled subsection}
\subsection{Subsection7 is a very long-titled subsection}
\subsection{Subsection8 is a very long-titled subsection}
\subsection{Subsection9 is a very long-titled subsection}
\frame{test Frame 3}
\frame{test Frame 4}
\end{document}