因为某些原因,我需要使用tabularx
来排版表格,并且需要能够跨页。所以我选择ltablex
同时满足这两个需求。但是我发现tabularx
使用 会导致环境附近的内容超出下边界ltablex
。我该如何解决这个问题?是 固有的 bug 吗ltablex
?或者如果我想让跨页的表格同时支持 X 列,还有其他解决方案吗?
\documentclass[a4paper]{article}
\usepackage[left=3cm,right=3cm,top=3cm,bottom=3cm,footskip=0cm,headsep=0cm,headheight=0cm,showframe,showcrop]{geometry}
\usepackage{tabularx}
\usepackage{ltablex}
\usepackage{graphicx}
\renewcommand{\topfraction}{.8}
\begin{document}
\begin{figure}
\centering
\includegraphics[height=17cm,width=10cm]{fig}
\caption{A}
\end{figure}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\begin{table}
\caption{A}
\centering
\begin{tabularx}{\linewidth}{cX}
A & A\\
A & A\\
A & A\\
A & A\\
A & A\\
A & A\\
A & A\\
A & A\\
A & A\\
\end{tabularx}
\end{table}
\end{document}
答案1
考虑到@DavidCalisle 和部分@marv 注释,您的文档示例可以写成:
\documentclass[a4paper]{article}
\usepackage[margin=3cm,
showframe,showcrop]{geometry}
%\usepackage{tabularx} it loaded by ltablex
\usepackage{ltablex}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{graphicx}
\renewcommand{\topfraction}{.8}
\usepackage{lipsum}
\begin{document}
\begin{figure}
\centering
\includegraphics[height=16cm,width=10cm]{example-image-duck}
\caption{My lovely mr. Duck}
\end{figure}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\begin{tabularx}{\linewidth}{cX}
\caption{Long table using \texttt{ltablex} package}\\
\hline
\textbf{header 1}
& \textbf{header 2} \\
A & \lipsum[66] \\
B & \lipsum[66] \\
C & \lipsum[66] \\
D & \lipsum[66] \\
E & \lipsum[66] \\
F & \lipsum[66] \\
G & \lipsum[66] \\
H & \lipsum[66] \\
I & \lipsum[66] \\
J & \lipsum[66] \\
\hline
\end{tabularx}
\begin{longtblr}[
caption = {Long table set using \texttt{longtvlr} environment defined in \texttt{tabularray} package},
label = {tab:longtable}
]{
colspec = {c X[j]},
row{1} = {font=\bfseries},
rowhead = 1}
\toprule
header 1
& header 2 \\
\midrule
A & \lipsum[66] \\
B & \lipsum[66] \\
C & \lipsum[66] \\
D & \lipsum[66] \\
E & \lipsum[66] \\
F & \lipsum[66] \\
G & \lipsum[66] \\
H & \lipsum[66] \\
I & \lipsum[66] \\
J & \lipsum[66] \\
L & \lipsum[66] \\
L & \lipsum[66] \\
M & \lipsum[66] \\
N & \lipsum[66] \\
\bottomrule
\end{longtblr}
\end{document}