floatrow
设置似乎会中断xltabular
,但仅在某些情况下。如果所有列都有X
,它将正常工作。另请注意,tabularx
不会受到影响。
考虑以下 MWE:
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{tabularx}
\usepackage{xltabular}
\usepackage{floatrow}
\usepackage{booktabs}
\floatsetup[table]{font = small, capposition = top}
\begin{document}
\begin{xltabular}{\linewidth}{|ccX|}
\caption{Not correct.} \\
\toprule
1 & 2 & 3 \\
\bottomrule
\end{xltabular}
\begin{xltabular}{\linewidth}{|ccX|}
\caption{Not correct either.} \\
\toprule
1 longer text & 2 emmm & 3 \\
\bottomrule
\end{xltabular}
\begin{xltabular}{\linewidth}{|XXX|}
\caption{But this works.} \\
\toprule
1 longer text & 2 emmm & 3 \\
\bottomrule
\end{xltabular}
\null
\begin{table}[h]
\caption{No problem for \texttt{tabularx}.}
\begin{tabularx}{\linewidth}{|ccX|}
\toprule
1 longer text & 2 emmm & 3 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案1
这是我查看.sty
源文件后找到的解决方案。
floatrow
和xltabular
都对 有一些定义\LTxxx
,因此floatrow
在 之前加载xltabular
可以解决宽度问题。关于floatrow
和 的一些相关讨论longtable
是这里。
副作用是\floatsetup
现在字体设置不再适用。作为一种解决方法,我们可以\renewenvironment
将xltabular
字体大小硬编码到其中。
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{tabularx}
\usepackage{floatrow}
\usepackage{xltabular}
\usepackage{booktabs}
\makeatletter
\renewenvironment{xltabular}[1][x]%
{%
\small % <-- font size change
\par
\if l#1%
\LTleft\z@ \LTright\fill
\else\if r#1%
\LTleft\fill \LTright\z@
\else\if c#1%
\LTleft\fill \LTright\fill
\fi\fi\fi
\let\TX@endtabularx=\XLT@ii@TX@endtabularx
\let\endtabularx\endxltabular
\XLT@ii@tabularx}
{\def\@currenvir{tabularx}}
\makeatletter
\floatsetup[table]{font = small, capposition = top}
\begin{document}
\begin{xltabular}{\linewidth}{|ccX|}
\caption{Not correct.} \\
\toprule
1 & 2 & 3 \\
\bottomrule
\end{xltabular}
\begin{xltabular}{\linewidth}{|ccX|}
\caption{Not correct either.} \\
\toprule
1 longer text & 2 emmm & 3 \\
\bottomrule
\end{xltabular}
\begin{xltabular}{\linewidth}{|XXX|}
\caption{But this works.} \\
\toprule
1 longer text & 2 emmm & 3 \\
\bottomrule
\end{xltabular}
\null
\begin{table}[h]
\caption{No problem for \texttt{tabularx}.}
\begin{tabularx}{\linewidth}{|ccX|}
\toprule
1 longer text & 2 emmm & 3 \\
\bottomrule
\end{tabularx}
\end{table}
ALL is working now.
\end{document}