在 Latex 中为 tex 添加下划线

在 Latex 中为 tex 添加下划线

我在 tex 下插入了如下的直线代码。我想让这条直线等同于单词“我的老师”,并且我想改变这条直线的长度,那么该怎么做呢?请帮帮我!非常感谢!

\documentclass{article}

  \usepackage{lipsum}

\usepackage{xparse}

\NewDocumentCommand{\myrule}{O{1.8pt} O{3pt} O{brown}}{%
  \par\nobreak % don't break a page here
 \kern\the\prevdepth % don't take into account the depth of the preceding line
  \kern#2 % space before the rule
  {\color{#3}\hrule height #1 width\hsize} % the rule
   \kern#2 % space after the rule
   \nointerlineskip % no additional space after the rule
    }

   \begin{document}
     lipsum[1]

     My teacher
     \hrule

      \end{document}

输出

在此处输入图片描述

答案1

这使用基本的\box宽度和深度,并将规则直接放在下降部下方(如果有的话)等等\dp\rulebox。)

\documentclass{article}

\usepackage{xcolor}
\usepackage{lipsum}

\usepackage{xparse}


\NewDocumentCommand{\myrule}{O{1.8pt}mO{brown}}{%
\begingroup
\newbox\rulebox
\setbox\rulebox=\hbox{#2}
#2
\parskip=0pt\par%
\nointerlineskip
{\color{#3}\rule[-\dp\rulebox]{\wd\rulebox}{#1}}
\endgroup
}


\begin{document}
\lipsum[1]

\myrule{My teacher}

\end{document}

在此处输入图片描述

更新一些选项界面 \documentclass{文章}

\usepackage{xcolor}
\usepackage{lipsum}

\usepackage{xparse}

\ExplSyntaxOn
\prop_new:N \l_tranhoang_options_prop
\keys_define:nn {tranhoang} {
  rulecolor  .code:n = {\prop_put:Nnn \l_tranhoang_options_prop {rulecolor} {#1}},
  rulewidth  .code:n = {\prop_put:Nnn \l_tranhoang_options_prop {rulewidth} {#1}},
  extraruleshift  .code:n = {\prop_put:Nnn \l_tranhoang_options_prop {extraruleshift} {#1}},  
}

\cs_new:Npn \retrieveadmindata #1 {
  \prop_item:Nn \l_tranhoang_options_prop {#1}
}

\cs_new:Npn \SetupMyRule #1 {
  \keys_set:nn {tranhoang} {#1}
}

\ExplSyntaxOff
\NewDocumentCommand{\myrule}{O{}+m}{%
  \begingroup
  \SetupMyRule{rulecolor=brown,rulewidth=1.8pt,extraruleshift=0pt,#1}
  \newbox\rulebox
  \setbox\rulebox=\hbox{#2}

  #2
  \par%
  \nointerlineskip
  \color{\retrieveadmindata{rulecolor}}\rule[\dimexpr-\dp\rulebox+\retrieveadmindata{extraruleshift}]{\wd\rulebox}{\retrieveadmindata{rulewidth}}
  \endgroup
}


\begin{document}
\lipsum[1]

\myrule[rulecolor=yellow]{My teacher}

\myrule[rulewidth=2pt,extraruleshift=-1ex]{My teacher}

\end{document}

在此处输入图片描述

答案2

或者您是这个意思?

\documentclass{article}

\usepackage{soul}
\usepackage{lipsum}

\begin{document}
    \lipsum[1]

    \ul{My teacher}


\end{document}

在此处输入图片描述

相关内容