我在文档中同时使用了“普通”表格和长表格。我只希望将长表格用于需要分页符的较长表格,较小的表格则希望浮动以适应最佳位置。我不希望所有表格都跨页。到目前为止一切顺利。
我唯一的问题是,两种类型的表格的标题工作方式不同。而对于长表,它基本上只是表格顶部的另一行,其边距与表格的所有其他行相同。对于“普通”表格,标题边距要大得多。在图片中,第一个表格是“普通”表格,第二个表格是长表 有什么好办法可以解决这个问题?提前谢谢您!
编辑 这是一个最小工作示例。在本例中,情况正好相反,但边距仍然彼此不同。
\documentclass{article}
\usepackage{longtable}
\begin{document}
\begin{longtable}[c]{| c | c |}
\caption{This is a longtable}\\
\hline
Something & something else\\
\hline
\endfirsthead
\hline
Something & something else\\
\hline
\endhead
\endfoot
\hline
\endlastfoot
Lots of lines & like this\\
Lots of lines & like this\\
Lots of lines & like this\\
end{longtable}
\begin{table}[ht!]
\centering
\caption{This is a normal table}
\begin{tabular}{|c|c|}
\hline
Lots of lines & like this\\
\hline
Lots of lines & like this\\
\hline
Lots of lines & like this\\
\hline
\end{tabular}
\end{table}
\end{document}
答案1
只需添加包caption
即可解决问题。然后您可以使用来设置标题\captionsetup[<float type>]{<options>}
。
\documentclass{article}
\usepackage{longtable}
\usepackage{caption} % needed <<<<<<<<<<<<<
\captionsetup[table]{labelfont=bf,textfont=it, skip= 5pt} % setup the table caption
\begin{document}
\begin{longtable}[c]{| c | c |}
\caption{This is a longtable}\\
\hline
Something & something else\\
\hline
\endfirsthead
\hline
Something & something else\\
\hline
\endhead
\endfoot
\hline
\endlastfoot
Lots of lines & like this\\
Lots of lines & like this\\
Lots of lines & like this\\
\end{longtable}
\begin{table}[ht!]
\centering
\caption{This is a normal table}
\begin{tabular}{|c|c|}
\hline
Lots of lines & like this\\
\hline
Lots of lines & like this\\
\hline
Lots of lines & like this\\
\hline
\end{tabular}
\end{table}
\end{document}