长表格(跨越多页),仅包含不同长度的文本内容

长表格(跨越多页),仅包含不同长度的文本内容

嗨,我对 LaTeX 还很陌生,但以前也用过代码,这让我很为难。我试图做一个跨多页的大表格,有三列文本,中间一列有很多文本,我用命令把它分开\thead

我目前正在制作如下的长表,但是文本没有排列好,而且出现了各种错误——这是一场灾难,但我已经尝试了很多不同的东西!

\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}

下面是由此产生的图像,如您所见,存在以下一些问题:

  • 内容不对齐
  • 列格式不起作用,只显示 ls 和 Xs
  • 标题不存在
  • 我收到很多错误放置的对齐制表符(&)错误 - 是因为\thead命令不起作用吗?
  • \end{center}线路似乎抛出了一些与此有关的错误\begin{document}?!

无论如何,我知道这现在是一堆垃圾,但我已经花了几个小时尝试不同的事情并想要摆脱它......它不可能那么难,但对我来说显然如此。

但是,它至少超过了两页(因此下面有两张图片)。

在此处输入图片描述

在此处输入图片描述

答案1

我已将所做的更改添加至内联注释中:

\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}

答案2

列  X类型需要tabularx环境,并且您必须设置表格的总宽度。该la tablex包将longtable功能带入tabularx,如果您添加指令,则列在各个页面上的宽度将相同\keepXColumns(如果没有此指令,则计算的宽度为X列宽度将是最大限度X 列的宽度。

您必须使用语法longtable,的语法第一头最后一脚部分。通常,标题设置为里面表中第一头部分。

\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} 

在此处输入图片描述 在此处输入图片描述

相关内容