4

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

\[\{\overline{0\underline{0}0}\}\]

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

enter image description here

3 Answers 3

5

Sometimes the obvious solution works.

%! TEX program = lualatex
\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{gather}
    \{ \overline{0}\overline{\underline{0}}\underline{0} \} \\
    \{ 00\overline{1}\overline{\underline{1}}\underline{1} \} \\
\end{gather}

\end{document}

output image

i.e., it's just like this

explanation

but by default there's no space inbetween.

2

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

enter image description here

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

\begin{document}
$\{\overline{00}\kern-\mylen\underline{00}\}$

$\{00\overline{11}\kern-\mylen\underline{11}\}$
\end{document}

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
\documentclass{article}
\usepackage{unicode-math}
\setmathfont{Cambria Math} % choose a suitable OpenType math font
\begin{document}
$\{\overline{0}\overline{\underline{0}}\underline{0}\}$

$\{00\overline{1}\overline{\underline{1}}\underline{1}\}$
\end{document}
2

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.

enter image description here

You must log in to answer this question.

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