Multiple alignment points in equations and no curly brackets for correcting spacing

Consider the following example:

\documentclass{article}

\usepackage{amsmath}
\usepackage{siunitx}

\begin{document}

\begin{alignat*}{5}
&&\frac{\SI{16710}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{\num{16710} \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx{} &\SI{182}{\degree}&;\\
&\text{Pollen:}
&&\frac{\SI{10155}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{\num{10155} \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx{} &\SI{111}{\degree}&;\\
&\text{Vand:}
&&\frac{\SI{6210}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{6210 \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx{} &\SI{68}{\degree}&.
\end{alignat*}

\end{document}


Is it possible to get the same alignment and spacing without putting {} after \approx?

Update

After simplifying Werner's answer even further, I've come up with the following solution:

\documentclass{article}

\usepackage{amsmath}
\usepackage{siunitx}

\ExplSyntaxOn
\cs_new_eq:NN \calculate \fp_eval:n
\ExplSyntaxOff

\newcommand*\pieSlice[1]{%
\dfrac{\SI{#1}{\g}}{\SI{\total}{\g}} \cdot \SI{360}{\degree}
& {\mkern -3mu}\biggl(\dfrac{\num{#1} \cdot 360}{\num{\total}}\biggr){\mkern -3mu} \si{\degree}
& \calculate{round(#1*360/\total)} \si{\degree}
&
}
\newcommand*\total{\calculate{\honning+\pollen+\vand}}

\begin{document}

\begin{equation*}
\def\honning{16710}
\def\pollen{10155}
\def\vand{6210}
\renewcommand*\arraystretch{2.2}
\text{Honning:} & \pieSlice{\honning}; \\
\text{Pollen:}  & \pieSlice{\pollen}; \\
\text{Vand:}    & \pieSlice{\vand}.
\end{array}
\end{equation*}

\end{document}

-
Define \newcommand{\Approx}{{}\approx{}} and then use \Approx instead of \approx. :-) – Peter Grill Feb 12 '14 at 19:52
@PeterGrill That is cheating :) and them I'm still using {}. – Svend Tveskæg Feb 12 '14 at 19:54
Is there anything wrong with using {}? What if the answer is no? – Werner Feb 12 '14 at 19:57
@Werner There's nothing wrong with it at all. I was just hoping that it would be possible in order to simplify the code as much as possible. – Svend Tveskæg Feb 12 '14 at 19:58

Since the construction is consistent and doesn't require numbering, you can define a macro to handle each row, constructing an array as needed:

\documentclass{article}

\usepackage{amsmath,siunitx}
\ExplSyntaxOn
\newcommand{\calculation}[2]{% \calculation{<num>}{<denom>}
\dfrac{\SI{#1}{\g}}{\SI{#2}{\g}} \cdot \SI{360}{\degree}
& \biggl( \dfrac{\num{#1} \cdot 360}{\num{#2}} \biggr) \si{\degree}
& \fp_eval:n {round(#1 * 360 / #2)} \si{\degree}
&
}
\ExplSyntaxOff

\begin{document}

$\renewcommand{\arraystretch}{2.1} \begin{array}{l@{\qquad}l@{{}={}}l@{{}\approx{}}r@{}l} \text{Honning:} & \calculation{16710}{33075}; \\ \text{Pollen:} & \calculation{10155}{33075}; \\ \text{Vand:} & \calculation{6210}{33075}. \end{array}$

\end{document}


Apart from the column specification (which handles the spacing; and could be modified), the code is probably better to read. Of course, it could be simplified even further.

-
I really like this solution! You say it can be simplified even further; can I make you do that? :) – Svend Tveskæg Feb 12 '14 at 20:34
@SvendTveskæg: One simplification I've added is to calculate <answer> using l3fp (which is loaded indirectly by siunitx). I've used round. – Werner Feb 12 '14 at 20:48

If you remove the & following the \approx, here are two ways you can achieve the desired result:

1. Add a \phantom{1} for the last case to right align it.
2. Define a custom MySI which uses \makebox to make sure that the text is right aligned within the appropriate width.

Code: \phantom:

\documentclass{article}

\usepackage{amsmath}
\usepackage{siunitx}

\begin{document}

\begin{alignat*}{5}
&&\frac{\SI{16710}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{\num{16710} \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx \SI{182}{\degree}&;\\
&\text{Pollen:}
&&\frac{\SI{10155}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{\num{10155} \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx \SI{111}{\degree}&;\\
&\text{Vand:}
&&\frac{\SI{6210}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{6210 \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx \phantom{1}\SI{68}{\degree}&.
\end{alignat*}


Code: \MySI:

\documentclass{article}

\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{calc}

\newcommand*{\MySI}[2]{\makebox[\widthof{\SI{999}{#2}}][r]{\SI{#1}{#2}}}%

\begin{document}

\begin{alignat*}{5}
&&\frac{\SI{16710}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{\num{16710} \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx \MySI{182}{\degree};\\
&\text{Pollen:}
&&\frac{\SI{10155}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{\num{10155} \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx \MySI{111}{\degree};\\
&\text{Vand:}
&&\frac{\SI{6210}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{6210 \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx \MySI{68}{\degree}.
\end{alignat*}

\end{document}

-
My 'problem' with this is (a) that one should use 2n-1 &'s for n & (I think) and (b) the \phantom{1} 'gets rit of' the simplicity, I think. – Svend Tveskæg Feb 12 '14 at 20:01
Much better using {}, I think... – karlkoeller Feb 12 '14 at 20:02
@SvendTveskæg: Ok, how about the revised solution where you don't need to manually add a \phantom{1} spacing? – Peter Grill Feb 12 '14 at 20:12
A nice try but I'm really fond of this. If no one comes up with a solution involving just the initial code without the curly braces, I'll accept your answer later today. – Svend Tveskæg Feb 12 '14 at 20:23

This answer replaces the \alignat with a \alignShortstack from the just released tabstackengine package (may or may not have propagated to a CTAN mirror near you).

The good news: 1) the approx does not need a {}; and 2) the result looks the same

The bad news: 1) it runs very slow (I am not sure why); and 2) the lone \qquad needs a {} (I am not sure why).

EDITED because I can use it in \centering situations (by changing the EOL character from \\ to, for example, \#)

\documentclass{article}
\usepackage{siunitx}
\usepackage{tabstackengine}
\stackMath
\makeatletter
\newcommand\TABstackDisplay{\renewcommand\TAB@delim[1]{\displaystyle##1}}
\makeatother
\TABstackDisplay
\setstackaligngap{0ex}
\setstackgap{S}{4pt}
\setstackEOL{\#}
\begin{document}
{\centering
\alignShortstack{
&&\frac{\SI{16710}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{\num{16710} \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx &\SI{182}{\degree}&;\#
&\text{Pollen:}
&&\frac{\SI{10155}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{\num{10155} \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx &\SI{111}{\degree}&;\#
&\text{Vand:}
&&\frac{\SI{6210}{\g}}{\SI{33075}{\g}} \cdot \SI{360}{\degree}
&&= {\mkern -6mu}\left(\frac{6210 \cdot 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx &\SI{68}{\degree}&.
}
}
\end{document}

-

A solution with only 3 alignment points and one pair of braces (as a spacing argument of the alignat* environment – first line):

\documentclass[12pt]{article}

\usepackage{mathtools}
\usepackage{siunitx}

\begin{document}

\begin{alignat*}{3}
&\frac{\SI{16710}{\g}}{\SI{33075}{\g}}  · \SI{360}{\degree}
&= {\mkern -6mu}\left(\frac{\num{16710}  · 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&{}&\approx {} \SI{182}{\degree};\\
&  \text{Pollen:}
&\frac{\SI{10155}{\g}}{\SI{33075}{\g}}  · \SI{360}{\degree}
&= {\mkern -6mu}\left(\frac{\num{10155}  · 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
& & \approx{} \SI{111}{\degree};\\
&  \text{Vand:}
& \frac{\SI{6210}{\g}}{\SI{33075}{\g}}  · \SI{360}{\degree}
&= {\mkern -6mu}\left(\frac{6210  · 360}{\num{33075}}\right){\mkern -6mu}\,\si{\degree}
&&\approx{} \SI{68}{\degree} .
\end{alignat*}

\end{document}


Resulting in:

If you prefer the last series of units to be right aligned, just add a \hphantom{0} in front of  \SIunit{68}:

-
This is all good but I need five alignment points. :) The output is also not as I would like. – Svend Tveskæg Feb 12 '14 at 21:45
@SvendTveskæg: your picture describing your problem doesn't require 5 points, but only 3. I suppose you have other requirements; could you explain? – Bernard Feb 12 '14 at 21:58
Alignment points: At the first text, at the first numbers, at the =, at the \approx and at the \degree. – Svend Tveskæg Feb 12 '14 at 22:08
I still don't understand: for me, I produced the same picture as yours, with only 3 points of alignment points and a \hphantom. The first numbers will be aligned on the right side by definition, and they will be on their left side because the have the same size. The final degrees will be aligned because of the \hphantom. So what did I miss? – Bernard Feb 12 '14 at 22:41
I don't know how to say it differently. Never mind; I appreciate your try. :) – Svend Tveskæg Feb 12 '14 at 22:48