0

EDIT: Thanks to David Carlisle who pointed out the problem, in the comments below. I decided to correct the MWE and add some comments to help anyone who's using longtable for the first time.

First of all, yes - I did Google, I did find some questions related to longtable plus siunitx - but sincerely? it didn't make much sense to me, and I got back at square one!

I've made a table and realized after compiling it that it was waaaay to big for a single page. At first, I thought of just making another table in another page, but I realized I've seen tables spawning two or more pages, so I opted for the 'not so clumsy' approach - and here comes longtable to the rescue!

Of course, after a few examples seen and trying to understand the manual, I decided to write it down and compile it! The result? Failure, the mother of all knowledge.

So please, oh guru gods of TeX, any help on understanding why and how to make this code run would be greatly appreciated!

    \documentclass[a4paper]{article}
    \usepackage{longtable}
    \usepackage{booktabs}
    \usepackage{siunitx}

    \begin{document}

    \begin{longtable}{@{\hspace{\tabcolsep}\extracolsep{\fill}} cccccc S[table-format=5.4] S[table-format=-1.4] } %set number of columns

    \caption{Measured rotational transitions (in MHz) assigned to conformer $I$ using CP-FTMW spectroscopy.}    \\ 


% First page Table Header setup
    \toprule
    {J\textasciiacute} &    {K\textasciiacute$_{-1}$}  & {K\textasciiacute$_{+1}$} &   {J\textacutedbl}  &  {K\textacutedbl$_{-1}$}  &  {K\textacutedbl$_{+1} $} &   {$ \nu_{obs} $} & {$ \nu_{obs} - \nu_{cal} $} \\   
    \midrule
    \endfirsthead
% *// END  //*

% Second page Table Header setup    
    \multicolumn{8}{c}%
    {{\tablename\ \thetable{} -- resuming from previous page}} \\
    \midrule
    {J\textasciiacute} &    {K\textasciiacute$_{-1}$}  & {K\textasciiacute$_{+1}$} &   {J\textacutedbl}  &  {K\textacutedbl$_{-1}$}  &  {K\textacutedbl$_{+1} $} &   {$ \nu_{obs} $} & {$ \nu_{obs} - \nu_{cal} $} \\
    \midrule
    \endhead
% *// END  //*

% Table Break Footnote Setup    
    \midrule
    \multicolumn{8}{c}{{Resumed on next page}}
    \endfoot
    \bottomrule
    \endlastfoot
% *// END  //*  


    7 & 0  &  7  &  6  &  0  &  6  &  6079.960   &   -0.001 \\
    8 & 0  &  8  &  7  &  0  &  7  &  6923.244   &    0.056 \\
   10 & 0  & 10  &  9  &  0  &  9  &  8588.202   &    0.047 \\
   11 & 0  & 11  & 10  &  0  & 10  &  9412.244   &    0.038 \\
    7 & 1  &  6  &  6  &  1  &  5  &  6337.229   &    0.027 \\
    8 & 1  &  7  &  7  &  1  &  6  &  7233.906   &    0.021 \\
    9 & 1  &  8  &  8  &  1  &  7  &  8126.661   &    0.032 \\
   10 & 1  &  9  &  9  &  1  &  8  &  9014.687   &    0.032 \\
   11 & 1  & 10  & 10  &  1  &  9  &  9897.147   &    0.026 \\
   10 & 1  & 10  &  9  &  1  &  9  &  8464.423   &   -0.012 \\
    9 & 1  &  9  &  8  &  1  &  8  &  7625.732   &   -0.013 \\
    8 & 1  &  8  &  7  &  1  &  7  &  6785.001   &   -0.003 \\
   11 & 1  & 11  & 10  &  1  & 10  &  9301.098   &   -0.012 \\
   10 & 2  &  9  &  9  &  2  &  8  &  8761.701   &   -0.007 \\
    9 & 2  &  8  &  8  &  2  &  7  &  7892.425   &    0.018 \\
    8 & 2  &  7  &  7  &  2  &  6  &  7020.953   &   -0.012 \\
    7 & 2  &  6  &  6  &  2  &  5  &  6147.569   &   -0.031 \\
    5 & 1  &  4  &  4  &  0  &  4  &  6491.023   &   -0.027 \\
    6 & 1  &  5  &  5  &  0  &  5  &  7558.030   &   -0.028 \\
    7 & 1  &  6  &  6  &  0  &  6  &  8666.376   &    0.020 \\
    8 & 1  &  7  &  7  &  0  &  7  &  9820.300   &    0.019 \\
    4 & 2  &  3  &  3  &  1  &  3  &  8652.332   &   -0.033 \\
    5 & 2  &  4  &  4  &  1  &  4  &  9645.484   &   -0.031 \\
    3 & 2  &  2  &  2  &  1  &  2  &  7687.458   &   -0.017 \\
    2 & 2  &  1  &  1  &  1  &  1  &  6750.755   &   -0.019 \\
    2 & 2  &  0  &  1  &  1  &  0  &  6695.425   &    0.032 \\
    3 & 2  &  1  &  2  &  1  &  1  &  7524.271   &    0.016 \\
    4 & 2  &  2  &  3  &  1  &  2  &  8333.209   &   -0.009 \\
    5 & 2  &  3  &  4  &  1  &  3  &  9128.076   &   -0.054 \\
    6 & 2  &  4  &  5  &  1  &  4  &  9916.154   &    0.002 \\
    2 & 2  &  1  &  1  &  1  &  0  &  6693.956   &    0.028 \\
    3 & 2  &  2  &  2  &  1  &  1  &  7516.964   &    0.027 \\
    4 & 2  &  3  &  3  &  1  &  2  &  8311.325   &    0.014 \\
    5 & 2  &  4  &  4  &  1  &  3  &  9077.186   &   -0.033 \\
   11 & 2  &  9  & 10  &  2  &  8  &  9893.710   &   -0.024 \\
   10 & 2  &  8  &  9  &  2  &  7  &  8971.500   &   -0.023 \\
    9 & 2  &  7  &  8  &  2  &  6  &  8051.888   &    0.001 \\
    8 & 2  &  6  &  7  &  2  &  5  &  7136.489   &   -0.008 \\
   11 & 3  &  8  & 10  &  3  &  7  &  9736.928   &   -0.029 \\
    9 & 3  &  6  &  8  &  3  &  5  &  7948.656   &   -0.006 \\
    8 & 3  &  5  &  7  &  3  &  4  &  7059.430   &   -0.000 \\
    7 & 3  &  5  &  6  &  3  &  4  &  6169.740   &    0.030 \\
    8 & 3  &  6  &  7  &  3  &  5  &  7053.534   &   -0.008 \\
    9 & 3  &  7  &  8  &  3  &  6  &  7937.882   &   -0.051 \\
   10 & 3  &  8  &  9  &  3  &  7  &  8822.755   &    0.036 \\
   11 & 3  &  9  & 10  &  3  &  8  &  9707.698   &    0.018 \\
   11 & 4  &  7  & 10  &  4  &  6  &  9703.309   &   -0.013 \\
   10 & 4  &  6  &  9  &  4  &  5  &  8817.517   &   -0.026 \\
    9 & 4  &  5  &  8  &  4  &  4  &  7932.918   &    0.039 \\
   11 & 4  &  8  & 10  &  4  &  7  &  9702.196   &   -0.055 \\
   10 & 4  &  7  &  9  &  4  &  6  &  8817.017   &    0.011 \\
    9 & 4  &  6  &  8  &  4  &  5  &  7932.606   &   -0.024 \\
    7 & 4  &  4  &  6  &  4  &  3  &  6166.219   &   -0.036 \\
    2 & 2  &  0  &  1  &  1  &  1  &  6752.243   &    0.005 \\
    3 & 2  &  1  &  2  &  1  &  2  &  7694.798   &    0.005 \\
    4 & 2  &  2  &  3  &  1  &  3  &  8674.239   &   -0.033 \\
    5 & 2  &  3  &  4  &  1  &  4  &  9696.521   &    0.096 \\
   10 & 0  & 10  &  9  &  1  &  9  &  7859.890   &   -0.006 \\
    9 & 0  &  9  &  8  &  1  &  8  &  6897.479   &   -0.005 \\

\end{longtable}
\end{document}

Final result - 1st page 2nd page

6
  • 1
    you are just missing a \\ after the caption before \toprule Commented Feb 19, 2020 at 17:11
  • Ah! The error message wasn't very elucidative! Thanks for the sharp eye, David!
    – Strelok
    Commented Feb 19, 2020 at 18:07
  • 1
    To also get rid of all of the "overfull box" warnings, you might want to correct the table-format of the two S type columns as follows: S[table-format=4.5] S[table-format=-1.5].
    – leandriis
    Commented Feb 19, 2020 at 18:22
  • 1
    @Strelok well it is my code, I didn't have to look too hard:-) Commented Feb 19, 2020 at 22:11
  • @DavidCarlisle, personally I felt a bit lost reading your manual. If you feel this table may provide some insight to anyone reading it, go forth and use it in your manual without any issue! and I just realized that the table was misaligned with the headers. Only after two passes did it get it right.
    – Strelok
    Commented Feb 20, 2020 at 8:38

1 Answer 1

1

I would introduce small changes to you MWE which enable to determine table width equal to text width and with this enable \extracolsep{\fill}} works as desired. Also in S columns I will use group-four-digits options, insert some vertical space after each fourth table's row, etc. All changes are marked in code by % <---.

Considering aforementioned, the table is:

\documentclass[a4paper]{article}
\usepackage{booktabs, longtable}
\usepackage{siunitx}
\usepackage[skip=1ex,
            labelfont=bf,font=small]{caption}   % <--- new

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begingroup
\sisetup{group-four-digits}     % <---
\setlength\LTleft{0pt}          % <---
\setlength\LTright{0pt}         % <---
\setlength\LTcapwidth\linewidth % <---
    \begin{longtable}{@{\hspace{\tabcolsep}\extracolsep{\fill}} 
                        *{6}{S[table-format=2.0]}   % <---
                             S[table-format=4.3]    % <--- 
                             S[table-format=-1.3] } % <---
\caption{Measured rotational transitions (in MHz) assigned to conformer $I$ using CP-FTMW spectroscopy.}
\label{tab:spectroscopy}        \\
% First page Table Header setup
    \toprule
{J´}    & {K$_{-1}$}    & {K´$_{+1}$}   & {J´}      & {K´$_{-1}$}   % <---  
        & {K´´$_{+1}$}  & {$\nu_{\mathrm{obs}}$}                    % <---
        & {$\nu_{\mathrm{obs}} - \nu_{\mathrm{cal}}$}       \\      % <---
    \midrule
\endfirsthead
% Second page Table Header setup
\caption[]{Measured rotational transitions --                       % <---
           resuming from previous page} \\                           
    \midrule
 {J´}   & {K$_{-1}$}    & {K´$_{+1}$}   & {J´}      & {K´$_{-1}$}
        & {K´´$_{+1}$}  & {$\nu_{\mathrm{obs}}$}
        & {$\nu_{\mathrm{obs}} - \nu_{\mathrm{cal}}$}       \\
    \midrule
\endhead
% Table Footer setup
   \midrule[\heavyrulewidth]
    \multicolumn{8}{r}{\small\textit{Resumed on next page}}
\endfoot
    \bottomrule
\endlastfoot
% end of longtable preamble 
%
% table body
    7 & 0  &  7  &  6  &  0  &  6  &  6079.960   &   -0.001 \\
    8 & 0  &  8  &  7  &  0  &  7  &  6923.244   &    0.056 \\
   10 & 0  & 10  &  9  &  0  &  9  &  8588.202   &    0.047 \\
   11 & 0  & 11  & 10  &  0  & 10  &  9412.244   &    0.038 \\
\addlinespace
    7 & 1  &  6  &  6  &  1  &  5  &  6337.229   &    0.027 \\
    8 & 1  &  7  &  7  &  1  &  6  &  7233.906   &    0.021 \\
    9 & 1  &  8  &  8  &  1  &  7  &  8126.661   &    0.032 \\
   10 & 1  &  9  &  9  &  1  &  8  &  9014.687   &    0.032 \\
\addlinespace
   11 & 1  & 10  & 10  &  1  &  9  &  9897.147   &    0.026 \\
   10 & 1  & 10  &  9  &  1  &  9  &  8464.423   &   -0.012 \\
    9 & 1  &  9  &  8  &  1  &  8  &  7625.732   &   -0.013 \\
    8 & 1  &  8  &  7  &  1  &  7  &  6785.001   &   -0.003 \\
\addlinespace
   11 & 1  & 11  & 10  &  1  & 10  &  9301.098   &   -0.012 \\
   10 & 2  &  9  &  9  &  2  &  8  &  8761.701   &   -0.007 \\
    9 & 2  &  8  &  8  &  2  &  7  &  7892.425   &    0.018 \\
    8 & 2  &  7  &  7  &  2  &  6  &  7020.953   &   -0.012 \\
\addlinespace
    7 & 2  &  6  &  6  &  2  &  5  &  6147.569   &   -0.031 \\
    5 & 1  &  4  &  4  &  0  &  4  &  6491.023   &   -0.027 \\
    6 & 1  &  5  &  5  &  0  &  5  &  7558.030   &   -0.028 \\
    7 & 1  &  6  &  6  &  0  &  6  &  8666.376   &    0.020 \\
\addlinespace
    8 & 1  &  7  &  7  &  0  &  7  &  9820.300   &    0.019 \\
    4 & 2  &  3  &  3  &  1  &  3  &  8652.332   &   -0.033 \\
    5 & 2  &  4  &  4  &  1  &  4  &  9645.484   &   -0.031 \\
    3 & 2  &  2  &  2  &  1  &  2  &  7687.458   &   -0.017 \\
\addlinespace
    2 & 2  &  1  &  1  &  1  &  1  &  6750.755   &   -0.019 \\
    2 & 2  &  0  &  1  &  1  &  0  &  6695.425   &    0.032 \\
    3 & 2  &  1  &  2  &  1  &  1  &  7524.271   &    0.016 \\
    4 & 2  &  2  &  3  &  1  &  2  &  8333.209   &   -0.009 \\
\addlinespace
    5 & 2  &  3  &  4  &  1  &  3  &  9128.076   &   -0.054 \\
    6 & 2  &  4  &  5  &  1  &  4  &  9916.154   &    0.002 \\
    2 & 2  &  1  &  1  &  1  &  0  &  6693.956   &    0.028 \\
    3 & 2  &  2  &  2  &  1  &  1  &  7516.964   &    0.027 \\
\addlinespace
    4 & 2  &  3  &  3  &  1  &  2  &  8311.325   &    0.014 \\
    5 & 2  &  4  &  4  &  1  &  3  &  9077.186   &   -0.033 \\
   11 & 2  &  9  & 10  &  2  &  8  &  9893.710   &   -0.024 \\
   10 & 2  &  8  &  9  &  2  &  7  &  8971.500   &   -0.023 \\
\addlinespace
    9 & 2  &  7  &  8  &  2  &  6  &  8051.888   &    0.001 \\
    8 & 2  &  6  &  7  &  2  &  5  &  7136.489   &   -0.008 \\
   11 & 3  &  8  & 10  &  3  &  7  &  9736.928   &   -0.029 \\
    9 & 3  &  6  &  8  &  3  &  5  &  7948.656   &   -0.006 \\
\addlinespace
    8 & 3  &  5  &  7  &  3  &  4  &  7059.430   &   -0.000 \\
    7 & 3  &  5  &  6  &  3  &  4  &  6169.740   &    0.030 \\
    8 & 3  &  6  &  7  &  3  &  5  &  7053.534   &   -0.008 \\
    9 & 3  &  7  &  8  &  3  &  6  &  7937.882   &   -0.051 \\
\addlinespace
   10 & 3  &  8  &  9  &  3  &  7  &  8822.755   &    0.036 \\
   11 & 3  &  9  & 10  &  3  &  8  &  9707.698   &    0.018 \\
   11 & 4  &  7  & 10  &  4  &  6  &  9703.309   &   -0.013 \\
   10 & 4  &  6  &  9  &  4  &  5  &  8817.517   &   -0.026 \\
\addlinespace
    9 & 4  &  5  &  8  &  4  &  4  &  7932.918   &    0.039 \\
   11 & 4  &  8  & 10  &  4  &  7  &  9702.196   &   -0.055 \\
   10 & 4  &  7  &  9  &  4  &  6  &  8817.017   &    0.011 \\
    9 & 4  &  6  &  8  &  4  &  5  &  7932.606   &   -0.024 \\
\addlinespace
    7 & 4  &  4  &  6  &  4  &  3  &  6166.219   &   -0.036 \\
    2 & 2  &  0  &  1  &  1  &  1  &  6752.243   &    0.005 \\
    3 & 2  &  1  &  2  &  1  &  2  &  7694.798   &    0.005 \\
    4 & 2  &  2  &  3  &  1  &  3  &  8674.239   &   -0.033 \\
\addlinespace
    5 & 2  &  3  &  4  &  1  &  4  &  9696.521   &    0.096 \\
   10 & 0  & 10  &  9  &  1  &  9  &  7859.890   &   -0.006 \\
    9 & 0  &  9  &  8  &  1  &  8  &  6897.479   &   -0.005 \\
    \end{longtable}
\endgroup
\end{document}

Above MWE gives:

enter image description here

enter image description here

1
  • The introduction of the line space is interesting to add to the readability of the table. Also, nice trick to make /sisetup act locally with the group option.
    – Strelok
    Commented Feb 20, 2020 at 8:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .