[Tex/LaTex] beamer full width hrule below frame title

beamerrules

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?

Best Answer

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