Placing a symbol before a table entry without upsetting alignment by the siunitx package

To add symbols, you have the key input-symbols, but this one is a comparator, so you just have to set the table-comparator switch to true:

\documentclass[oneside,11pt]{book}

\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[
  expansion = false ,
  tracking = smallcaps ,
  letterspace = 40 ,
  final
]{microtype}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}[!h]
  \centering
  \begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false, table-comparator]
}
    \toprule
    & {X}\\
    \midrule
    A & \sim 6\\
    B & 0.1\\
    \bottomrule
  \end{tabular}
  \caption{B}
\end{table}

\end{document} 

enter image description here


Try the following:

\documentclass[12pt]{article}

\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math} 
\usepackage[expansion = false,
            tracking = smallcaps,
            letterspace = 40,
            final]  {microtype}

\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
    \begin{center}
  \begin{tabular}{c
                  S[input-comparators,              % <----
                    table-space-text-pre=$\sim$,    % <----
                    table-format=1.1,
                    ]          
                 }
    \toprule
type    &   {X}         \\
    \midrule
A       & $\sim$ 6      \\
B       &        0.1    \\
    \bottomrule
    \end{tabular}
\caption{A}
    \end{table}
    
\medskip
    
\medskip
however, in table is better to use 

\verb+table-comparator+ instead of \verb+input-comparators+ as suggested in @Bernard's answer:

\medskip
  \begin{tabular}{c
                  S[table-format=1.1,
                    table-space-text-pre=$\sim$,
                    table-comparator]   % <----
                 }
    \toprule
type    &   {X}     \\
    \midrule
A       & \sim 6    \\                  % <----
B       & 0.1       \\
    \bottomrule
    \end{tabular}
    \end{center}
\end{document}

In both examples result is the same:

enter image description here


Put the \SI{\sim 6}{} instead of \sim and it is works in pdfLaTeX. Happy new year :-). See the explanation here: How to correctly use siunitx to align number in the center of a table for number with preamble

\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[
  expansion = false ,
  tracking = smallcaps ,
  letterspace = 40 ,
  final
]{microtype}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}

% A
\begin{table}[!h]
  \centering
  \begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
    \toprule
    & {X}\\
    \midrule
    A & 6\\
    B & 0.1\\
    \bottomrule
  \end{tabular}
  \caption{A}
\end{table}

% B
\begin{table}[!h]
  \centering
  \begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
    \toprule
    & {X}\\
    \midrule
    A & \SI{\sim 6}{}
\\
    B & 0.1\\
    \bottomrule
  \end{tabular}
  \caption{B}
\end{table}

\end{document}

enter image description here

Edit by comment:

\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[
  expansion = false ,
  tracking = smallcaps ,
  letterspace = 40 ,
  final
]{microtype}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}

% A
\begin{table}[!h]
  \centering
  \begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
    \toprule
    & {X}\\
    \midrule
    A & 6\\
    B & 0.1\\
    \bottomrule
  \end{tabular}
  \caption{A}
\end{table}

% B
\begin{table}[!h]
  \centering
  \begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
    \toprule
    & {X}\\
    \midrule
    A & \!\!\!\SI{\sim 6}{}
\\
    B & 0.1\\
    \bottomrule
  \end{tabular}
  \caption{B}
\end{table}

\end{document}

enter image description here

Tags:

Tables

Siunitx