![將符號放置在關係上而不更改上標的放置位置](https://rvso.com/image/449632/%E5%B0%87%E7%AC%A6%E8%99%9F%E6%94%BE%E7%BD%AE%E5%9C%A8%E9%97%9C%E4%BF%82%E4%B8%8A%E8%80%8C%E4%B8%8D%E6%9B%B4%E6%94%B9%E4%B8%8A%E6%A8%99%E7%9A%84%E6%94%BE%E7%BD%AE%E4%BD%8D%E7%BD%AE.png)
我想在關係上放置一個符號而不改變上標的放置位置。
\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{accents}
\newcommand{\rel}{\rhd}
\newcommand{\symb}{\text{I}}
\newcommand{\testmyrel}[1]{%
\begin{center}%
\begin{minipage}{\linewidth/2}%
\noindent Text text text\\%
$\text{T} #1^* \text{U}$\\%
$\text{T} \rel^* \text{U}$\\%
\end{minipage}%
\end{center}%
}%
\begin{document}
My goal is to place a symbol (e.g. $\symb$) over a rel (e.g. $\rel$) that can be used in text without overlapping with text above, and handles superscripts as if it did not have a symbol:
\begin{center}%
\begin{minipage}{\linewidth/2}%
\noindent Text text text\\%
$\text{T} \mathrel{\overset{\symb}{\rel}\vphantom{\rel}^*} \text{U}$\\%
$\text{T} \rel^* \text{U}$\\%
\end{minipage}%
\end{center}%
However, I do not want the superscript to be an argument of the command, which rules out the code above.
\begin{itemize}
\item Using overset makes the star too high:%
\testmyrel{%
\mathrel{%
\overset{%
\symb%
}{%
\mathord{\rel}%
}%
}%
}%
%
\item Smashing the rel makes it go over the text:%
\testmyrel{%
\mathrel{%
\smash{
\overset{\symb}{\mathord{\rel}}%
}%
}%
}%
%
\item Smashing the symbol makes it go over the text:%
\testmyrel{%
\mathrel{%
\overset{%
\smash{\symb}%
}{%
\mathord{\rel}%
}%
}%
}%
%
\item Adding a vphantom inside mathrel leads to the star being too high:%
\testmyrel{%
\mathrel{%
\overset{\symb}{\mathord{\rel}}%
\vphantom{\symb}%
}%
}%
%
\item Adding a vphantom after mathrel leads to the star being misplaced to the right:%
\testmyrel{%
\mathrel{%
\overset{\symb}{\mathord{\rel}}%
}%
\vphantom{\symb}%
}%
\item Accentset without mathrel does not have the spacing due to mathrel:
\testmyrel{%
\accentset{\symb}{\mathord{\rel}}%
}%
\item Accentset with mathrel puts the star too high:
\testmyrel{%
\mathrel{\accentset{\symb}{\mathord{\rel}}}%
}%
\end{itemize}
\end{document}
答案1
不要用於\text
數學中的直排字,它通常不起作用;使用\mathrm
。
\rhd
也是不是一個關係符號,但要實現它並不困難。
\documentclass{article}
\usepackage{amsmath,amssymb,accents}
% \rhd is not a relation symbol
\mathchardef\rel=\numexpr\rhd+"1000
\newcommand{\overrel}[2]{%
\mathrel{\accentset{#1}{#2}}%
\mathrel{\vphantom{#2}}%
}
\begin{document}
\begin{center}
Text text text\\
$T \overrel{\mathrm{I}}{\rel}^* U$\\
$T \rel^* U$
\end{center}
\end{document}
或者,使用\overset
:
\newcommand{\overrel}[2]{%
\overset{#1}{#2}%
\mathrel{\vphantom{#2}}%
}
訣竅在於 TeX 在連續的關係原子之間不添加空格,也不會添加換行點。因此我們可以將下標/上標加入到幻像關係中。