0

EDIT. Consider the following code. I wish to avoid empty beamercolorbox, if the required item to insert therein is empty. Consider the case of a section without a subsection, then the subsection beamercolorbox should not be rendered (now is rendered anyway, as an empty strip)

     \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}  

Is there a way to code something like:

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

I tried \ifstrempty by the etoolbox package, but I am not sure how to use it.

I need it for sectionhead, subsectionhead and so on too.

4
  • If there is no explicit short title, \insertshorttitle will normally fall back to the full title. Do you want to print the box in this case? Commented Nov 18, 2023 at 17:14
  • Your question would be much better if it would contain a short test document. Commented Nov 18, 2023 at 17:18
  • No, i don't. I want to print the box for whatever, only when whatever is not empty.
    – mario
    Commented Nov 18, 2023 at 19:13
  • Problem solved? Commented Mar 19 at 15:11

1 Answer 1

1

Assuming you also want to insert your colorbox when there is no explicit short title and just the full title, then you could do something like this:

\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}  
6
  • I don't want to write \foo in every frame, it should go by default.
    – mario
    Commented Nov 18, 2023 at 19:14
  • @mario It can be automated, but you have neither said where you want to print the title nor did you provide a test document in your question. Commented Nov 18, 2023 at 19:15
  • edited, better?
    – mario
    Commented Nov 18, 2023 at 19:23
  • @mario Not by much. It is still only a code fragment and not a compilable test document Commented Nov 18, 2023 at 19:29
  • I tried to write a mwe, I hope it works there too. I'll check better tomorrow. I will add a picture. Thanks for now.
    – mario
    Commented Nov 18, 2023 at 20:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .