语境
我正在使用表格样式用于构建漂亮表格以呈现数据库模式和表格的包。
问题
但当表格长度超过 A4 纸时,我无法找到一种很好的拆分表格的方法(图 1)。
没有提到长桌在里面表格样式文档,但它依赖于表格环境或表格型包,这有帮助。
图 1:表格在页面末尾没有中断。使用以下代码渲染纺织机械制造商 5.0.2
在 Ubuntu 上18.04
。
麦利来
下面是一段代码,您可以随意将某一行复制 N 次,N 值可以取很大(例如 100):
\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{
left=2cm,
right=1.6cm,
top=2cm,
bottom=2cm,
footskip=30pt
}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{float}
\usepackage{tabularx}
\usepackage{tablestyles}
\renewcommand{\arraystretch}{1.1}
\usepackage{longtable}
\usepackage{booktabs}
%\usepackage{makecell} % buggy
%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%
\begin{table}[H]
\tablestyle[sansboldbw]
\centering
\caption{The long table.}
%\begin{tabular}{*{4}{p{0.24\textwidth}}} % nope, this doesn't adapt to the columns' content
%\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}*{4}{l}@{}} % buggy
% You can replace \begin{tabular} by \begin{longtable}
\begin{tabular}{p{0.29\linewidth}p{0.24\linewidth}p{0.22\linewidth}p{0.18\linewidth}}
\theadstart
\thead Column\_category &
\thead Type &
\thead Information1 &
\thead Information2 \\
\tbody
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
\tend
% You can replace \end{tabular} by \end{longtable}
\end{tabular}
\end{table}
\end{document}
用\begin{tabular}
和替换和没有任何效果。\end{tabular}
\begin{longtable}
\end{longtable}
有用的帖子
答案1
以下内容应该可以为您指明正确的方向。我已更正语法longtable
,并要求仅在第一页显示标题,而列标题将在所有后续页面上重复。我还调整了列宽,因为您的表格比文本宽度宽。您可能需要进行更多调整,并且可能希望将各个列中的文本更改为右对齐,而不是对齐文本。
\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{
left=2cm,
right=1.6cm,
top=2cm,
bottom=2cm,
footskip=30pt
}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{float}
\usepackage{tabularx}
\usepackage{tablestyles}
\renewcommand{\arraystretch}{1.1}
\usepackage{longtable}
\usepackage{booktabs}
%\usepackage{makecell} % buggy
\usepackage{calc}
\usepackage{showframe}
%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%
%\begin{table}[H]
\tablestyle[sansboldbw]
%\centering
%\caption{The long table.}
%\begin{tabular}{*{4}{p{0.24\textwidth}}} % nope, this doesn't adapt to the columns' content
%\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}*{4}{l}@{}} % buggy
% You can replace \begin{tabular} by \begin{longtable}
\begin{longtable}{p{0.31\linewidth-2\tabcolsep}p{0.26\linewidth-2\tabcolsep}p{0.22\linewidth-2\tabcolsep}p{0.21\linewidth-2\tabcolsep}}
\rowcolor{white}\caption{The long table.}\label{key}\\
\theadstart
\thead Column\_category &
\thead Type &
\thead Information1 &
\thead Information2 \\
\endfirsthead
\theadstart
\thead Column\_category &
\thead Type &
\thead Information1 &
\thead Information2 \\
\endhead
\tbody
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
Quisque laoreet ultricies fringilla. & Lorem ipsum dolor sit amet & Pellentesque accumsan & Morbi nec est lacus \\
\tend
% You can replace \end{tabular} by \end{longtable}
\end{longtable}
%\end{table}
\end{document}