5

I'm trying to create a custom beamer theme. However, I want to put some color besides the frame title, but I cannot adjust the height of the bar automatically. I tried to fix it by adding some skip amounts, and it works if all the titles have the same height (one line). But if that changes then the theme doesn't work.

So, how can I adjust the height of the color box on the left to the height of the title on the right.

\documentclass{beamer}
\definecolor{secinhead}{RGB}{249,196,95}
\definecolor{titlebg}{RGB}{51,51,51}

\setbeamercolor{secsubsec}{fg=secinhead,bg=secinhead}
\setbeamercolor{frametitle}{fg=secinhead,bg=titlebg}

\makeatletter
\setbeamertemplate{frametitle}{%
  \nointerlineskip%
  \usebeamerfont{headline}%
  \nointerlineskip%
  \hbox{\hspace{-0.09\paperwidth}%
  \begin{beamercolorbox}[wd=0.1\paperwidth,vmode]{secsubsec}%
    \newdimen\titleheight%
    \setbox0=\hbox{\usebeamerfont*{frametitle}\insertframetitle}
    \titleheight=\ht0 \advance\titleheight by \dp0%
    \vskip-.5pt%
    \vskip\titleheight%
    \ifx\insertframesubtitle\@empty%
      \strut\par%
    \else%
      \setbox0=\hbox{\usebeamerfont*{framesubtitle}\insertframesubtitle}%
      \titleheight=\ht0 \advance\titleheight by \dp0%
      \par{%
      \vskip\titleheight%
      \strut\par%
      \vskip-.65ex%
      }%
    \fi%
    \usebeamerfont{headline}%
    \vskip.5ex%
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=0.99\paperwidth,leftskip=.3cm,rightskip=.3cm plus1fil,vmode]{frametitle}%
    \vskip.5ex%
    \usebeamerfont*{frametitle}\insertframetitle%
    \ifx\insertframesubtitle\@empty%
      \strut\par%
    \else%
      \par{\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\insertframesubtitle}\strut\par}%
    \fi%%
    \usebeamerfont{headline}%
    \vskip.5ex%
  \end{beamercolorbox}%
  }
  \nointerlineskip
}
\makeatother

\begin{document}
\begin{frame}{test}
content...
\end{frame}

\begin{frame}{longer title test to demonstrate it is not working}
content...
\end{frame}

\begin{frame}{even longer longer title test to demonstrate it is not working}
content...
\end{frame}
\end{document}

enter image description here

See in the left, how all the yellow marks have different heights.

1 Answer 1

6

A solution using the tcolorbox package:

\documentclass{beamer}
\usepackage[many]{tcolorbox}

\definecolor{secinhead}{RGB}{249,196,95}
\definecolor{titlebg}{RGB}{51,51,51}

\setbeamercolor{secsubsec}{fg=secinhead,bg=secinhead}
\setbeamercolor{frametitle}{fg=secinhead,bg=titlebg}

\makeatletter
\setbeamertemplate{frametitle}{%
  \nointerlineskip%
  \usebeamerfont{headline}%
  \nointerlineskip%
  \hbox{\hspace{-0.09\paperwidth}%
  \begin{tcolorbox}[
    enhanced,
    boxrule=15pt,
    colframe=secinhead,
    arc=0pt,
    outer arc=0pt,
    colback=titlebg,
    colupper=secinhead,
    width=\paperwidth+2mm,
    toprule=0pt,
    bottomrule=0pt,
    rightrule=0pt,
    left=15pt,
  ]%
    {\usebeamercolor{frametitle}\usebeamerfont*{frametitle}\strut\insertframetitle\strut}
    \ifx\insertframesubtitle\@empty%
      \strut\par%
    \else%
     \par{\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\insertframesubtitle}\par}%
    \fi
  \end{tcolorbox}%
  }
  \nointerlineskip
}
\makeatother

\begin{document}
\begin{frame}{test}
content...
\end{frame}

\begin{frame}{longer title test to demonstrate it is working}
content...
\end{frame}

\begin{frame}{even longer longer title test to demonstrate it is working even for several lines}{And even with a subtitle}
content...
\end{frame}

\end{document}

enter image description here

You must log in to answer this question.

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