答案1
回收我的代码https://tex.stackexchange.com/a/294539/4427
\documentclass{article}
\usepackage{amsmath}
\usepackage{stmaryrd}
\makeatletter
\newcommand{\segment}[1]{%
\mathord{\vbox{\offinterlineskip\m@th
\ialign{##\cr
$\m@th\scriptscriptstyle{\mapstochar\relbar}
\leaderbar
{\relbar\mkern-1mu\mapsfromchar}$\cr
$\m@th#1$\cr
}%
}}%
}
\newcommand{\leaderbar}{%
\mkern-7mu
\cleaders\hbox{$\scriptscriptstyle\mkern-2mu{\relbar}\mkern-2mu$}\hfill
\mkern-7mu
}
\makeatother
\begin{document}
$\segment{AB}$
\end{document}
答案2
已编辑以处理较小的数学样式。规则粗细基于\fboxrule
,但针对较小的数学尺寸减小。
\documentclass{article}
\usepackage{tabstackengine,scalerel}
\makeatletter
\def\m@scaleD{1}
\def\m@scaleT{1}
\def\m@scaleS{\scriptstyleScaleFactor}
\def\m@scales{\scriptscriptstyleScaleFactor}
\def\Mscale{\csname m@scale\m@switch\endcsname}
\makeatother
\newcommand\vstroke{\rule[\dimexpr-1.4\LMpt+.1pt\relax]{\fboxrule}{3\LMpt}}
\newcommand\flatarrow[1]{%
\ThisStyle{\ensurestackMath{\tabbedstackon[1\LMpt]{\SavedStyle#1}%
{\fboxrule=\Mscale\fboxrule\relax%
\SavedStyle\rlap{\vstroke}\TABrule\llap{\vstroke}}}}%
}
\begin{document}
$\flatarrow{AB}\quad\flatarrow{xyz}$\par
$\scriptstyle\flatarrow{AB}\quad\flatarrow{xyz}$\par
$\scriptscriptstyle\flatarrow{AB}\quad\flatarrow{xyz}$
\end{document}