答案1
您可以使用一个打开一列的普通表格。为此定义一个新命令会非常方便。以下是它的一个实现:
\documentclass[12pt]{article}
\begin{document}
\newcommand{\ltab}[1]{\begin{tabular}{|@{}l@{}}
\hline
\ensuremath{#1}\\
\hline
\end{tabular}
}
\newcommand{\rtab}[1]{\begin{tabular}{@{}r@{}|}
\hline
\ensuremath{#1}\\
\hline
\end{tabular}
}
\[
\ltab{\hat{g}} = \sqrt{\frac{4\pi\delta}{\sigma_1((X+Y)(X-Y))^{\sigma_2}}}
\;\rtab{\approx 999.121}
\]
\end{document}
答案2
一个替代解决方案tcbox
,tcolorbox
可提供其所有附加功能。
\documentclass[12pt]{article}
\usepackage[theorems]{tcolorbox}
\tcbset{%
nobeforeafter,
math upper,
tcbox raise base,
sharp corners,
colback=white,
colframe=black,
boxsep=0pt,
left=1pt,
right=1pt,
top=2pt,
bottom=2pt,
boxrule=1pt
}
\newtcbox{\lbox}[1][]{
rightrule=0pt, #1}
\newtcbox{\rbox}[1][]{
leftrule=0pt, #1}
\begin{document}
\[
\lbox[colback=green!30]{\hat{g}} =
\sqrt{\frac{4\pi\delta}{\sigma_1((X+Y)(X-Y))^{\sigma_2}}}
\;\rbox[colframe=red]{\approx 999.121}
\]
\end{document}