1

Question 1

A while ago, I used some code from here, which fitted my requirements perfectly. However, I'd like a different table, and playing around with the code (I'm quite new to Latex) has not yielded any encouraging results. Basically I'd like a table like the one below (produced in Excel because I can't produce it in Latex at the moment):

enter image description here

Currently I am getting the following - note the numbers in notes are from an old table

enter image description here

My MWE (don't worry about alignment when it appears in the article class - I'm using a customised template which already has all the margins etc set out). I'd also like the Notes column to have a slightly greater width than the other columns because I will be putting more text in there. Also you might notice the (See Appendix ??) - that is my second question.

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\renewcommand\arraystretch{1.2}
\usepackage{threeparttable}
\begin{document}
\begin{table}[H]
\centering
\renewcommand\arraystretch{1.2}
\begin{threeparttable}
\caption{Description of Independent Variables}
\begin{tabular}{@{}p{0.20\textwidth}*{4}{L{\dimexpr0.20\textwidth-2\tabcolsep\relax}}@{}}
\toprule
& {\bfseries Independent Variable} & {\bfseries Code} & {\bfseries Units} &    \bfseries{Notes} \\
\midrule
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
Adjusted Matric GPA & AMGPA & Continuous & The average includes the top four subjects,  excluding Mathematics, Additional Mathematics, Mathematics Paper 3 and English (First or Second Language. See Appendix~\ref{chapter:AppendixB}). & 11 -- 14 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

Question 2

I have a 'chapter' which is actually an Appendix. I've labelled the Appendix in the following way:

\chapter{Appendix B}
\label{AppendixB}
\lhead{Appendix B \emph{Adjusted Matric GPA }}

Now when I wanted to cross-reference this Appendix in my text, I get a ??. My cross-reference is the following:

See Appendix~\ref{chapter:AppendixB})

Why is Latex not picking up the label?

Question 3

My table is going to extend over one page once I put all my variables in. I see the longtable package is recommended for this job. However, simply replacing the \begin{table}...\end{table} with \begin{longtable}...\end{longtable} in my MWE is bringing up a whole host of additional errors (for example, it doesn't like the \centering command and says \caption -> \noalign). What should I be aware of when using the longtable package over the table package?

7
  • 1
    Question 2 is easy: Use correct label in the referense, i.e. "Appendix~\ref{AppendixB}. Or better: use the ‘cleveref’-package. ‘longtable’ is centered by default. Remove the \centering-command. Also, remove the table-environment. You set the caption within the longtable it self. Read the documentation.
    – Sveinung
    May 13, 2014 at 11:33
  • Interesting. A bit confusing as it is a "chapter", so to speak. Will read the documentation. May 13, 2014 at 11:38
  • 2
    Question 3: You basically replace tabular by longtable and leave out the table environment completely. In some sense longtable implements both environments at once and has its own support for captions; see the documentation. May 13, 2014 at 11:42
  • Reference is not confusing: In standard LaTeX you repeat the label, letter by letter, inside the brackets: You mix this with the the fact that many LaTeX-user use the refernce type in the label name: \label{chapter:AppendixB} "see Appendix~ \ref{chapter:AppendixB}"
    – Sveinung
    May 13, 2014 at 11:48
  • 1
    @Chris Put the label outside the last bracket in the caption: \caption{Description ...}\label{DIV}, and use correct label name: "A description of the ... in Table~\ref{DIV} below"
    – Sveinung
    May 13, 2014 at 20:48

1 Answer 1

1

A solution using the ltablex package, that extends longtable to the tabularx environment. I don't know what you want to do with athreeparttableenvironment (you don't really use it here), but anyway, it doesn't work with longtables. For long tables, you have to load thethreeparttablexpackage, and the environment isThreePartTable`.

To cross-reference, you have to put a label just after the caption. I think this code fulfills all your requirements:

\documentclass[11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}

\usepackage[showframe, nomarginpar]{geometry} %
\usepackage{ragged2e}
\usepackage{booktabs}
\usepackage{array}
\usepackage{ltablex}%
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hsize=1.25\hsize}X}
\newcolumntype{C}{>{\centering\arraybackslash\hsize=0.75\hsize}X}
\usepackage{threeparttablex}
\usepackage{makecell}
\renewcommand*{\theadfont}{\bfseries}
\renewcommand*{\theadalign}{{C}c}

\begin{document}

\begin{ThreePartTable}
\centering
\renewcommand\arraystretch{1.25}
\begin{tabularx}{\linewidth}{@{}X*{2}{C}*{2}{L}@{}}
\caption{Description of Independent Variables}\\
\toprule
& \thead{Independent \\ Variable} & \thead{Code} & \thead{Units} &    \thead{Notes} \\
\midrule
\endhead
\midrule
\multicolumn{5}{r}{\itshape continued}
\endfoot
\bottomrule
\endlastfoot
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
Adjusted Matric GPA & AMGPA & Continuous & The average includes the top four subjects,  excluding Mathematics, Additional Mathematics, Mathematics Paper 3 and English (First or Second Language. See Appendix~\ref{chapter:AppendixB}). & 11 -- 14 \\
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
Adjusted Matric GPA & AMGPA & Continuous & The average includes the top four subjects,  excluding Mathematics, Additional Mathematics, Mathematics Paper 3 and English (First or Second Language. See Appendix~\ref{chapter:AppendixB}). & 11 -- 14 \\
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
Adjusted Matric GPA & AMGPA & Continuous & The average includes the top four subjects, excluding Mathematics, Additional Mathematics, Mathematics & 11 -- 14 \\
 &  & & Paper 3 and English (First or Second Language. See Appendix~\ref{chapter:AppendixB}). & %\\
\end{tabularx}
\end{ThreePartTable}

\appendix
\section{First Appendix}
\section{Second Appendix} \label{chapter:AppendixB}
\end{document} 

enter image description here

You must log in to answer this question.

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