Aligning complex numbers in centre of table with siunitx

Now that we know that complex numbers are not fully supported by the siunitx package, here is a workaround that adapts DrJay's solution and uses the collcell package to automate the formatting of the number in that the integer real part is right aligned so that the + sign is aligned:

enter image description here

Notes:

  • The real part is currently right aligned -- could be enhanced to align on the decimal point. Let me know if this is required.
  • The imaginary part is left aligned. This could also be adjusted as needed.

Code:

\documentclass[a4paper]{article}

\usepackage{booktabs}
\usepackage{array}
\usepackage{siunitx}
\usepackage{xstring}
\usepackage{collcell}

\sisetup{
    output-complex-root = \ensuremath{\mathrm{j}},
    complex-root-position = before-number
}

\newlength{\WidestRealNum}
\settowidth{\WidestRealNum}{$99999$}
\newcommand*{\ApplyNumFormatting}[1]{%
    \StrBefore{#1}{+}[\RealPart]%
    \StrBehind{#1}{j}[\ImagPart]%
    $\makebox[\WidestRealNum][r]{$\RealPart$} + j\,\ImagPart$%
}%
\newcolumntype{N}{>{\collectcell\ApplyNumFormatting}l<{\endcollectcell}}

\begin{document}
\begin{table}[h!]
    \caption{Bus Loads}
    \label{fig:figurename}
    \centering
        \begin{tabular}{l|N}
        \toprule
        \textbf{Bus} & \multicolumn{1}{c}{\textbf{Bus Load (MVA)}} \\
        \midrule
            b1 &  50 + j 30.99 \\
            b2 & 170 + j105.35\\
            b3 & 200 + j123.94 \\
            b4 & 150 + j49.58 \\
        \bottomrule
        \end{tabular}
\end{table}
\end{document}

The siunitx package is primarily focussed on physical quantities (numbers with units). As such, the first version did not even cover complex numbers. For version 2 I was asked to add them as they crop up for example in some parts of electronics. However, as this is a relatively unusual situation, support for complex numbers is somewhat limited, and in particular the functionality for numbers with real plus complex parts is not complete. One reason for this, apart from code complexity, is maintaining reasonable performance for the most common cases: the more situations you cover, the more tests and so on are required.

In the case of numbers in tables, the real and complex parts would to me naturally form two separate columns

\documentclass[a4paper]{article}

\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{lS[table-format = 3]S[table-format = 3.2]}
\toprule
  \textbf{Bus} & \multicolumn{2}{c}{\textbf{Bus Load (MVA)}} \\
               & {Real} & {Complex} \\
  \midrule
  b1 &  50 &  30.99 \\
  b2 & 170 & 105.35 \\
  b3 & 200 & 123.94 \\
  b4 & 150 &  49.58 \\
  \bottomrule
\end{tabular}
\end{document}

as this removes the redundant + and j in each value.

That said, I am always willing to consider extensions to siunitx, particularly if the requests come with a link demonstrating use of the requested format in the published literature. Please feel free to open an issue in the tracker.