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:
- Is there a way in LaTeX or through a package which I can automate the addition of
\phantom{-}
? - Do you know of a better way to get the kind of alignment of fractions I'm looking for?
\+
?) to handle \phantom{-}.\phantom{-}
is far less complicated than creating a macro for this, IMHO.