0

I want to remove the frame header line every time a new section starts.

I created my own command to do that but I have some problems with the \ifnum command.

I tried to use \ifnum\insertframenumber=\insertsectionstartpage as a condition to check if a new section starts an then remove the header (like frame 2). LaTeX always seems to execute the else branch, although the condition should evaluate to true... I also tried the \ifthenelse command, but it didn't work either.

Does anybody have an explanation for that?

Here my minimal working example:

\documentclass[t,8pt]{beamer}
\usepackage{ifthen}

\usetheme{Warsaw}

\newcommand{\HeaderFrame}[2]{
    \ifnum\insertframenumber=\insertsectionstartpage
        {
            \makeatletter
                \setbeamertemplate{headline}[default]
                \def\beamer@entrycode{\vspace*{-\headheight}}
            \makeatother
            \begin{frame}{#1}
                #2
            \end{frame}
        }
    \else
        \begin{frame}{#1}
            \insertframenumber~\insertsectionstartpage
        \end{frame}
    \fi
}

\begin{document}

\section{Test1}

\HeaderFrame{Test}{
    That is a test
}

\section{Test2}

{
    \makeatletter
        \setbeamertemplate{headline}[default]
        \def\beamer@entrycode{\vspace*{-\headheight}}
    \makeatother
    \begin{frame}{New Frame}
        Test
    \end{frame}
}

\section{Test3}

\end{document}
  • Sounds like you are comparing apples to oranges. If you want to compare to the framenumber you have to use the section start frame and not page. See tex.stackexchange.com/a/302320/36296 how to get the section start frame. – user36296 Feb 8 '17 at 13:42
  • Btw: In the long run, creating a wrapper command for a frame creates more problems then it solves. Just image you need to use some frame options like fragile or plain. – user36296 Feb 8 '17 at 13:55
1

based on Check if page with a given number is a section page

\documentclass{beamer}
\usetheme{Warsaw}

\usepackage{etoolbox}
\makeatletter
\newcount\beamer@sectionstartframe
\beamer@sectionstartframe=1
\apptocmd{\beamer@section}{\addtocontents{nav}{\protect\headcommand{%
            \protect\beamer@sectionframes{\the\beamer@sectionstartframe}{\the\c@framenumber}}}}{}{}
\apptocmd{\beamer@section}{\beamer@sectionstartframe=\c@framenumber\advance\beamer@sectionstartframe by1\relax}{}{}
\AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\beamer@sectionframes{\the\beamer@sectionstartframe}{\the\c@framenumber}}}}}{}{}
\def\beamer@startframeofsection{1}
\def\beamer@endframeofsection{1}
\def\beamer@sectionframes#1#2{%
    \ifnum\c@framenumber<#1%
    \else%
    \ifnum\c@framenumber>#2%
    \else%
    \gdef\beamer@startframeofsection{#1}%
    \gdef\beamer@endframeofsection{#2}%
    \fi%
    \fi%
}
\newcommand\insertsectionstartframe{\beamer@startframeofsection}
\newcommand\insertsectionendframe{\beamer@endframeofsection}

\setbeamertemplate{headline}{%
    \ifnum\insertsectionstartframe=\insertframenumber%
      \vskip-\headheight%
    \else%
          \leavevmode%
          \@tempdimb=2.4375ex%
          \ifnum\beamer@subsectionmax<\beamer@sectionmax%
            \multiply\@tempdimb by\beamer@sectionmax%
          \else%
            \multiply\@tempdimb by\beamer@subsectionmax%
          \fi%
          \ifdim\@tempdimb>0pt%
            \advance\@tempdimb by 1.825ex%
            \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{section in head/foot}%
              \vbox to\@tempdimb{\vfil\insertsectionnavigation{.5\paperwidth}\vfil}%
            \end{beamercolorbox}%
            \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{subsection in head/foot}%
              \vbox to\@tempdimb{\vfil\insertsubsectionnavigation{.5\paperwidth}\vfil}%
            \end{beamercolorbox}%
          \fi%      
      \vskip-0.2pt
      \pgfuseshading{beamer@topshade}
      \vskip-2pt
    \fi%
    }
\makeatother

\begin{document}

    \section{The First}

    \begin{frame}
        First slide
    \end{frame}

    \begin{frame}
        Second slide
    \end{frame}

    \begin{frame}
        Third slide
    \end{frame}

    \begin{frame}
        Fourth slide
    \end{frame}

    \section{The Second}

    \begin{frame}
        First slide
    \end{frame}

    \begin{frame}
        Second slide
    \end{frame}

    \begin{frame}
        Third slide
    \end{frame}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.