Math & ScienceAlignment glitch with siunitx numbers

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

Alignment glitch with siunitx numbers

Post by Cham »

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

Code: Select all

\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
numbers.jpg (22.66 KiB) Viewed 4789 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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

Alignment glitch with siunitx numbers

Post by mas »

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.

Code: Select all

\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
x.png (6.93 KiB) Viewed 4778 times

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Alignment glitch with siunitx numbers

Post by Cham »

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: 10359
Joined: Mon Mar 10, 2008 9:44 pm

Alignment glitch with siunitx numbers

Post by Stefan Kottwitz »

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
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Alignment glitch with siunitx numbers

Post by Cham »

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