拆分相邻的上划线

拆分相邻的上划线

该序列4813065297按降序排列有 5 个相邻对,即8130655297。我想通过上划线突出显示这些对,但是65和 重叠52,因此只能得到连续的上划线:

\[4\overline{81}\overline{30}\overline{652}\overline{97}\]

问:6我怎样才能在 到的中间画一条上划线5,然后再从那里到 画另一条线2,并且留出一条可见的小间隙?

答案1

所有的\overlines 都会互相碰撞,因此首先需要一条狭窄的上划线,以留出空隙。

在这里,我创建了\noverline(narrow-overline),它使用字距调整技巧根据输入的长度来缩小上线的\def宽度\nindent

然后,您需要一些东西来执行问题所要求的操作,创建一个中间留有空隙的上划线。为此,我创建了\midoverline

\documentclass{article}
\usepackage{mathtools}
\newcommand\nindent{.5pt}
\newcommand\noverline[1]{%
  \kern\nindent\overline{\kern-\nindent#1\kern-\nindent}\kern\nindent}
\newcommand\midoverline[1]{%
  \sbox0{$#1$}%
  \bgroup\ooalign{$#1$\cr$\noverline{\rule{.5\wd0}{0pt}\vphantom{#1}}%
  \noverline{\rule{.5\wd0}{0pt}\vphantom{#1}}$}\egroup
}
\begin{document}
\[4\noverline{81}\noverline{30}\midoverline{652}\noverline{97}\]
\end{document}

在此处输入图片描述

答案2

您可以减少上划线的长度,并利用所有数字都具有相同的宽度。

\documentclass{article}
\usepackage{amsmath}

\newmuskip\ovskip
\ovskip=1mu

\newcommand{\decr}[1]{%
  \mspace{\ovskip}%
  \overline{\mspace{-\ovskip}#1\mspace{-\ovskip}}%
  \mspace{\ovskip}%
}
\newcommand{\decrdbl}[3]{%
  \decr{#1\hspace{0.5\fontcharwd\textfont0`0}}%
  \hspace{-0.5\fontcharwd\textfont0`0}%
  #2%
  \hspace{-0.5\fontcharwd\textfont0`0}%
  \decr{\hspace{0.5\fontcharwd\textfont0`0}#3}%
}

\begin{document}

\[
4\decr{81}\decr{30}\decrdbl{6}{5}{2}\decr{97}
\]

\end{document}

在此处输入图片描述

\ovskip=1.5mu会得到

在此处输入图片描述

尝试一下最适合您口味的东西。

自动版本

只是为了好玩,这里有一个可以为您完成所有工作的版本。

\documentclass{article}
\usepackage{amsmath}

\newmuskip\ovskip
\ovskip=1mu

\ExplSyntaxOn

\NewDocumentCommand{\markdecrease}{m}
 {
  \yrodro_markdecrease:n { #1 }
 }

\tl_new:N \l__yrodro_markdecrease_tl
\seq_new:N \l__yrodro_markdecrease_seq

\cs_new_protected:Nn \yrodro_markdecrease:n
 {
  % typeset the number
  #1
  % back up
  \hspace{-\tl_count:n { #1 } \fontcharwd\textfont0`0}
  % compute the overlines
  \tl_clear:N \l__yrodro_markdecrease_tl
  \__yrodro_markdecrease:NN #1 \q_nil
 }
\cs_new_protected:Nn \__yrodro_markdecrease:NN
 {
  \quark_if_nil:NTF { #2 }
   {% end of the recursion, add the last digit
    \tl_put_right:Nn \l__yrodro_markdecrease_tl { #1 }
    % split at periods
    \seq_set_split:NnV \l__yrodro_markdecrease_seq { . } \l__yrodro_markdecrease_tl
    % produce the overlines
    \seq_map_function:NN \l__yrodro_markdecrease_seq \__yrodro_markdecrease_item:n
   }
   {% there are more digits, add the first one
    \tl_put_right:Nn \l__yrodro_markdecrease_tl { #1 }
    % if the next digit is not less than the current one, add a period
    \int_compare:nF { #1 > #2 }
     {
      \tl_put_right:Nn \l__yrodro_markdecrease_tl { . }
     }
    % restart the recursion with the next digit as the first one
    \__yrodro_markdecrease:NN #2
   }
 }

\cs_new_protected:Nn \__yrodro_markdecrease_item:n
 {
  \int_case:nnF { \tl_count:n { #1 } }
   {
    {1}{ \__yrodro_markdecrease_blank: }
    {2}{ \__yrodro_markdecrease_over:n {00} }
   }
   { \__yrodro_markdecrease_more:n { #1 } }
 }

\cs_new_protected:Nn \__yrodro_markdecrease_blank:
 {
  \phantom{0}
 }
\cs_new_protected:Nn \__yrodro_markdecrease_over:n
 {
  \mspace{\ovskip}
  \overline{\mspace{-\ovskip}\phantom{#1}\mspace{-\ovskip}}
  \mspace{\ovskip}
 }
\cs_new_protected:Nn \__yrodro_markdecrease_more:n
 {
  \__yrodro_markdecrease_oneandhalf:
  \prg_replicate:nn { \tl_count:n { #1 } - 3 } { \__yrodro_markdecrease_over:n {0} }
  \__yrodro_markdecrease_oneandhalf:
 }
\cs_new_protected:Nn \__yrodro_markdecrease_oneandhalf:
 {
  \mspace{\ovskip}
  \overline{\mspace{-\ovskip}\phantom{0}\hspace{0.5\fontcharwd\textfont0`0}\mspace{-\ovskip}}
  \mspace{\ovskip}
 }

\ExplSyntaxOff

\begin{document}

\[
\markdecrease{4813065297}\quad\markdecrease{9876543210}
\]

\end{document}

在此处输入图片描述

略有不同的版本,它绘制从数字中间开始并结束的上线(带有小间隙)。

\documentclass{article}
\usepackage{amsmath}

\newmuskip\ovskip
\ovskip=1mu

\ExplSyntaxOn

\NewDocumentCommand{\markdecrease}{m}
 {
  \yrodro_markdecrease:n { #1 }
 }

\tl_new:N \l__yrodro_markdecrease_tl
\seq_new:N \l__yrodro_markdecrease_seq

\cs_new_protected:Nn \yrodro_markdecrease:n
 {
  % typeset the number
  #1
  % back up
  \hspace{-\tl_count:n { #1 } \fontcharwd\textfont0`0}
  % compute the overlines
  \tl_clear:N \l__yrodro_markdecrease_tl
  \__yrodro_markdecrease:NN #1 \q_nil
 }
\cs_new_protected:Nn \__yrodro_markdecrease:NN
 {
  \quark_if_nil:NTF { #2 }
   {% end of the recursion, add the last digit
    \tl_put_right:Nn \l__yrodro_markdecrease_tl { #1 }
    % split at periods
    \seq_set_split:NnV \l__yrodro_markdecrease_seq { . } \l__yrodro_markdecrease_tl
    % produce the overlines
    \seq_map_function:NN \l__yrodro_markdecrease_seq \__yrodro_markdecrease_item:n
   }
   {% there are more digits, add the first one
    \tl_put_right:Nn \l__yrodro_markdecrease_tl { #1 }
    % if the next digit is not less than the current one, add a period
    \int_compare:nF { #1 > #2 }
     {
      \tl_put_right:Nn \l__yrodro_markdecrease_tl { . }
     }
    % restart the recursion with the next digit as the first one
    \__yrodro_markdecrease:NN #2
   }
 }

\cs_new_protected:Nn \__yrodro_markdecrease_item:n
 {
  \hspace{0.5\fontcharwd\textfont0`0}
  \prg_replicate:nn { \tl_count:n { #1 } - 1 }
   {
    \mspace{\ovskip}
    \overline{\mspace{-\ovskip}\phantom{0}\mspace{-\ovskip}}
    \mspace{\ovskip}
   }
  \hspace{0.5\fontcharwd\textfont0`0}
 }

\ExplSyntaxOff

\begin{document}

\[
\markdecrease{4813065297}\quad\markdecrease{9876543210}
\]

\end{document}

在此处输入图片描述

相关内容