我想做一些类似下面等式中的框的事情
但我不知道如何在 Tex 中实现这一点。提前谢谢!
答案1
另一种选择(示例说明了根据数学样式的尺寸变化):
\documentclass{article}
\usepackage{amsmath}
\newlength\boxln
\newcommand\MyBox{{%
\setlength\fboxsep{0pt}%
\fbox{\phantom{\text{\raisebox{-0.25\boxln}{\rule{\boxln}{\boxln}}}}}}%
}
\newcommand\TwoBox[2]{%
\mathchoice
{\setlength\boxln{1.5em}{\text{\footnotesize#1}}\,\,\underset{\textstyle\text{\raisebox{-0.3em}{\footnotesize#2}}}{\MyBox}}
{\setlength\boxln{1em}{\scriptscriptstyle\text{#1}}\,\underset{\scriptscriptstyle\text{\raisebox{-0em}{#2}}}{\MyBox}}
{\setlength\boxln{0.5em}{\scriptscriptstyle\text{#1}}\,\underset{\text{\raisebox{-0.1em}{#2}}}{\MyBox}}
{\setlength\boxln{0.5em}{\scriptscriptstyle\text{#1}}\,\underset{\text{\raisebox{-0.25em}{#2}}}{\MyBox}}
}
\begin{document}
\[
\TwoBox{P}{A}\longleftrightarrow\TwoBox{A}{P}
\]
Some text $
\TwoBox{P}{A}\longleftrightarrow\TwoBox{A}{P}\quad
M_{\TwoBox{P}{A}\longleftrightarrow\TwoBox{A}{P}}\quad
A_{M_{\TwoBox{P}{A}\longleftrightarrow\TwoBox{A}{P}}}
$ and some more
\end{document}
答案2
\sum
这是我的解决方案;该框的高度与文本样式的高度相同。
\documentclass{article}
\usepackage{amsmath}
\newcommand{\boxop}{\mathop{\mathpalette\doboxop\relax}}
\newcommand{\doboxop}[2]{%
\sbox0{$\ifx#1\displaystyle\textstyle\else#1\fi\sum$}%
\dimen0=\ht0 \advance\dimen0 \dp0
\vcenter{\fboxsep=-\fboxrule
\hbox{\fbox{\rule{0pt}{\dimen0}\rule{\dimen0}{0pt}}}
}%
}
\newcommand{\nymefirst}[1]{\mathpalette\donymefirst{#1}}
\newcommand{\donymefirst}[2]{%
\vcenter{\hbox{$
\ifx#1\displaystyle\scriptstyle\else
\ifx#1\textstyle\scriptstyle\else
\scriptscriptstyle\fi\fi #2
$}}%
}
\newcommand{\nymebox}[2]{%
\nymefirst{#1}\mspace{2mu}{\boxop\limits_{#2}}%
}
\begin{document}
\begin{alignat*}{2}
&\text{Display}\qquad && \nymebox{P}{A}\leftrightarrow\nymebox{A}{P} \\
&\text{Text} && \textstyle \nymebox{P}{A}\leftrightarrow\nymebox{A}{P} \\
&\text{Script} && \scriptstyle \nymebox{P}{A}\leftrightarrow\nymebox{A}{P}
\end{alignat*}
\end{document}
\boxop
如果我们将的定义改为
\newcommand{\doboxop}[2]{%
\sbox0{$\ifx#1\displaystyle\textstyle\else#1\fi\sum$}%
\dimen0=\ht0 \advance\dimen0 \dp0
\vcenter{\fboxsep=-\fboxrule
\hbox{\fbox{\rule{0pt}{\dimen0}\rule{\dimen0}{0pt}}}
}%
}
盒子将以展示风格增长,
答案3
编辑以保留数学风格:
\documentclass{article}
\usepackage{amssymb,stackengine,graphicx,scalerel}
\stackMath
\def\mybox{\scalebox{2.3}{\raisebox{\dimexpr-1.5\LMpt-0.5pt}{$\SavedStyle\square$}}}
\newcommand\labelbox[2]{\ThisStyle{\,\,\raisebox{\dimexpr1.5\LMpt+1pt}{$\SavedStyle_#1$}%
\stackunder[2pt]{\mybox}{\SavedStyle_#2}\,\,}}
\begin{document}
\[X\quad\labelbox{P}{A} \longleftrightarrow \labelbox{A}{P}\]
\[\scriptstyle X\quad\labelbox{P}{A} \longleftrightarrow \labelbox{A}{P}\]
\[\scriptscriptstyle X\quad\labelbox{P}{A} \longleftrightarrow \labelbox{A}{P}\]
\end{document}
原始解决方案:
\documentclass{article}
\usepackage{amssymb}
\usepackage{stackengine,graphicx}
\def\mybox{\scalebox{2.3}{\raisebox{-2pt}{$\square$}}}
\newcommand\labelbox[2]{%
\,\,\scriptstyle\mathrm{#1}\stackunder[2pt]{\mybox}{\scriptsize#2}\,\,}
\begin{document}
$\labelbox{P}{A} \longleftrightarrow \labelbox{A}{P}$
\end{document}