1

Consider the following MWE:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{arrows,intersections,calc,decorations.pathreplacing,
decorations.markings}
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=south west, yshift=-2pt, xshift=1pt] at (current page.south west)
{};
\draw[blue] ([yshift=-1cm, xshift=0.25cm]current page.north west)
  -- ([yshift=-1cm, xshift=\paperwidth - 0.25cm]current page.north west);
\end{tikzpicture}}

\begin{document}

\begin{frame}
  \frametitle{A shor title}
  Foo
\end{frame}

\begin{frame}
  \frametitle{A terribly long beamer slide title about some obscure meaningless
  topic}
  Bar
\end{frame}

\end{document}

With this I get the following output: enter image description here

So my question is: is it possible to use tikz (or any other package) to generate a rule that adapts to a multiline frame title? Thanks!

Edit: In my particular I need a solution that works also with uppercased frame title. Which I'm currently obtaining by adding the following line:

\setbeamertemplate{frametitle}{\expandafter\MakeUppercase\expandafter\insertframetitle}
  • You want the new rule be at the bottom of the second line? or the bottom of the first line? – Symbol 1 Aug 16 '17 at 20:23
3

Using tikz to draw a simple rule sounds a bit overkill - I would simply do the following:

\documentclass{beamer}

\setbeamercolor{separation line}{bg=red}

\makeatletter
\setbeamertemplate{frametitle}{
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{frametitle}
    \usebeamerfont{frametitle}%
    \vbox{}\vskip-1ex%
    \if@tempswa\else\csname beamer@fteleft\endcsname\fi%
    \strut\MakeUppercase{\insertframetitle}\strut\par%
    {%
      \ifx\insertframesubtitle\@empty%
      \else%
      {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
      \fi
    }%
    \vskip-1ex%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}%
  \begin{beamercolorbox}[sep=0.3cm,wd=\the\@tempdima]{frametitle}
     \hrulefill\hspace*{0cm}
  \end{beamercolorbox}
}
\makeatother

\begin{document}

\begin{frame}
  \frametitle{A shor title}
  Foo
\end{frame}

\begin{frame}
  \frametitle{A terribly long beamer slide title about some obscure meaningless
  topic}
  Bar
\end{frame}

\end{document}

enter image description here


TIKZ solution

\documentclass{beamer}
\usepackage{tikz}

\setbeamercolor{separation line}{bg=red}

\makeatletter
\addtobeamertemplate{frametitle}{}{
    \begin{beamercolorbox}[sep=0.3cm,wd=\the\@tempdima]{frametitle}
       \begin{tikzpicture}
        \draw[structure.fg] (0,0) -- (12.2,0);
       \end{tikzpicture}
    \end{beamercolorbox}
}
\makeatother

\begin{document}

\begin{frame}
  \frametitle{A shor title}
  Foo
\end{frame}

\begin{frame}
  \frametitle{A terribly long beamer slide title about some obscure meaningless
  topic}
  Bar
\end{frame}

\end{document}
| improve this answer | |
  • Thanks for your answer. The thing is that I might also want to include an image in the header (that's why I'm using tikz). So basically this is not possible with tikz? – petobens Aug 16 '17 at 21:08
  • @petobens Is possible with tikz by not using absolute coordinates, but including an image does not need tikz – samcarter_is_at_topanswers.xyz Aug 16 '17 at 21:13
  • 1
    @petobens see my edit for a tikz solution, however I still think this is overkill. – samcarter_is_at_topanswers.xyz Aug 16 '17 at 21:18
  • If I add the following line : \setbeamertemplate{frametitle}{\expandafter\MakeUppercase\expandafter\insertframetitle} then your original code (without tikz) does not work. Can you please modify it so that i can also have uppercased frametitle? Thanks for the help – petobens Aug 17 '17 at 13:35
  • 1
    @petobens Comments are not the place to ask new questions – samcarter_is_at_topanswers.xyz Aug 17 '17 at 13:38

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.