1

I'm creating this table that has both numbers and words.

 \documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float,lipsum,subfig}
\usepackage{adjustbox,tabularx,ragged2e}
\usepackage{amsmath,geometry,booktabs}
\usepackage{mathtools,array,dcolumn,longtable}
\newcolumntype{L}[1]{>{\RaggedRight\arraybackslash\hsize=#1\hsize}X}
\setlength\tabcolsep{4pt} % default: 6pt  % '2pt' is not exactly much
\usepackage[justification = centering]{caption}
\usepackage{setspace}
\usepackage{geometry}
\usepackage{titlesec}    
\usepackage{lipsum}
\usepackage{etoolbox}
\usepackage{siunitx}

\usepackage[nodisplayskipstretch]{setspace}
\onehalfspacing
\usepackage[skip=1ex]{caption}
\newrobustcmd{\B}{\bfseries}

\begin{document}

\singlespacing  
\begin{longtable}{S[table-format=2.0]
        *{3}{S[table-format=2.1]}
        S[table-format=2.1,detect-weight]
    }
    \caption{}
    \label{tab:descr_stat_es}\\
    \toprule
    {Geological fm.} &{L mean} &{L std} &{R mean}  &{R std}\\
    \midrule
    \endfirsthead
    \caption[]{}\\
    \toprule
    {Geological fm.} &{L mean} &{L std} &{R mean}  &{R std}\\
    \midrule
    \endhead
    \midrule[\heavyrulewidth]
    \multicolumn{5}{r}{\footnotesize\textit{Continued on the next page}}
    \endfoot
    \bottomrule
    \endlastfoot
    $MAC$&  377.9&  41.7&   14.4&   1.8 \\
    $MAC$&  423.9&  36.5&   15.8&   1.9 \\
    $MAC$&  425.3&  33.3&   14.0&   2.6 \\
    $MAC$&  466.3&  56.8&   20.8&   5.6 \\
    $MAC$&  499.8&  86.4&   20.2&   7.0 \\
    $MAC$&  538.8&  45.3&   26.3&   2.4 \\
    $MAC$&  543.7&  47.4&   26.5&   2.8 \\
    $MAC$&  588.1&  122.7&  40.1&   7.2 \\
    $MAC$&  601.7&  143.7&  44.1&   5.6 \\
    $MAC$&  614.5&  54.4&   27.4&   2.9 \\
    $MAC$&  623.7&  80.7&   33.7&   4.7 \\
    $RET$&  636.7&  121.9&  35.7&   6.9 \\
    $RET$&  691.2&  51.4&   40.9&   5.0 \\
    $MAC$&  710.3&  59.6&   39.0&   4.3 \\
    $MAC$&  761.3&  60.3&   57.7&   2.3 \\
    $MAC$&  762.9&  41.6&   58.5&   1.5 \\
    $MAC$&  766.8&  36.2&   56.4&   2.0 \\
    $MAC$&  767.0&  49.7&   58.9&   1.8 \\
    $MAC$&  774.0&  39.1&   59.2&   2.3 \\
    $MAC$&  780.0&  64.2&   57.0&   2.5 \\
\end{longtable}
\onehalfspacing

\end{document}

I got this error:

Package siunitx Error: Invalid numerical input 'E'. $RET$&

How can I tell latex that the first column is not a numeric input?

  • Don't use the S column type. You can use, for instance, >{$}l<{$} to avoid having to type a pair of $ $ for each entry. – Bernard Sep 4 '19 at 16:55
1

Don't use the S column type for the first, i.e., left-hand-most column: That column contains no numbers -- with or without decimal markers -- so nothing useful is going to be achieved by using the S column type here. Instead, use the basic l column type -- and get rid of the $ math-mode initiators and terminators.

Also, don't load packages -- such as setspace, geometry, and lipsum -- more than once.

enter image description here

\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float,lipsum,subfig}
\usepackage{adjustbox,tabularx,ragged2e}
\usepackage{amsmath,geometry,booktabs}
\usepackage{mathtools,array,dcolumn,longtable}
\newcolumntype{L}[1]{>{\RaggedRight\arraybackslash%
       \hsize=#1\hsize\linewidth=\hsize}X}
\setlength\tabcolsep{4pt} % default: 6pt  % '2pt' is not exactly much
\usepackage[justification = centering]{caption}
%%%%\usepackage{setspace}  % don't load packages repeatedly
%%%%\usepackage{geometry}
\usepackage{titlesec}    
%%%%\usepackage{lipsum}
\usepackage{etoolbox}
\usepackage{siunitx}

\usepackage[nodisplayskipstretch]{setspace}
\onehalfspacing

\usepackage[skip=1ex]{caption}
\newrobustcmd{\B}{\bfseries}

\begin{document}

%\singlespacing   % <-- not needed for 'longtable'
\begin{longtable}{@{}
             l
        *{2}{S[table-format=3.1]}
             S[table-format=2.1]
             S[table-format=1.1]
    @{} }
    %% header and footer information
    \caption{}
    \label{tab:descr_stat_es}\\
    \toprule
    {Geological fm.} &{L mean} &{L std} &{R mean} &{R std}\\
    \midrule
    \endfirsthead

    \caption[]{}\\
    \toprule
    {Geological fm.} &{L mean} &{L std} &{R mean} &{R std}\\
    \midrule
    \endhead

    \midrule[\heavyrulewidth]
    \multicolumn{5}{r}{\footnotesize\textit{Continued on the next page}}
    \endfoot

    \bottomrule
    \endlastfoot

    %% body of longtable
    MAC&  377.9&  41.7&   14.4&   1.8 \\
    MAC&  423.9&  36.5&   15.8&   1.9 \\
    MAC&  425.3&  33.3&   14.0&   2.6 \\
    MAC&  466.3&  56.8&   20.8&   5.6 \\
    MAC&  499.8&  86.4&   20.2&   7.0 \\
    MAC&  538.8&  45.3&   26.3&   2.4 \\
    MAC&  543.7&  47.4&   26.5&   2.8 \\
    MAC&  588.1&  122.7&  40.1&   7.2 \\
    MAC&  601.7&  143.7&  44.1&   5.6 \\
    MAC&  614.5&  54.4&   27.4&   2.9 \\
    MAC&  623.7&  80.7&   33.7&   4.7 \\
    RET&  636.7&  121.9&  35.7&   6.9 \\
    RET&  691.2&  51.4&   40.9&   5.0 \\
    MAC&  710.3&  59.6&   39.0&   4.3 \\
    MAC&  761.3&  60.3&   57.7&   2.3 \\
    MAC&  762.9&  41.6&   58.5&   1.5 \\
    MAC&  766.8&  36.2&   56.4&   2.0 \\
    MAC&  767.0&  49.7&   58.9&   1.8 \\
    MAC&  774.0&  39.1&   59.2&   2.3 \\
    MAC&  780.0&  64.2&   57.0&   2.5 \\
\end{longtable}
\onehalfspacing

\end{document}
|improve this answer|||||
  • 1
    Fantastic explanation, thank you @Mico!!!! :D – Elisa m Sep 4 '19 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.