![当同时使用表格和长表时,表格和标题之间的垂直边距相同](https://linux22.com/image/458960/%E5%BD%93%E5%90%8C%E6%97%B6%E4%BD%BF%E7%94%A8%E8%A1%A8%E6%A0%BC%E5%92%8C%E9%95%BF%E8%A1%A8%E6%97%B6%EF%BC%8C%E8%A1%A8%E6%A0%BC%E5%92%8C%E6%A0%87%E9%A2%98%E4%B9%8B%E9%97%B4%E7%9A%84%E5%9E%82%E7%9B%B4%E8%BE%B9%E8%B7%9D%E7%9B%B8%E5%90%8C.png)
我在文档中同时使用了“普通”表格和长表格。我只希望将长表格用于需要分页符的较长表格,较小的表格则希望浮动以适应最佳位置。我不希望所有表格都跨页。到目前为止一切顺利。
我唯一的问题是,两种类型的表格的标题工作方式不同。而对于长表,它基本上只是表格顶部的另一行,其边距与表格的所有其他行相同。对于“普通”表格,标题边距要大得多。在图片中,第一个表格是“普通”表格,第二个表格是长表
有什么好办法可以解决这个问题?提前谢谢您!
编辑 这是一个最小工作示例。在本例中,情况正好相反,但边距仍然彼此不同。
\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}