## LaTeX forum ⇒ Math & Science ⇒ Alignment glitch with siunitx numbers

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Cham
Posts: 816
Joined: Sat Apr 02, 2011 4:06 pm

### Alignment glitch with siunitx numbers

In the following MWE example, I would like to align all the numbers with their \pm symbol :

\documentclass[10pt,letterpaper]{book}\usepackage{lmodern}\usepackage{amsmath}\usepackage[separate-uncertainty=true]{siunitx}\sisetup{output-decimal-marker = {,}}\usepackage{icomma}\usepackage{tensor} \begin{document} 	\begin{alignat*}{2}		\tensor{\mathcal{N}}{_1} &= \SI{0,03+-0,04}{\mA}, \\		\tensor{\mathcal{N}}{_2} &= \SI{-0,02+-0,05}{\mA}, \\		\tensor{\mathcal{N}}{_3} &= \SI{0,01+-0,02}{\mA}, \\		\tensor{\mathcal{N}}{_4} &= \SI{-0,04+-0,03}{\mA}, \\		\tensor{\mathcal{M}}{_1} &= \SI{0,003+-0,004}{\V}, \\		\tensor{\mathcal{M}}{_2} &= \SI{0,06+-0,09}{\V}, \\		\tensor{\mathcal{M}}{_3} &= \SI{-0,08+-0,05}{\V}.	\end{alignat*} \end{document}

Preview of what this code is doing :
numbers.jpg (22.66 KiB) Viewed 380 times

How can I align the numbers on their +- sign (red line) ? I tried adding commands like [cmd]\phantom{-}[/cmd], but it doesn't work well.

mas
Posts: 203
Joined: Thu Dec 04, 2008 4:39 am
Are you articular about using {alignat}? I feel {tabular} with siunitx would better serve you.

Using {alignat}, I split the quantities into more columns which gives what you want.
\documentclass[10pt,letterpaper]{book}\usepackage{lmodern}\usepackage{amsmath}\usepackage[separate-uncertainty=true]{siunitx}\sisetup{output-decimal-marker = {,}}\usepackage{icomma}\usepackage{tensor} \begin{document} \begin{alignat*}{4}  \tensor{\mathcal{N}}{_1} &= &\num{ 0,03} &\,\pm\,& &\SI{0,04}{\mA}, \\  \tensor{\mathcal{N}}{_2} &= &\num{-0,02} &\,\pm\,& &\SI{0,05}{\mA}, \\  \tensor{\mathcal{N}}{_3} &= &\num{ 0,01} &\,\pm\,& &\SI{0,02}{\mA}, \\  \tensor{\mathcal{N}}{_4} &= &\num{-0,04} &\,\pm\,& &\SI{0,03}{\mA}, \\  \tensor{\mathcal{M}}{_1} &= &\num{0,003} &\,\pm\,& &\SI{0,004}{\V}, \\  \tensor{\mathcal{M}}{_2} &= &\num{ 0,06} &\,\pm\,& &\SI{0,09}{\V}, \\  \tensor{\mathcal{M}}{_3} &= &\num{-0,08} &\,\pm\,& &\SI{0,05}{\V}.\end{alignat*} \end{document}

The output
x.png (6.93 KiB) Viewed 369 times

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

Cham
Posts: 816
Joined: Sat Apr 02, 2011 4:06 pm
Hmm, the spacings are looking a bit weird. Maybe I should align the units instead of the +- ? Or the commas of the first values (not their uncertainty)?? How should I do this ?

Stefan Kottwitz
Posts: 8529
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
I would align at relations, operators, and the decimal point (or fill up with zeroes at the right and align the numbers at the right then).

Stefan