escape underscores
Set a \rule
of specified width:
\documentclass{article}
\newcommand{\format}[2][-.2\baselineskip]{\rule[#1]{#2}{.4pt}}
\begin{document}
Format (\format{2em}) \format{2em}-\format{2em}-\format{2em}-\format{2em}
\end{document}
Some vertical adjustment can be tweaked by trying different lengths. The optional argument to \format
sets the rule .2\baselineskip
below the baseline by default.
\documentclass{article}
\newcommand{\format}[2][2pt]{\underline{\hspace{#1}\phantom{#2}\hspace{#1}}}
\begin{document}
Format (\format{000}) \format{000}-\format{000}-\format{000}-\format{000}
\end{document}
The above option uses an \underline
d \phantom
with some padding.
I suggest making \format
to use a sample argument to define the width (plus buffer, in this case 2pt). For example, \format{000}
will make the underline the width of "000" plus 2pt.
\documentclass{article}
\newcommand{\format}[1]{\setbox0=\hbox{#1}\rule[-.2\baselineskip]{\dimexpr2pt+\wd0}{.4pt}}
\begin{document}
Format (\format{00}) \format{000}-\format{000}-\format{000}-\format{000}
\end{document}
If one wanted to account for the difference between typeset versus handwritten lettering, one could apply a multiplier to \wd0
, as in
\documentclass{article}
\newcommand{\format}[1]{\setbox0=\hbox{#1}\rule[-.2\baselineskip]{\dimexpr3pt+1.5\wd0}{.4pt}}
\begin{document}
Format (\format{00}) \format{000}-\format{000}-\format{000}-\format{000}
\end{document}