کد: [انتخاب]
\documentclass{article}
\newcommand\mytext[1]{%
\setbox0=\hbox{#1}%
\hrule height 2pt width \wd0}
\begin{document}
\mytext{Example 1}
\bigskip
\mytext{Example 1.2}
\end{document}
\documentclass{article}
\newcommand\mytext[1]{%
\setbox0=\hbox{#1}%
\hrule height 2pt width \wd0}
\begin{document}
\mytext{Example 1}
\bigskip
\mytext{Example 1.2}
\end{document}