答案1
以下是该图片的复制版:
\documentclass{article}
\usepackage{amsmath,array,booktabs}
\newcommand{\hmtag}[2][hm]{[\textsc{#2}]_{\textsc{#1}}}
\newcommand{\entails}[1][hm]{\vdash_{\textsc{#1}}}
\newcommand{\hmcolon}{{\mspace{2mu}:\mspace{2mu}}}
\begin{document}
\begin{figure}
\centering
\fbox{%
$\begin{array}{>{\displaystyle}cl}
\addlinespace[2ex]
\frac{\tau\prec\Gamma(x)}{\Gamma\entails x\hmcolon\tau} & \hmtag{Var}
\\ \addlinespace[3ex]
\frac{\Gamma\entails e_1\hmcolon\tau_1\to\tau_2\quad \Gamma\entails e_2\hmcolon\tau_1}
{\Gamma\entails e_1\ e_2\hmcolon\tau_2} & \hmtag{App}
\\ \addlinespace[3ex]
\frac{\Gamma\backslash x\cup\{x\hmcolon\tau_1\} \entails e\hmcolon\tau_2}
{\Gamma\entails \lambda x\to e_1\hmcolon\tau_1\to\tau_2} & \hmtag{Abs}
\\ \addlinespace[3ex]
\frac{\Gamma\entails e_1\hmcolon\tau_1 \quad
\Gamma\backslash x\cup\{x\colon\textit{generalize}(\Gamma,\tau_1)\}
\entails e_2\hmcolon\tau_2}
{\Gamma\entails\textbf{let $x=e_1$ in $e_2\hmcolon\tau_2$}} & \hmtag{Let}
\\ \addlinespace[2ex]
\end{array}$%
}
\caption{Hindley-Milner type inference rules}
\end{figure}
\end{document}
在正文中,使用flalign*
和\Cen
来自https://tex.stackexchange.com/a/209732/4427
\documentclass{article}
\usepackage{amsmath,array,booktabs}
\usepackage{lipsum} % just for the example
\newcommand{\hmtag}[2][hm]{[\textsc{#2}]_{\textsc{#1}}}
\newcommand{\entails}[1][hm]{\vdash_{\textsc{#1}}}
\newcommand{\hmcolon}{{\mspace{2mu}:\mspace{2mu}}}
\makeatletter
\newcommand{\Cen}[2]{%
\ifmeasuring@
#2%
\else
\makebox[\ifcase\expandafter #1\maxcolumn@widths\fi]{$\displaystyle#2$}%
\fi
}
\makeatother
\begin{document}
\lipsum*[2]
\begin{flalign*}
&&\Cen{3}{
\frac{\tau\prec\Gamma(x)}{\Gamma\entails x\hmcolon\tau}
} &&& \hmtag{Var}
\\
&&\Cen{3}{
\frac{\Gamma\entails e_1\hmcolon\tau_1\to\tau_2\quad \Gamma\entails e_2\hmcolon\tau_1}
{\Gamma\entails e_1\ e_2\hmcolon\tau_2}
} &&& \hmtag{App}
\\
&&\Cen{3}{
\frac{\Gamma\backslash x\cup\{x\hmcolon\tau_1\} \entails e\hmcolon\tau_2}
{\Gamma\entails \lambda x\to e_1\hmcolon\tau_1\to\tau_2}
} &&& \hmtag{Abs}
\\
&&\Cen{3}{
\frac{\Gamma\entails e_1\hmcolon\tau_1 \quad
\Gamma\backslash x\cup\{x\colon\textit{generalize}(\Gamma,\tau_1)\}
\entails e_2\hmcolon\tau_2}
{\Gamma\entails\textbf{let $x=e_1$ in $e_2\hmcolon\tau_2$}}
} &&& \hmtag{Let}
\end{flalign*}
\lipsum[3]
\begin{figure}
\centering
\fbox{%
$\begin{array}{>{\displaystyle}cl}
\addlinespace[2ex]
\frac{\tau\prec\Gamma(x)}{\Gamma\entails x\hmcolon\tau} &\hmtag{Var}
\\ \addlinespace[3ex]
\frac{\Gamma\entails e_1\hmcolon\tau_1\to\tau_2\quad \Gamma\entails e_2\hmcolon\tau_1}
{\Gamma\entails e_1\ e_2\hmcolon\tau_2} &\hmtag{App}
\\ \addlinespace[3ex]
\frac{\Gamma\backslash x\cup\{x\hmcolon\tau_1\} \entails e\hmcolon\tau_2}
{\Gamma\entails \lambda x\to e_1\hmcolon\tau_1\to\tau_2} &\hmtag{Abs}
\\ \addlinespace[3ex]
\frac{\Gamma\entails e_1\hmcolon\tau_1 \quad
\Gamma\backslash x\cup\{x\colon\textit{generalize}(\Gamma,\tau_1)\}
\entails e_2\hmcolon\tau_2}
{\Gamma\entails\textbf{let $x=e_1$ in $e_2\hmcolon\tau_2$}} &\hmtag{Let}
\\ \addlinespace[2ex]
\end{array}$%
}
\caption{Hindley-Milner type inference rules}
\end{figure}
\end{document}
答案2
这些标签是右对齐的。使用嵌套的\makebox
,(当我有机会时),可以将左对齐的标签移到右侧。可选参数\mytag
设置 上方和下方的间隙equation*
。
\documentclass{article}
\usepackage{stackengine,amsmath,lipsum}
\stackMath
\newcommand\mytag[3][2pt]{%
\renewcommand\useanchorwidth{T}
\renewcommand\stacktype{L}
\addstackgap[#1]{\stackon[0pt]{\displaystyle#2}{\makebox[\textwidth][r]{#3}}}
}
\begin{document}
\lipsum[3]
\begin{equation*}
\mytag{\min_{x_{ij},\delta_i} \sum_{i=1}^m (P_i^{svr} + P_i^{cool})}
{$\text{[VAR]}_\text{HM}$}
\end{equation*}
\begin{equation*}
\mytag{E = \frac{1}{n!}mc^2}
{$\text{[APP]}_\text{HM}$}
\end{equation*}
\begin{equation*}
\mytag{y = \frac{Ax^2 + Bx + C}{x - a}}
{$\text{[ABS]}_\text{HM}$}
\end{equation*}
\begin{equation*}
\mytag{y = mx + b}
{$\text{[LET]}_\text{HM}$}
\end{equation*}
\lipsum[2]
\end{document}
答案3
\newtagform
基于的和\usetagform
命令mathtools
以及环境,具有实数方程标签的解决方案framed
:
\documentclass{article}
\usepackage{mathtools, caption, eqparbox, framed}
\newtagform{hmstring}[\scshape\eqparbox{HM}]{[}{\textsubscript{hm}]}
\usepackage[x11names]{xcolor} \colorlet{framecolor}{OrangeRed3}
\def\FrameCommand{\fboxrule=2\FrameRule\fboxsep=0\FrameSep \fcolorbox{framecolor}{white}}%
\usepackage[showframe]{geometry} \newcommand{\entails}[1][hm]{\vdash_{\textsc{#1}}}
\newcommand{\hmcolon}{{\mspace{2mu}:\mspace{2mu}}}
\begin{document}
\begin{framed}
\usetagform{hmstring}
\begin{gather}
\frac{\tau\prec\Gamma(x)}{\Gamma\entails x\hmcolon\tau} \tag{Var}\label{var}
\\[2ex]
\frac{\Gamma\entails e_1\hmcolon\tau_1\to\tau_2\quad \Gamma\entails e_2\hmcolon\tau_1}
{\Gamma\entails e_1\ e_2\hmcolon\tau_2} \tag{App}
\\[2ex]
\frac{\Gamma\backslash x\cup\{x\hmcolon\tau_1\} \entails e\hmcolon\tau_2}
{\Gamma\entails \lambda x\to e_1\hmcolon\tau_1\to\tau_2}\tag{Abs}
\\[2ex] \frac{\Gamma\entails e_1\hmcolon\tau_1 \quad
\Gamma\backslash x\cup\{x\colon\textit{generalize}(\Gamma,\tau_1)\}
\entails e_2\hmcolon\tau_2}
{\Gamma\entails\textbf{let $x=e_1$ in $e_2\hmcolon\tau_2$}} \tag{Let}
\end{gather}
\end{framed}%
\captionof{figure}{Hindley-Milner type inference rules}
\end{document}