This is potentially a very noob question, but how could one use multiple conditions when parsing with xstring?
The accepted answer that I'm linking below, shows how one can align complex numbers in a table.
https://tex.stackexchange.com/a/83639/118726
I want the complex numbers to be allowed to be of the form a+ib but also a-ib.
I need to modify the line
\StrBefore{#1}{+}[\RealPart]%
to look for the string before + OR -.
Any ideas?
MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{xstring}
\usepackage{collcell}
\sisetup{
output-complex-root = \ensuremath{\mathrm{i}},
complex-root-position = before-number
}
\newlength{\WidestRealNum}
\settowidth{\WidestRealNum}{$99999$}
\newcommand*{\ApplyNumFormatting}[1]{%
\StrBefore{#1}{+}[\RealPart]%
\StrBehind{#1}{i}[\ImagPart]%
$\makebox[\WidestRealNum][r]{$\RealPart$} + i\,\ImagPart$%
}%
\newcolumntype{N}{>{\collectcell\ApplyNumFormatting}l<{\endcollectcell}}
\begin{document}
\begin{table}
\caption{Some complex numbers }
\label{table:Fhkl}
\centering
\begin{tabular}{ N S[]}
\toprule
\multicolumn{1}{c}{N column } & \multicolumn{1}{c}{S[] column}\\
\midrule
-774.66 - i 325.61 & -774.66 - i 325.61 \\
774.66 - i 325.61 & 774.66 - i 325.61 \\
-151.85 + i 325.61 & -151.85 + i 325.61 \\
151.85 + i 325.61 & 151.85 + i 325.61 \\
\bottomrule
\end{tabular}
\end{table}
%
\end{document}
The S[] type is indeed a solution but I do prefer the center alignment of the sign. You can see below the N format as it is now fails for anything other than a+ib or -a+ib.


Scolumn added bysiunitx? It is good that you linked the answer, but it would've been better if you posted a minimal working example (MWE). – Skillmon Sep 01 '18 at 13:13listofitemspackage can parse based on multiple separators (e.g.,\setsepchar{+||-}). Not sure if it can be leveraged for your app. – Steven B. Segletes Sep 01 '18 at 15:42