[Tex/LaTex] Longtable Assist- Undefined Control Sequence

longtabletexmaker

I am trying to produce quiet a few tables for my thesis and keep running into an issue when trying to make a table a long table. While I can get the table to work in just a document on its own – there seems to be an issue when its in my thesis.

I keep getting an error 'Undefined control sequence'. \begin{longtable}

Also what would be the best way to limit the spacing of the table, ex. ensure that there isn't large gaps between each row.

here is the table

\documentclass[12pt]{thesis} 

\usepackage{titlesec}
   \titleformat{\chapter}
      {\normalfont\large}{Chapter \thechapter:}{1em}{}

\usepackage{footnote}
\usepackage{todonotes}
\usepackage{adjustbox}
\graphicspath{ {images/} }
\usepackage{longtable}
\usepackage{booktabs} ... more after this 

    \begin{center}
\begin{longtable}{lllll}
        \caption[Totals of listed buildings per category in each council from 2010.]{Listed Building per category.} \label{LBperCat} \\

    \hline Local Authority                        & Category A & Category B & Category C & Totals \\ \hline 
    \endfirsthead

    \multicolumn{5}{c}%
    {{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
    Local Authority                        & Category A & Category B & Category C & Totals \\ \hline 
    \endhead

    \hline \multicolumn{5}{|r|}{{Continued on next page}} \\ \hline
    \endfoot

    \hline \hline
    \endlastfoot
    Aberdeen & 68 & 679 & 464 & 1211 \\
    Abredeenshire & 208 & 1640 & 1948 & 3796 \\
    Angus \& Bute & 96 & 1019 & 1035 & 2150 \\
    Argyll \& Bute & 143 & 988 & 738 & 1869 \\
    Clackmannan & 17 & 134 & 152 & 303 \\
    Comhairle Nan Eilean Siar & 19 & 172 & 84 & 275 \\
    Dumfries \& Galloway & 224 & 1798 & 1382 & 3404 \\
    Dundee & 82 & 564 & 247 & 893 \\
    East AYRSHIRE & 45 & 339 & 364 & 748 \\
    East Dunbartonshire & 16 & 89 & 75 & 180 \\
    East Lothian & 136 & 1083 & 602 & 1821 \\
    East Refrenshire & 5 & 93 & 37 & 135 \\
    Edinburgh & 910 & 2646 & 1290 & 4846 \\
    Falkirk & 27 & 195 & 128 & 350 \\
    Fife & 212 & 2198 & 2549 & 4959 \\
    Glasgow & 281 & 1273 & 286 & 1840 \\
    Highland & 186 & 1669 & 1161 & 3016 \\
    Inverclyde & 25 & 129 & 91 & 245 \\
    Loch Lomond \& Trossachs National Park & 27 & 208 & 335 & 570 \\
    Midlothian & 71 & 315 & 327 & 713 \\
    Moray & 117 & 768 & 785 & 1670 \\
    North Ayrshire & 41 & 406 & 391 & 838 \\
    North Lanarkshire & 10 & 147 & 155 & 312 \\
    Orkney Islands & 24 & 295 & 313 & 632 \\
    Perth \& Kincorss & 160 & 1438 & 1500 & 3098 \\
    Renfrewshire & 39 & 343 & 185 & 567 \\
    Scottish Borders & 182 & 1247 & 1560 & 2989 \\
    Shetland & 13 & 173 & 158 & 344 \\
    South Ayrshrie & 74 & 438 & 429 & 941 \\
    South Lanarkshire & 92 & 544 & 443 & 1079 \\
    Stirling & 80 & 561 & 530 & 1171 \\
    West Dunbartonshire & 16 & 83 & 39 & 138 \\
    West Lothian & 43 & 215 & 179 & 437 \\ 
    Totals & 3689& 23889 & 19962 & 47540 \\ 
\end{longtable}
\end{center}

Any help/solutions would be amazing.. I have like 45 more tables that I need to make which will be similar to this.

Best Answer

this is more or less off-topic answer

  • instead thesis i use book document class
  • remove spurious text after \usepackage{booktabs} in preamble
  • add \begin{document} and `\end{document}
  • add two new package: makecell and siunitx (by their use the table become more consistent)
  • use horizontal rules defined in booktabs
  • use S column type for columns with numbers
  • long name in the first column split into two lines using `\makecell{...}˙˙

result:

enter image description here

enter image description here

enter image description here

hopefully mwe below will help you to find error in your document:

\documentclass[12pt]{book}

\usepackage{longtable}
\usepackage{booktabs}

\usepackage{makecell}
\usepackage{siunitx}    % <--- added

\begin{document}

\begin{longtable}{@{} l*{4}{S[table-format=4.0,
                              group-minimum-digits=4]}
                 @{} }
    \caption[Listed Building per category.]
            {Totals of listed buildings per category in each council from 2010.}
    \label{LBperCat}                                            \\
    \toprule
                    &   \multicolumn{3}{c}{Category}            \\
    \cmidrule(lr){2-4}
Local Authority     &   {A}  &  {B} &   {C} &   {Totals}        \\
    \midrule
\endfirsthead
    \caption[Listed Building per category.]
            {Totals of listed buildings per category in each council from 2010. (cont.)}
    \label{LBperCat}                                            \\
    \toprule
                    &   \multicolumn{3}{c}{Category}            \\
    \cmidrule(lr){2-4}
Local Authority     &   {A}  &  {B} &   {C} &   {Totals}        \\
    \midrule
\endhead
    \midrule
\multicolumn{5}{r}{\footnotesize\textit{Continued on next page}}
\endfoot
    \bottomrule
\endlastfoot
%
Aberdeen        & 68    & 679   & 464   & 1211  \\
Abredeenshire   & 208   & 1640  & 1948  & 3796  \\
Angus \& Bute   & 96    & 1019  & 1035  & 2150  \\
Argyll \& Bute  & 143   & 988   & 738   & 1869  \\
Clackmannan     & 17    & 134   & 152   & 303   \\
Comhairle Nan Eilean Siar
                & 19    & 172   & 84    & 275   \\
Dumfries \& Galloway
                & 224   & 1798  & 1382  & 3404  \\
Dundee          & 82    & 564   & 247   & 893   \\
East AYRSHIRE   & 45    & 339   & 364   & 748   \\
East Dunbartonshire
                & 16    & 89    & 75    & 180   \\
East Lothian    & 136   & 1083  & 602   & 1821  \\
East Refrenshire
                & 5     & 93    & 37    & 135   \\
Edinburgh       & 910   & 2646  & 1290  & 4846  \\
Falkirk         & 27    & 195   & 128   & 350   \\
Fife            & 212   & 2198  & 2549  & 4959  \\
Glasgow         & 281   & 1273  & 286   & 1840  \\
Highland        & 186   & 1669  & 1161  & 3016  \\
Inverclyde      & 25    & 129   & 91    & 245   \\
\makecell[l]{Loch Lomond \&\\
             Trossachs National Park}
                & 27    & 208   & 335   & 570   \\
Midlothian      & 71    & 315   & 327   & 713   \\
Moray           & 117   & 768   & 785   & 1670  \\
North Ayrshire  & 41    & 406   & 391   & 838   \\
North Lanarkshire
                & 10    & 147   & 155   & 312   \\
Orkney Islands  & 24    & 295   & 313   & 632   \\
Perth \& Kincorss
                & 160   & 1438  & 1500  & 3098  \\
Renfrewshire    & 39    & 343   & 185   & 567   \\
Scottish Borders
                & 182   & 1247  & 1560  & 2989  \\
Shetland        & 13    & 173   & 158   & 344   \\
South Ayrshrie  & 74    & 438   & 429   & 941   \\
South Lanarkshire & 92  & 544   & 443   & 1079  \\
Stirling        & 80    & 561   & 530   & 1171  \\
West Dunbartonshire
                & 16    & 83    & 39    & 138   \\
West Lothian    & 43    & 215   & 179   & 437   \\
Totals          & 3689  & 23889 & 19962 & 47540 \\
\end{longtable}
\end{document}