如何让表格扩展到多页?
我得到了一些关于 longtable 的建议,但无法让它在这种情况下发挥作用。下面的代码只能在一页中显示表格。我需要将表格扩展到多页。
\documentclass[journal]{IEEEtran}
\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{array}
\usepackage[caption=false,font=normalsize,labelfont=sf,textfont=sf]{subfig}
%\usepackage{textcomp}
\usepackage{stfloats}
\usepackage{url}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{cite}
\usepackage{booktabs,capt-of}
\usepackage{newtxtext, newtxmath}
\usepackage{array}
\usepackage{parskip}
\usepackage{mathtools}
\begin{document}
\begin{table*}[!t]
\centering
\caption{}
\label{}
\begin{tabular}{c|c|c|c}
\toprule
\textbf{No} &\textbf{C1} &\textbf{C3}&\textbf{C4} \\\midrule
1 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
2 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
3 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
4 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
5 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
6 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
7 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
8 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
9 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
10 & \begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\label{fig:third}
\end{minipage}\\\midrule
\end{tabular}
\end{table*}
\end{document}
答案1
- 在您的情况下,当文档有两列时,您有两个选择,可以在文档中插入长表格:
- 手动将表格拆分成两部分,每部分都用浮点数括起来,并使用包中的命令
table*
对标题进行编号\ContinuedFloat
caption
- 在表格之前将文档格式从两列更改为一列,并在表格之后恢复两列。此时您应该注意,进行此更改的命令(
\onecolumn
和twocolumn
)开始新页面。因此,此时表格前后通常会出现空白(据我所知,无法通过使用包删除这些空白afterpage
)
- 手动将表格拆分成两部分,每部分都用浮点数括起来,并使用包中的命令
第一个解决方案:
根据我对您之前的回答问题。为了将表格定位在插入的同一页的底部和下一页的顶部,使用stfloats
包:
\documentclass[journal]{IEEEtran}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum} % for dummy text
%---------------------------------------------------------------%
\usepackage{newtxtext, newtxmath}
\usepackage[export]{adjustbox} % it load graphicx too
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{caption} % <--- new
\usepackage{stfloats} % <--- new
\begin{document}
\lipsum
\begin{table*}[b]
\caption{Table with images}
\label{tab:image}
\adjustboxset{width=\linewidth, valign=M}
\begin{tblr}{hlines, vlines,
colsep=3pt,
colspec= {c *{3}{X[c,m]} },
row{1} = {font=\bfseries},
rowsep = 3pt,
}
No & C1 & C3 & C4 \\
1 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
2 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
3 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
\end{tblr}
\end{table*}
\begin{table*}[t]
\ContinuedFloat
\caption{Table with images}
\label{tab:image}
\adjustboxset{width=\linewidth, valign=M}
\begin{tblr}{hlines, vlines,
colsep=3pt,
colspec= {c *{3}{X[c,m]} },
row{1} = {font=\bfseries},
rowsep = 3pt,
}
No & C1 & C3 & C4 \\
4 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
5 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
6 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
7 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
\end{tblr}
\end{table*}
\lipsum\lipsum
\end{document}
第二种解决方案: 使用长桌,你需要在哪里
- 移除
table
浮动 - 用于表格使用
longtblr
包而不是tblr
- 对于从一列到另一列的改变以及返回的改变分别使用命令
\onecolumn
和\twocolumn
\documentclass[journal]{IEEEtran}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum} % for dummy text
%---------------------------------------------------------------%
\usepackage{newtxtext, newtxmath}
\usepackage[export]{adjustbox} % it load graphicx too
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\lipsum
\onecolumn
\adjustboxset{width=\linewidth, valign=M}
\begin{longtblr}[
caption = {Table with images},
label = {tab:image}
]{hlines, vlines,
colsep=3pt,
colspec= {c *{3}{X[c,m]} },
row{1} = {font=\bfseries},
rowsep = 3pt,
}
No & C1 & C3 & C4 \\
1 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
2 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
3 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
4 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
5 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
6 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
7 & \adjincludegraphics{example-image-a}
& \adjincludegraphics{example-image-b}
& \adjincludegraphics{example-image-c} \\
\end{longtblr}
\twocolumn
\lipsum
\end{document}
附录:
- 通过您的评论,您的问题变得不清楚,您的问题到底是什么。
- 据我所知,答案的原始版本解决了您问题中提到的所有问题。
- 网站不是论坛。如果您在使用收到的答案后发现有新问题,请提出新问题。评论中提出的(子)问题对其他人来说不太明显,这可能比对我更有帮助,因此您可以排除他们来帮助您。
- 关于您在以下评论中提出的最后一个请求:
- 仅在第一行有垂直线:
\begin{tblr}{hlines, vline{1-Z}={1}{solid}, % <---
colsep=3pt,
colspec= {c *{3}{X[c,m]} },
row{1} = {font=\bfseries},
rowsep = 3pt,
}
- 图像高度较小,例如其高度仅为 22 毫米:
\adjustboxset{width=\linewidth, height=22mm, valign=M}
- 有关其他选项,请参阅软件包文档。它们是 LaTeX 安装的一部分,也可在 CTAN(使用 Google)上使用。