2

I have some tables of numbers, most of which are small (0, 1, -1), but occasionally I have fractions. If I just has 0, 1, -1's I'd right align so the $-$ signs will line up, but the fractions throw things off. Center align doesn't look great either, nor does left align. Here is a small example of a right and center align: tables

\begin{tabular}{rr}
$\frac 1{24}$ & $-\frac 1{24}$ \\
$1$ & $-1$ \\
$-1$ & $0$ \\
\end{tabular}
\quad
\begin{tabular}{cc}
$\frac 1{24}$ & $-\frac 1{24}$ \\
$1$ & $-1$ \\
$-1$ & $0$ \\
\end{tabular}

Can I center align the numbers without the signs, so the top two rows will look like they do on the right in the example above, and the bottom two rows will look like the do on the left in the above example?

3

Here I make - active (inside a limited group) and define it as a \mathllap. I use a TABstack with enough column separation to allow for the -.

\documentclass{article}
\usepackage{tabstackengine,mathtools}
\TABstackMath
\begin{document}
\bgroup
\setstackgap{L}{16pt}
\setstacktabbedgap{13pt}
\let\svm-
\catcode`-=\active
\def-{\mathllap{\svm}}
\Matrixstack{\frac 1{24} & -\frac 1{24} \\ 1 & -1 \\ -1 & 0}
\quad\Matrixstack{\frac 1{24} & -\frac 1{24} \\ 1 & -1 \\ -1 & 0 }
\egroup
\end{document}

enter image description here

3

With \phantom you can insert an invisible -:

enter image description here

\documentclass{article}

\begin{document}
\begin{tabular}{cc}
$\phantom{-}\frac 1{24}$ & $-\frac 1{24}$ \\
$\phantom{-}1$ & $-1$ \\
$-1$ & $\phantom{-}0$ \\
\end{tabular}
\end{document}

If your table contains only (mostly) math, you might want to use array instead of tabular.

  • Thanks for your answer. It's a good "local" solution for a small number of table entries, but since I can only accept one answer, I am accepting the answer with the more "global" approach that scales better. – Kimball Apr 17 at 23:27
3

enter image description here

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{tabular}{cc}
$\frac 1{24}$ & $\mathllap-\frac 1{24}$ \\
$1$ & $\mathllap-1$ \\
$\mathllap-1$ & $0$ \\
\end{tabular}

\end{document}
  • Thanks for your answer. It's a good "local" solution for a small number of table entries, but since I can only accept one answer, I am accepting the answer with the more "global" approach that scales better. – Kimball Apr 17 at 23:28

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.