答案1
对于简单的应用程序,您只需添加规则即可。
\documentclass{article}
\usepackage{amsmath}
\newcommand{\UnderlineWithBorders}[1]{\setbox0\hbox{#1}%
\rule[\the\dimexpr-0.37ex-\dp0]{0.1ex}{0.3ex}\underline{#1}\rule[\the\dimexpr-0.37ex-\dp0]{0.1ex}{0.3ex}}
\begin{document}
\UnderlineWithBorders{ABC} \UnderlineWithBorders{ijk}
\end{document}
对于更通用的版本,你可以开始编写非常复杂的宏,或者直接使用 Ti钾Z 和tikzmark
图书馆。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcounter{underlinedtikzmarknode}
\newcommand{\UnderlineWithBorders}[2][]{\stepcounter{underlinedtikzmarknode}%
\tikzmarknode[inner xsep=0.2ex,inner ysep=0.4ex,path picture={
\draw([yshift=0.4ex,xshift=\pgflinewidth]path picture bounding box.south west)
|- ([yshift=\pgflinewidth,xshift=-\pgflinewidth]path picture bounding box.south east)
-- ([yshift=0.4ex,xshift=-\pgflinewidth]path picture bounding box.south east);
}]{underlinedtikzmarknode-\number\value{underlinedtikzmarknode}}{#2}}
\begin{document}
\UnderlineWithBorders{ABC} \UnderlineWithBorders{ijk}
\[\UnderlineWithBorders{A}=\UnderlineWithBorders{\int\limits_0^1f(x)\,\mathrm{d}x}\]
\end{document}