LaTeX forum ⇒ Math & ScienceAlignment glitch with siunitx numbers

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

Alignment glitch with siunitx numbers

Postby Cham » Sun Oct 01, 2017 5:20 pm

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

  1. \documentclass[10pt,letterpaper]{book}
  2. \usepackage{lmodern}
  3. \usepackage{amsmath}
  4. \usepackage[separate-uncertainty=true]{siunitx}
  5. \sisetup{output-decimal-marker = {,}}
  6. \usepackage{icomma}
  7. \usepackage{tensor}
  8.  
  9. \begin{document}
  10.  
  11. \begin{alignat*}{2}
  12. \tensor{\mathcal{N}}{_1} &= \SI{0,03+-0,04}{\mA}, \\
  13. \tensor{\mathcal{N}}{_2} &= \SI{-0,02+-0,05}{\mA}, \\
  14. \tensor{\mathcal{N}}{_3} &= \SI{0,01+-0,02}{\mA}, \\
  15. \tensor{\mathcal{N}}{_4} &= \SI{-0,04+-0,03}{\mA}, \\
  16. \tensor{\mathcal{M}}{_1} &= \SI{0,003+-0,004}{\V}, \\
  17. \tensor{\mathcal{M}}{_2} &= \SI{0,06+-0,09}{\V}, \\
  18. \tensor{\mathcal{M}}{_3} &= \SI{-0,08+-0,05}{\V}.
  19. \end{alignat*}
  20.  
  21. \end{document}


Preview of what this code is doing :
numbers.jpg
numbers.jpg (22.66 KiB) Viewed 385 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: 204
Joined: Thu Dec 04, 2008 4:39 am

Postby mas » Mon Oct 02, 2017 4:01 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.
  1. \documentclass[10pt,letterpaper]{book}
  2. \usepackage{lmodern}
  3. \usepackage{amsmath}
  4. \usepackage[separate-uncertainty=true]{siunitx}
  5. \sisetup{output-decimal-marker = {,}}
  6. \usepackage{icomma}
  7. \usepackage{tensor}
  8.  
  9. \begin{document}
  10.  
  11. \begin{alignat*}{4}
  12. \tensor{\mathcal{N}}{_1} &= &\num{ 0,03} &\,\pm\,& &\SI{0,04}{\mA}, \\
  13. \tensor{\mathcal{N}}{_2} &= &\num{-0,02} &\,\pm\,& &\SI{0,05}{\mA}, \\
  14. \tensor{\mathcal{N}}{_3} &= &\num{ 0,01} &\,\pm\,& &\SI{0,02}{\mA}, \\
  15. \tensor{\mathcal{N}}{_4} &= &\num{-0,04} &\,\pm\,& &\SI{0,03}{\mA}, \\
  16. \tensor{\mathcal{M}}{_1} &= &\num{0,003} &\,\pm\,& &\SI{0,004}{\V}, \\
  17. \tensor{\mathcal{M}}{_2} &= &\num{ 0,06} &\,\pm\,& &\SI{0,09}{\V}, \\
  18. \tensor{\mathcal{M}}{_3} &= &\num{-0,08} &\,\pm\,& &\SI{0,05}{\V}.
  19. \end{alignat*}
  20.  
  21. \end{document}

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

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

User avatar
Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Oct 02, 2017 3:51 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 ?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8541
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Oct 02, 2017 4:44 pm

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
Site admin

User avatar
Cham
Posts: 820
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Oct 02, 2017 5:10 pm

Stefan, can you be more specific ? Your code version, please ?


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 1 guest