带有垂直间距的彩色下划线

带有垂直间距的彩色下划线

如何通过调整\colorunderline命令在下划线和其他项目之间添加垂直间距?

\documentclass[12pt,b5paper]{article}
\usepackage{amsmath}
\usepackage{color}

\newsavebox\UnderlineBox
\newcommand\colorunderline[2][red]{%
        {\sbox\UnderlineBox{$#2$}%
        \rlap{\usebox\UnderlineBox}\color{#1}%
        \raisebox{-5pt}{\mbox{\rule[-\dp\UnderlineBox]{\wd\UnderlineBox}{3pt}}}%
        }%
}

\begin{document}


\begin{align}
\begin{array}{c}
A\\
\colorunderline[red]{A}\\
A
\end{array}
\end{align}

\end{document}

在此处输入图片描述

答案1

这是一个\innercolorunderline可以满足您需求的宏,参数列表应该是不言自明的。我添加了一个更方便的键值接口和一些示例。

\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}

\newcommand{\innercolorunderline}[4]{%
  % #1 = space above rule, #2 = space below rule, #3 = color, #4 = symbol
  \vtop{
    \offinterlineskip
    \sbox0{$#4$}
    \copy0
    \kern#1
    \hbox{\color{#3}\vrule height 3pt width \wd0}
    \kern#2
  }%
}

\ExplSyntaxOn
\keys_define:nn { gabriel/colorunderline }
 {
  color .tl_set:N  = \l_gabriel_colorunderline_color_tl,
  color .initial:n = red,
  above .dim_set:N = \l_gabriel_colorunderline_above_dim,
  above .initial:n = 2pt,
  below .dim_set:N = \l_gabriel_colorunderline_below_dim,
  below .initial:n = 0pt,
 }

\NewDocumentCommand{\colorunderline}{O{}m}
 {
  \group_begin:
  \keys_set:nn { gabriel/colorunderline } { #1 }
  \gabriel_colorunderline:VVVn
    \l_gabriel_colorunderline_above_dim
    \l_gabriel_colorunderline_below_dim
    \l_gabriel_colorunderline_color_tl
    { #2 }
  \group_end:
 }
\cs_set_eq:NN \gabriel_colorunderline:nnnn \innercolorunderline
\cs_generate_variant:Nn \gabriel_colorunderline:nnnn { VVV }
\ExplSyntaxOff

\begin{document}

\[
\begin{array}[t]{c}
A\\
\colorunderline{A}\\
A
\end{array}
\quad
\begin{array}[t]{c}
A\\
\colorunderline[color=green]{A}\\
A
\end{array}
\quad
\begin{array}[t]{c}
A\\
\colorunderline[above=6pt]{A}\\
A
\end{array}
\quad
\begin{array}[t]{c}
A\\
\colorunderline[color=red,above=6pt,below=6pt]{A}\\
A
\end{array}
\]

\end{document}

在此处输入图片描述

相关内容