ビーマーセクションナビゲーションバーの現在のセクションと他のセクションに異なる背景色を使用する方法

ビーマーセクションナビゲーションバーの現在のセクションと他のセクションに異なる背景色を使用する方法

セクション ナビゲーション バーを作成するには、次のコードを使用します。

\setbeamercolor{section in head/foot}{bg=blue,fg=white}
\addtobeamertemplate{footline}{%
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,center]{section in head/foot}%
            \insertsectionnavigationhorizontal{\paperwidth}{}{}
        \end{beamercolorbox}}%

}{}

現在、ナビゲーション バーの背景は青で、現在のセクションのフォントは白、他のセクションのフォントは灰色になっています。しかし、それらの背景色を変えることはできますか? たとえば、現在のセクションの背景は濃い青、他のセクションの背景は薄い青などです。

Beamer の TEX ファイル全体は、この非常に最小限のファイルです。

\documentclass{beamer}

\usetheme{Madrid}
\title{Title}
\author{Author}
\date{\today}
\addtobeamertemplate{footline}{%
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
            \insertsectionnavigationhorizontal{\paperwidth}{}{}
        \end{beamercolorbox}}%

}{}

\begin{document}
\titlepage
\section{Sec 1}
\begin{frame}{Frame Title}{Frame Subtitle}
    Frame contents
    \begin{itemize}
        \item Item 1
        \item Item 2
              \begin{itemize}
                  \item Subitem 2.1
                  \item Subitem 2.2
              \end{itemize}
    \end{itemize}
    This is \textbf{bold text for normal text}.
\end{frame}

\section{Sec 2}
\begin{frame}{Frame Title}{Frame Subtitle}
    \begin{block}{Block}
        This is \textbf{bold text for blocks}.
    \end{block}
    \begin{alertblock}{Alert Block}
        This is \textbf{bold text for alert blocks}.
    \end{alertblock}
    \begin{example}
        This is \textbf{bold text for example blocks}.
    \end{example}
    \begin{block}{}
        \centering
        This is \textbf{bold text for unnamed blocks}.
    \end{block}
\end{frame}

\end{document}

そして結果は ここに画像の説明を入力してください

簡単にわかるように、ナビゲーション バーの sec 1 と sec 2 は、間に境界のない長い水平バー全体に属しているようです。これらは同じ背景色を共有していますが、現在の背景色が強調表示されています。これらに異なる背景色を作成したいのですが、それは可能ですか?

答え1

section in head/foot (shaded)何らかのカラーボックスを含めるようにテンプレートを再定義することもできます。

\documentclass{beamer}

\usetheme{Madrid}
\title{Title}
\author{Author}
\date{\today}

\addtobeamertemplate{footline}{%
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.1ex,center]{author in head/foot}%
            \insertsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll}
        \end{beamercolorbox}}%

}{}

\makeatletter
\newcommand{\secwidth}{\dimexpr\paperwidth/\beamer@sectionmax-2\fboxsep\relax}

\setbeamertemplate{section in head/foot}{\colorbox{orange}{\parbox{\secwidth}{\centering\insertsectionhead}}}
\setbeamertemplate{section in head/foot shaded}{\colorbox{cyan}{\parbox{\secwidth}{\centering\insertsectionhead}}}

\def\insertsectionnavigationhorizontal#1#2#3{%
  \hbox to #1{{%
     \def\slideentry##1##2##3##4##5##6{}%
     #2%\hskip.3cm%
     \usebeamerfont{section in head/foot}\usebeamercolor[fg]{section in head/foot}%
     \setbox\beamer@sectionbox=\hbox{}%
     \ht\beamer@sectionbox=1.875ex%
     \dp\beamer@sectionbox=0.75ex%
     \dohead%
     \box\beamer@sectionbox\hfil%\hskip.3cm%
     #3}}}
     
\def\sectionentry#1#2#3#4#5{% section number, section title, page
  \beamer@xpos=0\relax%
  \beamer@ypos=1\relax%
  \beamer@ypos@offset=0\relax%
  \ifnum#5=\c@part%
  \beamer@section@set@min@width%
  \box\beamer@sectionbox\hskip0ex plus 1fill%
  \setbox\beamer@sectionbox=
  \hbox{\def\insertsectionhead{#2}%
    \def\insertsectionheadnumber{#1}%
    \def\insertpartheadnumber{#5}%
    {%
      \usebeamerfont{section in head/foot}\usebeamercolor[fg]{section in head/foot}%
      \ifnum\c@section=#1%
        \hyperlink{Navigation#3}{{\usebeamertemplate{section in head/foot}}}%
      \else%
        \hyperlink{Navigation#3}{{\usebeamertemplate{section in head/foot shaded}}}%
      \fi}%
  }%
  \ht\beamer@sectionbox=1.875ex%
  \dp\beamer@sectionbox=0.75ex%
  \fi\ignorespaces}     
\makeatother

\begin{document}

\section{Sec 1}
\begin{frame}
\end{frame}

\section{Sec 2}
\begin{frame}
\end{frame}

\section{Sec 3}
\begin{frame}
\end{frame}

\end{document}

ここに画像の説明を入力してください

関連情報