I'm trying to produce table with equally sized columns, right aligned, using math mode and tabularx
package. Everything is ok when all numbers in table are positive:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\newcolumntype{Q}{>{\hsize=0.7\hsize\raggedleft\arraybackslash$}X<{$}}
\usepackage{booktabs}
\begin{document}
\begin{table}[ht]
\begin{tabularx}{\textwidth}{*{12}{Q}}
\toprule
V1 & V2 & V3 & V4 & V5 & V6 & V7 & V8 & V9 & V10 & V11 & V12 \\
\midrule
5.93 & 4.53 & 5.62 & 4.82 & 5.12 & 4.97 & 4.64 & 5.43 & 4.97 & 5.51 & 5.21 & 5.14 \\
4.32 & 4.47 & 6.02 & 5.35 & 5.61 & 5.32 & 5.76 & 4.95 & 4.12 & 4.00 & 4.98 & 5.51 \\
5.01 & 4.78 & 5.65 & 4.95 & 4.33 & 5.67 & 5.19 & 5.31 & 5.05 & 4.79 & 3.77 & 5.41 \\
5.62 & 5.17 & 5.38 & 4.37 & 5.33 & 5.00 & 3.97 & 5.48 & 4.71 & 5.06 & 6.29 & 4.90 \\
4.64 & 3.99 & 4.14 & 5.84 & 4.74 & 5.51 & 4.32 & 5.84 & 4.51 & 4.55 & 4.90 & 5.19 \\
4.62 & 5.11 & 4.70 & 5.46 & 5.34 & 4.41 & 4.90 & 5.03 & 4.91 & 5.17 & 5.33 & 4.53 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
However, when I have negative numbers in my table, it does not work properly anymore:
\begin{table}[ht]
\begin{tabularx}{\textwidth}{*{12}{Q}}
\toprule
V1 & V2 & V3 & V4 & V5 & V6 & V7 & V8 & V9 & V10 & V11 & V12 \\
\midrule
-0.36 & 1.96 & -0.18 & 1.50 & -0.66 & 1.60 & -0.52 & -0.13 & 0.68 & 0.43 & 0.12 & 1.17 \\
0.06 & -0.09 & 0.42 & -1.14 & 0.49 & -0.09 & -0.49 & -1.76 & -1.40 & 0.02 & 0.13 & 1.05 \\
-0.70 & 0.21 & 0.32 & -0.18 & -0.38 & 1.08 & 0.05 & -0.39 & 0.85 & -1.67 & 0.22 & 1.15 \\
-0.72 & -0.74 & -0.78 & 1.90 & -0.56 & 0.63 & 1.30 & 0.09 & -0.45 & 0.74 & 1.64 & -0.58 \\
0.88 & -0.57 & -0.79 & -0.10 & -0.34 & -0.11 & 2.29 & 0.85 & 0.17 & 0.39 & -0.22 & 2.00 \\
-1.02 & -1.32 & -0.50 & -1.36 & 0.09 & -1.53 & 1.55 & 0.96 & 0.07 & -0.27 & 0.17 & 0.07 \\
\bottomrule
\end{tabularx}
\end{table}
How can I fix this?
\raggedright
means left aligned, look at all the minus' they all left align with the contents just as you asked for. Instead if this construction I'd probably use the S column fromsiunitx
with the proper column configuration.\newcolumntype{R}{>{$}r<{$}}
and used tabular, or tabular*.