0

Hi I'm pretty new to LaTeX but used to code and this has me stumped. I am trying to do a big table that goes over multiple pages, with three columns of text where the middle column has quite a lot of text and I break it with the \thead command.

I'm making my long table as follows at the moment but the text doesn't line up and I am getting all sorts of errors -- it's a disaster but I've tried so many different things!

\documentclass{article}
\begin{document}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{float}
\usepackage{makecell}
\usepackage{longtable}
\begin{center}
\resizebox{\textwidth}
\begin{longtable}{l>{\RaggedRight}X>{\RaggedRight\arraybackslash}X}
    \toprule
    Cited Name & Current Position & \thead{Former Role \\ (if applicable)} \\
    Consultant 1 & \thead{CEO \\ Some Long Type Company} & Some old role. \\
    Consultant 2 & \thead{CTO \\ Some Long Type Company} & N/A \\
    Consultant 3 & \thead{CTO \\ Short Company} & N/A \\
    Entrepreneur 1 & \thead{Director \\ Some Long Type Company} & Some old role. \\
    Entrepreneur 2 & \thead{CFO \\ Some Really Long Type Company} & Some older role. \\
    Entrepreneur 3 1 & \thead{Director \\ Some Company} &  N/A \\
    Entrepreneur 4 & \thead{CFO \\ Short Company} & N/A \\
    Entrepreneur 5 & \thead{CEO \\Some Long Type Company} & Some old role. \\
    Investor 1 & \thead{CEO \\ Some Long Type Company} & Some older role. \\
    Investor 2 & \thead{CEO \\ Some Really Long Type Company} & N/A \\
    Consultant 3 & \thead{CTO \\ Short Company} & N/A \\
    Entrepreneur 1 & \thead{Director \\ Some Long Type Company} & Some old role. \\
    Entrepreneur 2 & \thead{CFO \\ Some Really Long Type Company} & Some older role. \\
    Entrepreneur 3 1 & \thead{Director \\ Some Company} &  N/A \\
    Entrepreneur 4 & \thead{CFO \\ Short Company} & N/A \\
    Entrepreneur 5 & \thead{CEO \\Some Long Type Company} & Some old role. \\
    Investor 1 & \thead{CEO \\ Some Long Type Company} & Some older role. \\
    Investor 2 & \thead{CEO \\ Some Really Long Type Company} & N/A \\
    Consultant 3 & \thead{CTO \\ Short Company} & N/A \\
    Entrepreneur 1 & \thead{Director \\ Some Long Type Company} & Some old role. \\
    Entrepreneur 2 & \thead{CFO \\ Some Really Long Type Company} & Some older role. \\
    Entrepreneur 3 1 & \thead{Director \\ Some Company} &  N/A \\
    Entrepreneur 4 & \thead{CFO \\ Short Company} & N/A \\
    Entrepreneur 5 & \thead{CEO \\Some Long Type Company} & Some old role. \\
    Investor 1 & \thead{CEO \\ Some Long Type Company} & Some older role. \\
    Investor 2 & \thead{CEO \\ Some Really Long Type Company} & N/A \\    
    \bottomrule
\end{longtable}
\caption{this is the caption and it says lots of boring stuff about these types of individuals and so on.}
\label{listofpeople}
\end{center}
\end{document}

An image of what is generated by that is below, and as you can see, some problems include:

  • content isn't aligned
  • the column formatting isn't working and just comes up as ls and Xs
  • caption is not there
  • I'm getting lots of misplaced alignment tab character (&) errors -- is it because the \thead command doesn't work?
  • the \end{center} line seems to throw some error to do with \begin{document}?!

Anyway, I know this is a pile of garbage right now but I've spent hours trying different things and want out... it can't be that hard, but for me apparently so.

However, it does at least pass over two pages (hence two images below).

enter image description here

enter image description here

2
  • \resizebox{\textwidth}\begin is \resizebox{\textwidth}{\begin} and just puts \begin into the argument of resizebox. That will generate multiple errors, but you can not put longtable into a box of any sort as that will prevent page breaking so just remove the resizebox (and the center environment) Jan 22, 2018 at 16:20
  • The posted code does not produce the output shown, and produces multiple errors unrelated to the table starting with ! LaTeX Error: Can be used only in preamble. as you can not have \usepackage after \begin{docuemnt} Jan 22, 2018 at 16:22

2 Answers 2

1

I have put comments inline where I made changes:

\documentclass{article}
%\begin{document} this has to be after the \usepackage lines
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{float}
\usepackage{makecell}
\usepackage{longtable}
\begin{document}
% \begin{center} don't put longtable in center
% \resizebox{\textwidth} this just took \begin as argument and would never do anything useful to a table
\begin{longtable}
%{l>{\RaggedRight}X>{\RaggedRight\arraybackslash}X} longtable does not have X columns
 {lll}
    \toprule
    Cited Name & Current Position & \thead{Former Role \\ (if applicable)} \\
    Consultant 1 & \thead{CEO \\ Some Long Type Company} & Some old role. \\
    Consultant 2 & \thead{CTO \\ Some Long Type Company} & N/A \\
    Consultant 3 & \thead{CTO \\ Short Company} & N/A \\
    Entrepreneur 1 & \thead{Director \\ Some Long Type Company} & Some old role. \\
    Entrepreneur 2 & \thead{CFO \\ Some Really Long Type Company} & Some older role. \\
    Entrepreneur 3 1 & \thead{Director \\ Some Company} &  N/A \\
    Entrepreneur 4 & \thead{CFO \\ Short Company} & N/A \\
    Entrepreneur 5 & \thead{CEO \\Some Long Type Company} & Some old role. \\
    Investor 1 & \thead{CEO \\ Some Long Type Company} & Some older role. \\
    Investor 2 & \thead{CEO \\ Some Really Long Type Company} & N/A \\
    Consultant 3 & \thead{CTO \\ Short Company} & N/A \\
    Entrepreneur 1 & \thead{Director \\ Some Long Type Company} & Some old role. \\
    Entrepreneur 2 & \thead{CFO \\ Some Really Long Type Company} & Some older role. \\
    Entrepreneur 3 1 & \thead{Director \\ Some Company} &  N/A \\
    Entrepreneur 4 & \thead{CFO \\ Short Company} & N/A \\
    Entrepreneur 5 & \thead{CEO \\Some Long Type Company} & Some old role. \\
    Investor 1 & \thead{CEO \\ Some Long Type Company} & Some older role. \\
    Investor 2 & \thead{CEO \\ Some Really Long Type Company} & N/A \\
    Consultant 3 & \thead{CTO \\ Short Company} & N/A \\
    Entrepreneur 1 & \thead{Director \\ Some Long Type Company} & Some old role. \\
    Entrepreneur 2 & \thead{CFO \\ Some Really Long Type Company} & Some older role. \\
    Entrepreneur 3 1 & \thead{Director \\ Some Company} &  N/A \\
    Entrepreneur 4 & \thead{CFO \\ Short Company} & N/A \\
    Entrepreneur 5 & \thead{CEO \\Some Long Type Company} & Some old role. \\
    Investor 1 & \thead{CEO \\ Some Long Type Company} & Some older role. \\
    Investor 2 & \thead{CEO \\ Some Really Long Type Company} & N/A \\    
    \bottomrule
% \end{longtable}   \caption should be inside the table (usually at the start not the end)
\caption{this is the caption and it says lots of boring stuff about these types of individuals and so on.}
\label{listofpeople}
\end{longtable}
%\end{center} dont put longtable in center
\end{document}
1
  • This is great apart from two things -- 1) I get an underfull vbox for the 7th to last line on the table (badness 10000) and 2) the toprule and bottom rule (and therefore the table) don't fill the width of the text to the edge of the caption (i.e. caption sticks out a bit on left and right below bottom rule). As my other tables all align, is there a way to modify your (otherwise excellent) answer to solve these two issues?
    – ratuk_
    Jan 22, 2018 at 17:58
0

The  X column type requires a tabularx environment, and you have to set the total width of the table. The la tablex package brings the longtable functionalities to tabularx, and the columns will have the same width through pages if you add the \keepXColumns directive (without this directive, the calculated width for X columns will be the maximum width of the X columns.

You have to use the syntax of longtable, with the head, firsthead, foot, lastfoot sections. Normally, the caption is set inside the table, in the firsthead section.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{ragged2e}
\usepackage{float}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize}

\begin{document}

\keepXColumns
\renewcommand{\theadalign}{lc}
\begin{tabularx}{\linewidth}{l >{\RaggedRight}X >{\RaggedRight\arraybackslash}X}
\caption{this is the caption and it says lots of boring stuff about these types of individuals and so on.}
\label{listofpeople}\\
\toprule
Cited Name & Current Position & \thead{Former Role \\ (if applicable)} \\
\midrule
\endfirsthead
\multicolumn{3}{c}{\tablename~\thetable \enspace (continued)} \\
\midrule
Cited Name & Current Position & \thead{Former Role \\ (if applicable)} \\
\midrule
\endhead
\midrule
\multicolumn{3}{r}{To be continued}
\endfoot
 \bottomrule
\endlastfoot
    Consultant 1 & \thead[lc]{CEO \\ Some Long Type Company} & Some old role. \\
    Consultant 2 & \thead{CTO \\ Some Long Type Company} & N/A \\
    Consultant 3 & \thead{CTO \\ Short Company} & N/A \\
    Entrepreneur 1 & \thead{Director \\ Some Long Type Company} & Some old role. \\
    Entrepreneur 2 & \thead{CFO \\ Some Really Long Type Company} & Some older role. \\
    Entrepreneur 3 1 & \thead{Director \\ Some Company} & N/A \\
    Entrepreneur 4 & \thead{CFO \\ Short Company} & N/A \\
    Entrepreneur 5 & \thead{CEO \\Some Long Type Company} & Some old role. \\
    Investor 1 & \thead{CEO \\ Some Long Type Company} & Some older role. \\
    Investor 2 & \thead{CEO \\ Some Really Long Type Company} & N/A \\
    Consultant 3 & \thead{CTO \\ Short Company} & N/A \\
    Entrepreneur 1 & \thead{Director \\ Some Long Type Company} & Some old role. \\
    Entrepreneur 2 & \thead{CFO \\ Some Really Long Type Company} & Some older role. \\
    Entrepreneur 3 1 & \thead{Director \\ Some Company} & N/A \\
    Entrepreneur 4 & \thead{CFO \\ Short Company} & N/A \\
    Entrepreneur 5 & \thead{CEO \\Some Long Type Company} & Some old role. \\
    Investor 1 & \thead{CEO \\ Some Long Type Company} & Some older role. \\
    Investor 2 & \thead{CEO \\ Some Really Long Type Company} & N/A \\
    Consultant 3 & \thead{CTO \\ Short Company} & N/A \\
    Entrepreneur 1 & \thead{Director \\ Some Long Type Company} & Some old role. \\
    Entrepreneur 2 & \thead{CFO \\ Some Really Long Type Company} & Some older role. \\
    Entrepreneur 3 1 & \thead{Director \\ Some Company} & N/A \\
    Entrepreneur 4 & \thead{CFO \\ Short Company} & N/A \\
    Entrepreneur 5 & \thead{CEO \\Some Long Type Company} & Some old role. \\
    Investor 1 & \thead{CEO \\ Some Long Type Company} & Some older role. \\
    Investor 2 & \thead{CEO \\ Some Really Long Type Company} & N/A
\end{tabularx}

\end{document} 

enter image description here enter image description here

2
  • the showframe geometry thing makes everything go bananas with lines everywhere in the document!
    – ratuk_
    Jan 22, 2018 at 19:16
  • I used it only for demonstrating purposes. In production, remove the option, of course.
    – Bernard
    Jan 22, 2018 at 19:30

You must log in to answer this question.

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