我有一张长表格,上面有很多行和列,分布在很多页上。由于标题太长,我无法正确看到整个表格内容。当我尝试使用较短的标题编写代码时,表格看起来没问题。有办法解决吗?任何帮助我都感激不尽。我也愿意接受其他简单的长表格模板。
\begin{longtable}
{|l|l|l|l|c|l|l|l|c|c|c|}
\hline
\textbf{n} &\textbf{$M$} &\textbf{$A_s$} &\textbf{$A_d$} &\textbf{Space} &\textbf{$D_m$} &\textbf{$D_s$} &\textbf{$D_d$} &\textbf{Delay} &\textbf{Space x Delay} &\textbf{Algorithm} \\
\hline
\endfirsthead
\multicolumn{11}{c}%
{\textit{ Continued from previous page} } \\
\hline
\textbf{n} &\textbf{$M$} &\textbf{$A_s$} &\textbf{$A_d$} &\textbf{Space} &\textbf{$D_m$} &\textbf{$D_s$} &\textbf{$D_d$} &\textbf{Delay} &\textbf{Space x Delay} &\textbf{Algorithm} \\
\hline
\endhead
\hline \multicolumn{11}{c}{\tablename\ \thetable \text{: }{Polynomial Multiplication Delay Optimization Result \protect(No Padding, $M=A_s=A_d$, $D_m=D_s=D_d$)}} \\
\endfoot
\hline
\caption{Polynomial Multiplication Delay Optimization Result (No Padding, $M=A_s=A_d$, $D_m=D_s=D_d$)}
\endlastfoot
\label{Table:Polynomial Multiplication-1}
1&1&0&0&1&1&0&0&1&1&Initial Condition\\
2&4&0&1&5&1&2&0&3&15&SB\\
\end{longtable}
答案1
- 我宁愿使用
xltabular
包而不是longtable
。它规定了表格宽度(例如等于\textwidth
) - 对于这两个标题我都会使用
\caption
命令(参见下面的 MWE) - 在表格底部插入标题是不常见的,这需要一些技巧来为中间标题腾出空间,更重要的是,在使用包时
xltabular
,会使标题编号变得复杂。
梅威瑟:
\documentclass{article}
%\usepackage{geometry}
\usepackage{makecell, xltabular}
\renewcommand\theadfont{\bfseries}
\usepackage[font=small, labelfont=bf]{caption}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\begin{document}
\listoftables
\section{Long table}
\lipsum[1-3]
\begingroup
\small
\setlength\tabcolsep{4pt}
\addtocounter{table}{1}
\begin{xltabular}{\textwidth}{|r|l|l|l|c|l|l|l|c|c|>{\centering\arraybackslash}X|}
\hline
\thead{n} & \thead{$M$} & \thead{$A_s$} & \thead{$A_d$}
& \thead{Space} & \thead{$D_m$} & \thead{$D_s$}
& \thead{$D_d$} & \thead{Delay} & \thead{Space x\\ Delay}
& \thead{Algorithm} \\
\hline
\endfirsthead
\multicolumn{11}{c}%
{\textit{ Continued from previous page} } \\
\hline
\thead{n} & \thead{$M$} & \thead{$A_s$} & \thead{$A_d$}
& \thead{Space} & \thead{$D_m$} & \thead{$D_s$}
& \thead{$D_d$} & \thead{Delay} & \thead{Space x\\ Delay}
& \thead{Algorithm} \\
\hline
\endhead
\hline
\multicolumn{11}{c}{}\\[-3ex]
\caption[]{Polynomial Multiplication Delay Optimization Result (No Padding, $M=A_s=A_d$, $D_m=D_s=D_d$)}
\smallskip
\addtocounter{table}{-1}
\endfoot
\hline
\multicolumn{11}{c}{}\\[-3ex]
\caption[Polynomial Multiplication Delay Optimization Result]
{Polynomial Multiplication Delay Optimization Result (No Padding, $M=A_s=A_d$, $D_m=D_s=D_d$)}
\endlastfoot
\label{Table:Polynomial Multiplication-1}
%
1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
2 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
3 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
4 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
5 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
6 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
7 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
8 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
9 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
10 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
11 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
12 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
\end{xltabular}
\endgroup
\end{document}
(红线表示页面布局)
附录(题外话):
我会以更常见和“专业”的方式设计您的表格:
- 表格顶部的标题
- 表格底部有表格续表的注释
- 对于数字使用
siunitx
包 - 删除垂直线
对于表格,我应该使用tabularray
表格及其库siunitx
(它加载siunitx
包)。表格的最终形式只需要一次编译。
\documentclass{article}
%\usepackage{geometry}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\ExplSyntaxOn
\NewChildSelector{eachtwo}
{
\int_step_inline:nnnn {2}{2}{\l_tblr_childs_total_tl}
{ \clist_put_right:Nn \l_tblr_childs_clist {##1} }
}
\ExplSyntaxOff
\begin{document}
\listoftables
\section{Long table}
\lipsum[1-3]
%\small
\SetTblrStyle{contfoot-text}{font=\small\itshape, gray3}
\SetTblrStyle{caption-text}{font=\small}
\SetTblrStyle{caption-tag}{font=\small\bfseries}
\begin{longtblr}[
caption = {Polynomial Multiplication Delay Optimization Result (No Padding,\\ $M=A_s=A_d$, $D_m=D_s=D_d$)},
entry = {Polynomial Multiplication Delay Optimization Result},
label = {tab:tblr}
]{rowhead = 1,
colsep=5pt,
colspec={@{} Q[c, si={table-format=2.0}]
*{8}{c}
X[c, si={table-format=2.0}]
X[2,j]
@{} },
hline{1,Z} = 1pt, hline{2}=0.6pt,
row{1} = {mode=math},
row{2-Y} = {rowsep=-0.5pt},
row{eachtwo} = {abovesep=1ex},
}
% column headers
n & M & A_s & A_d
& \SetCell[c=1]{mode=text} Space
& D_m & D_s & D_d
& \SetCell[c=1]{mode=text} Delay
& \SetCell[c=1]{m,mode=text} {{{Space x Delay}}}
& \SetCell[c=1]{c,mode=text} Algorithm \\
% table body
1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
2 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
3 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
4 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
5 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
6 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
7 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
8 & 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
9 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
10& 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
11& 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & Initial Condition\\
12& 4 & 0 & 1 & 5 & 1 & 2 & 0 & 3 & 15 & SB\\
\end{longtblr}
\end{document}