[Tex/LaTex] How to make text in a middle of a line : ——- Text example ——-

line

I would like to make horizontal lines at each side of some text. I tried to use \rule, but I want the total lenght (text + line) to be the same (and user defined) for several line-text, so the line lenght depends on the text lenght. Example :

Tree text-lines

Is there a package or a native LaTeX command to do the trick ?

Best Answer

\documentclass{article}
\usepackage{xhfill}
\begin{document}        
\noindent
\xrfill[0.7ex]{1pt}Text\xrfill[0.7ex]{1pt}

\noindent
\xrfill[0.7ex]{1pt}This is a longer text\xrfill[0.7ex]{1pt}
\end{document}

enter image description here

Related Question