# Siunitx: how to deal with invalid numerical input '-'?

Thanks to you all, I found siunitx for decimal alignment. However, some of the columns in my correlation matrix don't have any numbers and have "-" instead. siunitx gives me an error about invalid numerical input. How can I get around this?

This is my code:

\documentclass[6pt]{article}
\usepackage[landscape, total={8.5in, 5.45in}, top=1.5in, bottom=1.25in, right=1.
25in, left=1.25in, centering]{geometry}
\usepackage{longtable}
\usepackage{bm}
\usepackage[table]{xcolor}
\usepackage[none]{hyphenat}
\usepackage[T1]{fontenc}
\usepackage[default]{cantarell}
\usepackage{booktabs}
\usepackage{rotating}
\usepackage{siunitx}
\usepackage{array}

\pagestyle{empty}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\arraystretch}{1.2}
\usepackage{arydshln}

% this is the column for rotated headers
\newcolumntype{R}[1]{>{\begin{turn}{90}\begin{minipage}{#1}\footnotesize}l%
<{\end{minipage}\end{turn}}%
}
\begin{document}

\begin{center}
\textbf{Tricky longtable with rotated headers for a correlation matrix}\end{center}
\setlength\LTleft{0in}
\setlength\LTright{0in}
\setlength\LTpre{-0.3cm}
\setlength\LTpost{0in}
\setlength{\tabcolsep}{8pt}
\centering

\begin{longtable}{lS[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]
S[table-format=+1.2]}

\hiderowcolors
&&\multicolumn{7}{c}{First Group}&\multicolumn{4}{c}{Second Group}\\\cmidrule(lr){3-9}\cmidrule(lr){10-13}
&\multicolumn{1}{R{2.4cm}}{Fifth blah\\loooooong blah}
&\multicolumn{1}{R{2.4cm}}{As if that \\ was not enough}
&\multicolumn{1}{R{2.4cm}}{And so it \\ keeps on going}
&\multicolumn{1}{R{2.4cm}}{When exactly \\ will this end?}
&\multicolumn{1}{R{2.4cm}}{Not exactly \\minimal is it?}
&\multicolumn{1}{R{2.4cm}}{Welcome to my\\ longtable hell}
&\multicolumn{1}{R{2.4cm}}{And this is it\\ I promise}\\
\specialrule{0.01em}{0.0em}{0em}
\specialrule{0.01em}{0.0em}{0em}
\noalign{\raggedright
\footnotesize
%Complicated legend begins
\begin{tabular}{llllllllll}
\hiderowcolors
\multicolumn{6}{l}{\textbf{LEGEND}}\\
{\cellcolor{tableShade8}$\ge$0.8}&:Very high&
{\cellcolor{tableShade2}$\le$0.19}&:Very low\\
\end{tabular}
}

\endfoot

\showrowcolors

\end{longtable}
\end{document}


As you can see, I am getting an error about the ! ! Invalid numerical input '-'. I looked at the siunitx manual and I am finding it hard to resolve this error. Any help would be most welcome! Thanks for your time.

References:

1. Question about 'dcolumn' and siunitx on tex.stackexchange

2. siunitx for bolded numbers

3. siunitx manual

• You are not using siunitx here to typeset your numbers, as they are all inside braces. To get things working properly, load the etoolbox package and \robustify\cellcolor in your preamble. Then remove all of the extra braces. You should also set table-format = -1.2, as with the settings you use the signs will not have any space reserved. – Joseph Wright Mar 9 '12 at 16:56

\documentclass[6pt]{article}
\usepackage[landscape, total={8.5in, 5.45in}, top=1.5in, bottom=1.25in, right=1.
25in, left=1.25in, centering]{geometry}
\usepackage{longtable}
\usepackage{bm}
\usepackage[table]{xcolor}
\usepackage[none]{hyphenat}
\usepackage[T1]{fontenc}
\usepackage[default]{cantarell}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{rotating}
\usepackage{siunitx}
\usepackage{array}

\pagestyle{empty}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\arraystretch}{1.2}
\usepackage{arydshln}
\usepackage{etoolbox}
\robustify\cellcolor

% this is the column for rotated headers
\newcolumntype{R}[1]{>{\begin{turn}{90}\begin{minipage}{#1}\footnotesize}l%
<{\end{minipage}\end{turn}}%
}
\begin{document}

\begin{center}
\textbf{Tricky longtable with rotated headers for a correlation matrix}\end{center}
\setlength\LTleft{0in}
\setlength\LTright{0in}
\setlength\LTpre{-0.3cm}
\setlength\LTpost{0in}
\setlength{\tabcolsep}{8pt}
\centering

\begin{longtable}{lS[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]
S[table-format=-1.2]}

\hiderowcolors
&&\multicolumn{7}{c}{First Group}&\multicolumn{4}{c}{Second Group}\\\cmidrule(lr){3-9}\cmidrule(lr){10-13}
&\multicolumn{1}{R{2.4cm}}{Fifth blah\\loooooong blah}
&\multicolumn{1}{R{2.4cm}}{As if that \\ was not enough}
&\multicolumn{1}{R{2.4cm}}{And so it \\ keeps on going}
&\multicolumn{1}{R{2.4cm}}{When exactly \\ will this end?}
&\multicolumn{1}{R{2.4cm}}{Not exactly \\minimal is it?}
&\multicolumn{1}{R{2.4cm}}{Welcome to my\\ longtable hell}
&\multicolumn{1}{R{2.4cm}}{And this is it\\ I promise}\\
\specialrule{0.01em}{0.0em}{0em}
\specialrule{0.01em}{0.0em}{0em}
\noalign{\raggedright
\footnotesize
%Complicated legend begins
\begin{tabular}{llllllllll}
\hiderowcolors
\multicolumn{6}{l}{\textbf{LEGEND}}\\
{\cellcolor{tableShade8}$\ge$0.8}&:Very high&
{\cellcolor{tableShade2}$\le$0.19}&:Very low\\
\end{tabular}
}

\endfoot

\showrowcolors

\end{longtable}
\end{document}


This will correctly align the decimals, and retains the cell colouration. Note that it is necessary to make \cellcolor 'engine robust' for this to work.

• Thanks very much! It looks great now, but the numbers are in a different font. Is that intentional? – Ariel Mar 9 '12 at 17:14
• See the manual on font settings. You probably want to set mode = text, detect-all. – Joseph Wright Mar 9 '12 at 18:50

I don't think they are really minus signs, but just a place holder? If I change your table to use

&\textemdash&


 &-&

• This works as well! Thanks for the alternative! Any thoughts on how to make the real minus sign behave with the decimal alignment? I thought the + before 1.2 in table-format=+1.2 took care of it... but apparently, that isn't helping. – Ariel Mar 9 '12 at 16:55