答案1
答案2
主要思想来自https://tex.stackexchange.com/a/479765/201158
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\makeatletter
\newlength\lrvec@height
\newlength\lrvec@width
\newif\iflrvec@same@height
\def\lrvec{\@ifstar\slrvec@\lrvec@}
\newcommand{\slrvec@}[2][.4ex]{
\lrvec@same@heighttrue
\mathpalette\lrvec@@{{#1}{#2}}
}
\newcommand{\lrvec@}[2][.4ex]{
\lrvec@same@heightfalse
\mathpalette\lrvec@@{{#1}{#2}}
}
\def\lrvec@@#1#2{\lrvec@@@#1#2}
\def\lrvec@@@#1#2#3{%
\iflrvec@same@height
\settoheight{\lrvec@height}{$\m@th#1 \mathbf{T}#3$}
\else
\settoheight{\lrvec@height}{$\m@th#1#3$}
\fi
\settowidth{\lrvec@width}{$\m@th#1#3$}
\kern.08em
\raisebox{#2}{\raisebox{\lrvec@height}{\rlap{%
\kern-.05em
\begin{tikzpicture}[<-> /.tip={To[width=.4em, length=.2em]}]
\draw [<->] (-.05em,0)--(\lrvec@width+.05em,0);
\end{tikzpicture}%
}}}%
#3
\kern.08em
}
\makeatother
\begin{document}
Overleftrightarrow: $\lrvec{\mathrm{T}}\lrvec{a}$
With same height: $\lrvec*{\mathrm{T}}\lrvec*{c}$
Above arrow sep: $\lrvec{a}\lrvec[1ex]{a}$
In script: $T_{\lrvec{a}}$
In display math:
\[
\lrvec{a}\lrvec{\sum_{i=1}^{n} a^n}
\]
\end{document}