0

I want to create a beamer template with a horizontal rule below every frame title.

The line should start just below the first letter of the title and extend until the very end of the frame.

Desired result:

Frame title with an hrule below spanning to the right end of the frame

The solution should be flexible enough to handle different font sizes and long titles spanning two lines. However, the vertical position of rule should not adapt to the height of the characters used in the frame title (e.g., whether or not the characters extend below to the baseline). To clarify:

Vertical alignment of the hrule depending on the characters in the frame title

To create a rule spanning the entire width of the frame, I use \makebox[\linewidth][l]{\rule{\paperwidth}{0.4pt}}, as suggested by others. An undesired side-effect of using \makebox is that it behaves differently from \hrule, e.g., it has a different height.

I solved the problem of fluctuating positioning of the rule by using \vphantom{g} in the frame title, but another solution might be more elegant.

\documentclass[t,9pt]{beamer}

\setbeamertemplate{frametitle}{%
    \usebeamerfont{frametitle}\insertframetitle%
    \vphantom{g}% To avoid fluctuations per frame
    %\hrule% Uncomment to see desired effect, without a full-width hrule
    \makebox[\linewidth][l]{\rule{\paperwidth}{0.4pt}}% 
}

\begin{document}
\begin{frame}{Frame Title}
Frame contents.
\end{frame}
\end{document}

How do I get the desired result of a line below the frame title running until the right end of the frame?

5

I understand that you looking for:

enter image description here

\documentclass[t,9pt]{beamer}

\setbeamertemplate{frametitle}{%
    \usebeamerfont{frametitle}\insertframetitle%
    \vphantom{g}% To avoid fluctuations per frame
    %\hrule% Uncomment to see desired effect, without a full-width hrule
    \par% <-- added
    \hspace*{-\dimexpr0.5\paperwidth-0.5\textwidth}% <-- calculation of left margin width
    \rule[0.5\baselineskip]{\paperwidth}{0.4pt}%
}

\begin{document}
\begin{frame}{Frame Title }
Frame contents.
\end{frame}
\end{document}

Edit If you like to have less vertical space after horizontal rule, than try the following:

\setbeamertemplate{frametitle}{%
    \usebeamerfont{frametitle}\insertframetitle%
    \vphantom{g}% To avoid fluctuations per frame
    %\hrule% Uncomment to see desired effect, without a full-width hrule
    \par\hspace*{-\dimexpr0.5\paperwidth-0.5\textwidth}\rule[0.5\baselineskip]{\paperwidth}{0.4pt}
    \par\vspace*{-\baselineskip}% <-- reduce vertical space after rule
}

which gives

enter image description here

  • Nope, I wasn't looking for the negative hspace you added. However, omitting this, your answer solves my question, although I find a solution with leaders cleaner. – timothymctim Dec 11 '16 at 19:30
  • I consider the following sentence your question: "To create a rule spanning the entire width of the frame" :(. – Zarko Dec 11 '16 at 20:24
  • I'm sorry for the confusion. I also dislike the fact that I posted a question that I could answer myself in the end, even tough I have been stuck with this problem for quite some time. Still, I greatly appreciate your quick(!) answer. – timothymctim Dec 12 '16 at 23:36
0

Using another answer using \leaders, I solved my issue. Additionally, a cleaner solution is to use \strut instead of \vphantom{g}.

\setbeamertemplate{frametitle}{%
    \usebeamerfont{frametitle}\insertframetitle\strut%
    \vskip-.25\baselineskip%
    \leaders\vrule width \paperwidth\vskip0.4pt%
    \vskip0pt%
    \nointerlineskip
}

Note that I’ve moved the line ¼ baselineskip up. This makes the line run over the descenders (that’s actually what I needed).

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.