0

I am trying to typeset a type derivation tree.

% \usepackage{amsmath}
% \usepackage{amssymb}
\newcommand*{\stext}[1]{\text{ #1 }}
\newcommand*{\sd}[1]{\rule[-#1]{\textwidth}{0.4pt}}


\begin{align*}
    T \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y): num \rightarrow num \rightarrow num \qquad & T \vartriangleright{} 1 : num \sd{2ex} \\
    T \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y)\, 1: num \rightarrow num \rightarrow num \qquad & T \vartriangleright{} 5 : num \sd{2ex} \\
    T \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y)\, 1\enskip 5: num \rightarrow num \rightarrow num
\end{align*}      

The result does not look good:

line alignment wrong

What I actually want is something like this:

enter image description here

Note that:

  1. The bottom line is centered with respect to the other lines in the environment

  2. The horizontal dividing lines are nicely spaced (veritcally), start on the LHS and are the correct width

I've also tried an approach using \hline, but the spacing is unacceptable:

enter image description here

\newcommand*{\sd}{\hline}
\begin{align*}
    T \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y): num \rightarrow num \rightarrow num \qquad & T \vartriangleright{} 1 : num \\ \sd
    T \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y)\, 1: num \rightarrow num \rightarrow num \qquad & T \vartriangleright{} 5 : num \\ \sd
    T \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y)\, 1\enskip 5: num \rightarrow num \rightarrow num
\end{align*}

Is there a better approach? Is align even the correct environment to use here?

  • Since align is defined in amsmath, this isn't going to work at all with that package commented out. – barbara beeton May 12 '19 at 22:41
  • Yes, indeed :P I figured it was fairly obvious that was supposed to go in the preamble, though! – Adam Williams May 13 '19 at 15:50
1

How about you change your \sd command to \newcommand*{\sd}{\\[-10pt]\hline\\[-10pt]}?

Output

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}
\newcommand*{\sd}{\\[-10pt]\hline\\[-10pt]}
\begin{align*}
    T \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y): num \rightarrow num \rightarrow num \qquad & T \vartriangleright{} 1 : num \\ \sd
    T \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y)\, 1: num \rightarrow num \rightarrow num \qquad & T \vartriangleright{} 5 : num \\ \sd
    T \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y)\, 1\enskip 5: num \rightarrow num \rightarrow num
\end{align*}

\end{document}
  • Can you explain why this works? I thought the \\ argument specified additional extra space before the next line, so why is it negative in this case? – Adam Williams May 12 '19 at 20:03
  • 2
    Sure, so the \\ will create some space and the [-10pt] will take away from that space 10pt. Basically, you make too much extra space and then take away 10pt from it. – M. Al Jumaily May 12 '19 at 20:11
  • Ah, of course - that makes a lot of sense! – Adam Williams May 12 '19 at 20:17
2

How about this solution based on booktabs?

\documentclass{report}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{booktabs}

\begin{document}

\begin{align*}
    T & \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y): num \rightarrow num \rightarrow num & \quad & T \vartriangleright{} 1 : \\[-1.5ex]
    \cmidrule{1-4}
    T & \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y)\, 1: num \rightarrow num \rightarrow num & \quad & T \vartriangleright{} 5 : \\[-1.5ex]
    \cmidrule{1-4}
    T & \vartriangleright{} (\lambda x: num.\, \lambda y: num.\, x+y)\, 1\enskip 5: num \rightarrow num \rightarrow num
\end{align*}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.