[Tex/LaTex] How to insert a text in \rule

cvrulestext;

\documentclass{article}

\begin{document}

\hrule

\noindent\rule{\textwidth}{0.4mm}

\noindent\rule{\textwidth}{0.4pt}

\end{document}

I need to insert text inside the rule.

Best Answer

Unless I've completely misunderstood the problem, here's a version that inserts text into a "rule" by using a \colorbox of appropriate width instead of an actual LaTeX rule:

\documentclass{article}

\usepackage{lipsum}
\usepackage{xcolor}

\newcommand\rulebox[1]{%
    \begingroup
    \fontsize{5}{5}\selectfont
    \fboxsep0.5pt%
    \colorbox{black}{\makebox[\linewidth][c]{\textcolor{black!80}{#1}}}%
    \endgroup
}

\begin{document}

\lipsum[1]

\noindent\rulebox{Some hidden text here}

\end{document}

enter image description here

With a higher magnification, the hidden message (if that was intended) becomes readable:

enter image description here