[Tex/LaTex] Adding line after section heading

rulessectioningsectstytitlesec

I am trying to add a horizontal line (like \hrule) that starts just after each section's heading, fills the rest of the line, and is vertically aligned with the heading, as shown below.
Desired output

To do so, I have defined a \newcommand called \raisedrule that generates the desired horizontal line (following this post). However, I am having difficulty incorporating it into the definition of the sections' headings.

I have tried using the titlesec package, but I have not found a way to generate a line that is shorter than the text's width. I have also tried using the sectsty package, using the following code:

\documentclass{article}

\newcommand{\raisedrule}[2][0em]{\leaders\hbox{\rule[#1]{1pt}{#2}}\hfill}

\usepackage{sectsty} 
    \sectionfont{
        \setmainfont{Arial} \raisedrule[0.32em]{0.75pt}
    }

\usepackage{fontspec}

\begin{document}

\section*{SECTION HEADING}

\end{document}

which, not only gives a "Leaders not followed by proper glue." error, but I don't think would generated the required output anyway.

Note that, as shown in the code, I also want to change the font of the heading, which may be important for the solution.

Any help would be greatly appreciated.

Best Answer

If you are willing to switch to titlesec which offers more customization capabilities (I also used xhfill to easily produce the rule, but this is optional):

\documentclass{article}
\usepackage{fontspec}
\usepackage{titlesec} 
\usepackage{xhfill}

\newcommand\ruleafter[1]{#1~\xrfill[.7ex]{1pt}}
\titleformat{\section}
  {\normalfont\Large\fontspec{Arial}}{\thesection}{1em}{\ruleafter}

\begin{document}

\section*{SECTION HEADING}

\end{document}

The result:

enter image description here

Adjust the rule settings according to your needs; you might want to adjust the space between the title and the rule and, as Sean Allred mentions in his comment, it's enough to use \fontspec instead of \setmainfont.