Here's a fairly general macro.
The idea is to typeset twice the sequence of digits using first the digits themselves with the overlines and then the phantoms of the digits with the underlines.
For the first step we use a zero width box sticking on the right, which contains a bottom aligned array
with all spacing parameters set to zero; the second passage uses a top aligned array
.
\documentclass{article}
\usepackage{booktabs}
\ExplSyntaxOn
\NewDocumentCommand{\overunderline}{mmm}
{% #1 is the sequence of digits
% #2 is the sequence of overlines
% #3 is the sequence of underlines
\group_begin:
\setlength{\arraycolsep}{0pt}
\renewcommand{\arraystretch}{0}
\setlength{\belowrulesep}{\aboverulesep}
\setlength{\cmidrulekern}{0.1em}
\ziggy_overunderline:nnn { #1 } { #2 } { #3 }
\group_end:
}
\seq_new:N \l__ziggy_overunderline_over_seq
\seq_new:N \l__ziggy_overunderline_under_seq
\seq_new:N \l__ziggy_overunderline_digits_seq
\seq_new:N \l__ziggy_overunderline_phantoms_seq
\cs_new_protected:Nn \ziggy_overunderline:nnn
{
\seq_set_split:Nnn \l__ziggy_overunderline_digits_seq { } { #1 }
\seq_set_map:NNn \l__ziggy_overunderline_phantoms_seq \l__ziggy_overunderline_digits_seq
{
\phantom{##1}
}
\clist_map_inline:nn { #2 }
{
\seq_put_right:Nn \l__ziggy_overunderline_over_seq { \cmidrule(lr){##1} }
}
\clist_map_inline:nn { #3 }
{
\seq_put_right:Nn \l__ziggy_overunderline_under_seq { \cmidrule(lr){##1} }
}
\hbox_to_zero:n
{
$\begin{array}[b]{*{\seq_count:N \l__ziggy_overunderline_digits_seq}{c}}
\seq_use:Nn \l__ziggy_overunderline_over_seq {}
\seq_use:Nn \l__ziggy_overunderline_digits_seq { & } \\
\end{array}$\hss
}
\begin{array}[t]{*{\seq_count:N \l__ziggy_overunderline_digits_seq}{c}}
\seq_use:Nn \l__ziggy_overunderline_phantoms_seq { & } \\
\seq_use:Nn \l__ziggy_overunderline_under_seq {}
\end{array}
}
\ExplSyntaxOff
\begin{document}
$\{\overunderline{000}{1-2}{2-3}\}$
$0\overunderline{0000000000}{1-2,3-5}{2-4,6-9}$
\end{document}
The second example has a leading digit to show that the vertical placement is correct.