0

I've tried everything I can think of but longtable just won't allow me to add a caption and label to the top of the table.

My table looks like this: enter image description here

But when I add in a caption and figure, overleaf/texstudio both crashes. Here's my code:

\documentclass[10pt,a4paper]{article}
\usepackage[hmargin=1cm, top=2cm]{geometry}
\usepackage{amsmath, amssymb}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{booktabs, makecell, longtable}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\parindent=0em
\parskip=20pt

\usepackage{enumitem}


\begin{document}
\begin{center}

\setlist[itemize]{topsep = 1ex, parsep =0pt, leftmargin=*,after=\vspace{-\baselineskip}}
\begin{longtable}{ll L{5.5cm} L{4.5cm}}
    \caption{Table of 2013 Census variables used in this dissertation} 
    \label{Table 2.1}
    \toprule
    \textbf{Variable} & \textbf{Census Code} & \textbf{Description} & \textbf{Study Variables} \\

\midrule
    Education & cen\_ind\_std\_highest\_qual\_code
    & This variable records the highest qualification achieved by an individual. A qualification is a formally recognised award for educational or training attainment by one of the following authorities:
\begin{itemize}
    \item New Zealand Qualifications Authority and their recognised approval bodies
    \item Universities New Zealand
    \item Associations of Polytechnics of New Zealand
    \item Association of Colleges of Education in New Zealand
    \item Recognised overseas authorities
\end{itemize}
        & \textbf{highest\_qual}
            \begin{itemize}[leftmargin=1.5em]
        \item[0.]   No formal qualifications
        \item[1.]   Level 1, 2, or 3 certificate
        \item[2.]   Level 4, 5, or 6 certificate
        \item[3.]   Undergraduate degree
        \item[4.]   Postgraduate degree
        \item[9.]   Missing or unidentifiable
            \end{itemize}   \\
\bottomrule
\end{longtable}
\end{center}
\end{document}
Lucas
  • 35

1 Answers1

2

Edit: There is already an answer in how to have a caption on top of longtable?. I am keeping mine as it contains further suggestions on package loading order.


Due to the way longtable is implemented, you need to add a manual line break \\ before \toprule. I also adjusted the loading order of some of your packages.

\documentclass[10pt,a4paper]{article}    
\usepackage{amsmath, amssymb}
\usepackage{graphicx}
\usepackage{booktabs, makecell, longtable}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\setlength\parindent{0pt}
\setlength\parskip{20pt}% <- This should be a glue
\usepackage{enumitem}
\usepackage{hyperref}
\usepackage[hmargin=1cm,top=2cm]{geometry}

\begin{document}
\begin{center}
\setlist[itemize]{topsep=1ex, parsep=0pt, leftmargin=*, after=\vspace{-\baselineskip}}
\begin{longtable}{ll L{5.5cm} L{4.5cm}}
    \caption{Table of 2013 Census variables used in this dissertation}
    \label{Table-2.1}\\
    \toprule
    \textbf{Variable} & \textbf{Census Code} & \textbf{Description} & \textbf{Study Variables} \\
    \midrule
    Education & cen\_ind\_std\_highest\_qual\_code
    & This variable records the highest qualification achieved by an individual. A qualification is a formally recognised award for educational or training attainment by one of the following authorities:
    \begin{itemize}
    \item New Zealand Qualifications Authority and their recognised approval bodies
    \item Universities New Zealand
    \item Associations of Polytechnics of New Zealand
    \item Association of Colleges of Education in New Zealand
    \item Recognised overseas authorities
    \end{itemize}
        & \textbf{highest\_qual}
          \begin{itemize}[leftmargin=1.5em]
          \item[0.]   No formal qualifications
          \item[1.]   Level 1, 2, or 3 certificate
          \item[2.]   Level 4, 5, or 6 certificate
          \item[3.]   Undergraduate degree
          \item[4.]   Postgraduate degree
          \item[9.]   Missing or unidentifiable
          \end{itemize}   \\
    \bottomrule
\end{longtable}
\end{center}
\end{document}
Ruixi Zhang
  • 9,553