beamer 和 \ifstrempty

beamer 和 \ifstrempty

编辑。考虑以下代码。beamercolorbox如果要插入的项为空,我希望避免出现空的情况。考虑没有子节的部分的情况,则beamercolorbox不应呈现子节(现在无论如何都会呈现为空条)

     \documentclass{beamer}
     \usepackage[T1]{fontenc}
     \mode<presentation>
      \setbeamertemplate{navigation symbols}{}
      \usetheme{Antibes} 
      \usecolortheme{seahorse}
      \useoutertheme{tree}
      \setbeamertemplate{footline}[frame number]
      \usefonttheme{serif}

      \makeatletter
      \setbeamertemplate{headline}
      {%
      \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
      \end{beamercolorbox}
      \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
    leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
       \usebeamerfont{title in head/foot}\insertshorttitle
       \end{beamercolorbox}
       \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
    leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
       \usebeamerfont{section in head/foot}%
       \ifbeamer@tree@showhooks
       \setbox\beamer@tempbox=\hbox{\insertsectionhead}%
       \ifdim\wd\beamer@tempbox>1pt%
       \hskip2pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
       \hskip1pt%
       \fi%
       \else%  
       \hskip6pt%
       \fi%
       \ifdim\wd\beamer@tempbox>1pt% DA CAPIRE
       {\thesection  \;- \insertsectionhead} 
       \else 
       {}
       \fi%
       \end{beamercolorbox}
       \begin{beamercolorbox}[wd=\paperwidth,ht=4.55ex,dp=1.125ex,%  
% ht=4.75ex aumentato per sub titoli lunghi
leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
     \usebeamerfont{subsection in head/foot}%
     \ifbeamer@tree@showhooks
     \setbox\beamer@tempbox=\hbox{\insertsubsectionhead}%
     \ifdim\wd\beamer@tempbox>1pt%
     \hskip9.4pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt
     }%
     \hskip1pt%
     \fi%
     \else%  
     \hskip12pt%
     \fi%
     \ifdim\wd\beamer@tempbox>1pt% DA CAPIRE
     {\thesection.\thesubsection \;- \insertsubsectionhead} 
     \else 
     {}
     \fi%
     \end{beamercolorbox}

     \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
     \end{beamercolorbox}
     }
     \makeatother

     \setbeamerfont{frametitle}{size=\fontsize{12}{14}}
     \setbeamerfont{framesubtitle}{size=\fontsize{5}{4}}
     \setbeamercolor{mycolor}{fg=blue,bg=yellow}
     \setbeamercolor{frametitle}{fg=red}
     \setbeamercolor{framesubtitle}{fg=black}



     \title{test}
     \author{m}
     \date{\footnotesize{\today}}


     \setbeamertemplate{section in toc}[sections numbered]
     \setbeamertemplate{subsection in toc}[subsections numbered]
     \defbeamertemplate{subsubsection in toc}{subsubsections numbered}
     {\leavevmode\leftskip=3em%
     \rlap{\hskip-3em\inserttocsectionnumber.\inserttocsubsectionnumber.\inserttocsubsubsectionnumber}%
     \inserttocsubsubsection\par}
      \setbeamertemplate{subsubsection in toc}[subsubsections numbered]

      \begin{document}\frame{\titlepage}    
       \begin{frame}{Hello}
         Hello!
      \end{frame}           
        
       \begin{frame}[t,noframenumbering]
        \frametitle{Index} 
        \tableofcontents[pausesections, pausesubsections,sections={1-2}]
    \end{frame}     
        
       \section{\textbf{{First}}}
       \begin{frame}{A}
        AAAA
        \end{frame}
        \section{Second}
        \begin{frame}{B}
        BBBB
        \end{frame}
        \subsection{Sub Second}
        \begin{frame}{C}
        CCCC
        \end{frame}     
        \end{document}  

有没有办法编写类似的代码:

if shorttitle is empty do not insert the beamercolorbox, else insert it

我尝试过 \ifstrempty这个etoolbox包,但我不知道如何使用它。

我也需要它sectionheadsubsectionhead等等。

答案1

假设您还想在没有明确的简称而只有完整标题的情况下插入颜色框,那么您可以执行以下操作:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\mode<presentation>
\setbeamertemplate{navigation symbols}{}
\usetheme{Antibes} 
\usecolortheme{seahorse}
\useoutertheme{tree}
\setbeamertemplate{footline}[frame number]
\usefonttheme{serif}

\makeatletter
\setbeamertemplate{headline}
{%
\begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
\end{beamercolorbox}
\ifx\beamer@shorttitle\@empty
\else
\begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
\usebeamerfont{title in head/foot}\insertshorttitle
\end{beamercolorbox}
\fi
\ifx\insertsectionhead\@empty
\else
\begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
\usebeamerfont{section in head/foot}%
\ifbeamer@tree@showhooks
\setbox\beamer@tempbox=\hbox{\insertsectionhead}%
\ifdim\wd\beamer@tempbox>1pt%
\hskip2pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
\hskip1pt%
\fi%
\else%  
\hskip6pt%
\fi%
\ifdim\wd\beamer@tempbox>1pt% DA CAPIRE
{\thesection  \;- \insertsectionhead} 
\else 
{}
\fi%
\end{beamercolorbox}
\fi
\ifx\insertsubsectionhead\@empty
\else
\begin{beamercolorbox}[wd=\paperwidth,ht=4.55ex,dp=1.125ex,%  
% ht=4.75ex aumentato per sub titoli lunghi
leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
\usebeamerfont{subsection in head/foot}%
\ifbeamer@tree@showhooks
\setbox\beamer@tempbox=\hbox{\insertsubsectionhead}%
\ifdim\wd\beamer@tempbox>1pt%
\hskip9.4pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt
}%
\hskip1pt%
\fi%
\else%  
\hskip12pt%
\fi%
\ifdim\wd\beamer@tempbox>1pt% DA CAPIRE
{\thesection.\thesubsection \;- \insertsubsectionhead} 
\else 
{}
\fi%
\end{beamercolorbox}
\fi
\begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
\end{beamercolorbox}
}
\makeatother

\setbeamerfont{frametitle}{size=\fontsize{12}{14}}
\setbeamerfont{framesubtitle}{size=\fontsize{5}{4}}
\setbeamercolor{mycolor}{fg=blue,bg=yellow}
\setbeamercolor{frametitle}{fg=red}
\setbeamercolor{framesubtitle}{fg=black}



\title{test}
\author{m}
\date{\footnotesize{\today}}


\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{subsection in toc}[subsections numbered]
\defbeamertemplate{subsubsection in toc}{subsubsections numbered}
{\leavevmode\leftskip=3em%
\rlap{\hskip-3em\inserttocsectionnumber.\inserttocsubsectionnumber.\inserttocsubsubsectionnumber}%
\inserttocsubsubsection\par}
\setbeamertemplate{subsubsection in toc}[subsubsections numbered]

\begin{document}\frame{\titlepage}    
\begin{frame}{Hello}
Hello!
\end{frame}           

\begin{frame}[t,noframenumbering]
\frametitle{Index} 
\tableofcontents[pausesections, pausesubsections,sections={1-2}]
\end{frame}     

\section{First}
\begin{frame}{A}
AAAA
\end{frame}
\section{Second}
\begin{frame}{B}
BBBB
\end{frame}
\subsection{Sub Second}
\begin{frame}{C}
CCCC
\end{frame}     
\end{document}  

相关内容