A sort of 2-column grid layout, where the left column is 80% of the width and centre aligned, while the right column is left aligned.
Asked
Active
Viewed 172 times
3
-
Do the labels have to be aligned to the right margin? – Steven B. Segletes Mar 31 '16 at 19:52
-
Ideally yes, but not necessarily. I'd like the left square brackets to be in line. – jackweirdy Mar 31 '16 at 19:56
3 Answers
3
These labels are right aligned. With a nested \makebox, (when I get a chance), one can make left-aligned labels off to the right. An optional argument to \mytag sets the gap above and below the 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}
Steven B. Segletes
- 237,551
2
Here's a reproduction of the picture:
\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}
In the body of the text, using flalign* and \Cen from 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}
0
A solution with real equation tags, based on the \newtagform and \usetagform commands from mathtools, and the framed environment:
\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}
Bernard
- 271,350




