[Tex/LaTex] Horizontal line next to section heading

rules

I have found good methods for adding a line over or under a section heading. A horizontal line that fills the whole width.

Is it possible to add such a line extending the rest of the width placed exactly next to the heading? That is, positioned in the middle of the line-height (not top or bottom)?

Best Answer

Something like that? Found on the internet this construction for raised rules:

\documentclass[a4paper]{article}
    \usepackage[explicit]{titlesec}
    % Raised Rule Command:
    % Arg 1 (Optional) - How high to raise the rule
    % Arg 2 - Thickness of the rule
    \newcommand{\raisedrulefill}[2][0ex]{\leaders\hbox{\rule[#1]{1pt}{#2}}\hfill}
    \titleformat{\section}{\Large\bfseries}{\thesection. }{0em}{#1\,\raisedrulefill[0.4ex]{2pt}}
\pagestyle{plain}

\begin{document}

  \section{A short title}
  This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.

  \section{Another purposely very long title that extends on more than one line}
  This is another paragraph.This is another paragraph.This is another paragraph.This is another paragraph.This is another paragraph.This is another paragraph.This is another paragraph.This is another paragraph.

\end{document} 

enter image description here