# Improving alignment of signed fractions in table

I would like to find a way to better align signed fractions in a table. Take the following example:

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\begin{tabular}{rr} \toprule
$\alpha$ & $\beta$ \\ \midrule
$-\frac{9}{2}$ & $-\frac{1}{6}$ \\[0.8ex]
$-\frac{7}{2}$ & $\frac{1}{30}$ \\[0.5ex]
\bottomrule
\end{tabular}
\end{table}

\end{document}


This gives:

I don't like the look of the second column, which I think would look better if 1/30 would be centrally aligned with 1/6. By playing around, I noticed that changing the type of the second column to c and adding a \phantom{-} in front of 1/30, i.e.,

\begin{table}
\centering
\begin{tabular}{rc} \toprule
$\alpha$ & $\beta$ \\ \midrule
$-\frac{9}{2}$ & $-\frac{1}{6}$ \\[0.8ex]
$-\frac{7}{2}$ & $\phantom{-}\frac{1}{30}$ \\[0.8ex]
\bottomrule
\end{tabular}
\end{table}


I get what I think is a much better looking result:

This, however, requires that I manually add the \phantom{-} command for every positive entry in my tables: I want to avoid this because the tables are large. So I have two questions:

1. Is there a way in LaTeX or through a package which I can automate the addition of \phantom{-}?
2. Do you know of a better way to get the kind of alignment of fractions I'm looking for?
• What should be done if an entire column consists of positive numbers? – Mico Dec 30 '18 at 14:09
• Well, for positive numbers no change in alignment is necessary, so nothing needs to be done. – user1362373 Dec 30 '18 at 14:11
• You could put the negative signs into a separate column, or create a new command (\+ ?) to handle \phantom{-}. – John Kormylo Dec 30 '18 at 15:20
• Adding \phantom{-} is far less complicated than creating a macro for this, IMHO. – AboAmmar Dec 30 '18 at 15:54
• the main problem here is that math fonts should have a minus sign as binary operator and a minus sign (shorter, more like an hyphen) for negative numbers; sadly the two are typeset the same and it is ugly (despite the fact nobody complains, but life is a path of solitude if you seek enlightenment) – user4686 Dec 30 '18 at 22:17

I don't think there's anything wrong with standard center alignment. Consider the case where you have -1/6 and -1/30: if you center align the fractions, the minus signs will be off.

I can offer a new column type for the columns with negative entries.

\documentclass{article}
\usepackage{amsmath,mathtools}
\usepackage{booktabs,array,calc}

\newcolumntype{n}{@{\hspace{\dimexpr\fontcharwd\textfont2 0+\arraycolsep}}c}
\newcommand{\?}{\mathllap{-}}
\newcommand{\mcn}[1]{%
\multicolumn{1}{c}{\kern-\fontcharwd\textfont2 0 #1}%
}

\begin{document}

\begin{table}
\centering

$\begin{array}{nnc} \toprule \mcn{\alpha} & \mcn{\beta} & \gamma \\ \midrule \?\frac{9}{2} & \?\frac{1}{6} & 2 \\[0.8ex] \?\frac{7}{2} & \frac{1}{30} & 3 \\[0.5ex] \bottomrule \end{array}$

\end{table}

\end{document}