I'm attempting to put an underline and an overline above a single digit and I can't seem to figure out a way to do it. Here is what I'm attempting to do. I only used color to emphasize my point. The idea is to show that their is a repeating pattern of 2 with one overlapping element {00} and {00} {11} and {11}.

enter image description here

All I can think of to do is


This produces the below which is obviously incorrect. Any assistance would be appreciated! Thank you!

enter image description here

3 Answers 3


Sometimes the obvious solution works.

%! TEX program = lualatex

    \{ \overline{0}\overline{\underline{0}}\underline{0} \} \\
    \{ 00\overline{1}\overline{\underline{1}}\underline{1} \} \\


output image

i.e., it's just like this


but by default there's no space inbetween.


You could exploit the fact that lining-style numerals (generally) have the same width.

enter image description here

\settowidth\mylen{0} % measure width of lining-style numerals 



Alternatively, you could make use of the fact that \overline and \underline are as wide as the material they cover. E.g.,

enter image description here

% !TEX TS-program = lualatex
\setmathfont{Cambria Math} % choose a suitable OpenType math font


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.



 {% #1 is the sequence of digits
  % #2 is the sequence of overlines
  % #3 is the sequence of underlines
  \ziggy_overunderline:nnn { #1 } { #2 } { #3 }

\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
  \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} }
    $\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 { & } \\
   \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 {}






The second example has a leading digit to show that the vertical placement is correct.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .