更改 \underline 线条粗细

更改 \underline 线条粗细

正如标题所说,我想改变命令生成的线条的粗细\underline(并避免使用更多包)到目前为止,我已经设法使用宏来改变它的颜色

\def\underline#1{%
  \relax
  \ifmmode\@@underline{#1}%
  \else $\textcolor{NavyBlue}{\@@underline{\hbox{#1}}}\m@th$\relax\fi}
\makeatother

我一直在阅读这里发布的一些帖子,但没有一个帖子提供使用相同命令的直接解决方案\underline。我也一直在寻找的原始定义,\@@underline但它不是latex.ltx文件,也不是我检查过的任何其他文件。

真的没有办法吗?为什么这么难?

谢谢

PS:该命令是在投影仪中使用,以防万一。

答案1

您的-macro 会在数学模式之外\underline对内容进行排版。\hbox

这意味着需要加下划线的材料不需要连字符和换行。

这也意味着所有内容都可以按照其自然方式排版,而无需应用一些拉伸/收缩,以使材料很好地适应在非限制水平模式下自动断开的线条。

因此,如果不是处于数学模式,下面类似的东西可能就足够了:

\documentclass{article}
\usepackage[dvipsnames, usenames]{xcolor}

\newcommand\MyUnderLineWithNoLinebreaks[5]{%
  % #1 - text to underline
  % #2 - color of rule
  % #3 - color of text
  % #4 - distance between rule and baseline of line of text
  % #5 - thickness of rule
  \protect\leavevmode
  {%
    \color{#2}%
    \vtop{%
      \hbox{\color{#3}#1}%
      \kern-\prevdepth
      \kern#4\relax
      \hrule height #5\relax
      \kern-#4\relax
      \kern-#5\relax
    }%
  }%
}%

\begin{document}
Text Text \MyUnderLineWithNoLinebreaks{Bla xypqg}{NavyBlue}{ForestGreen}{.3mm}{.3pt}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text \MyUnderLineWithNoLinebreaks{Bla xypqg}{Melon}{WildStrawberry}{.75mm}{2mm}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
\end{document}

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

这样,下划线就会覆盖/划掉有一定深度的字母部分。(图片中蓝色确实覆盖了绿色。)

如果您希望字母的某些部分有一定深度以掩盖下划线,您可以尝试以下方法:

\documentclass{article}
\usepackage[dvipsnames, usenames]{xcolor}

\newlength\scratchlength

\newcommand\MyUnderLineWithNoLinebreaks[5]{%
  % #1 - text to underline
  % #2 - color of rule
  % #3 - color of text
  % #4 - distance between rule and baseline of line of text
  % #5 - thickness of rule
  \protect\leavevmode
  {%
    \color{#2}%
    \vtop{%
      \settoheight\scratchlength{#1}%
      \hbox{\phantom{#1}}%
      \kern-\prevdepth
      \kern#4\relax
      \hrule height #5\relax
      \kern-#4\relax
      \kern-#5\relax
      \kern-\scratchlength
      \hbox{\color{#3}#1}%
    }%
  }%
}%

\begin{document}
Text Text \MyUnderLineWithNoLinebreaks{Bla xypqg}{NavyBlue}{ForestGreen}{.3mm}{.3pt}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text \MyUnderLineWithNoLinebreaks{Bla xypqg}{Melon}{WildStrawberry}{.75mm}{2mm}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
\end{document}

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

(图片中的绿色确实遮住了蓝色。)

如果你不喜欢这些限制(自然宽度,即不收缩/拉伸,没有连字符,没有自动换行),请查看灵魂-包裹。

相关内容