\documentclass[UTF8]{ctexart}
\usepackage{tabularx,fancyvrb}
\usepackage[margin=1cm,papersize={21cm,14.85cm}]{geometry}%\geometry{showframe}
\pagestyle{empty}
\newcommand*\cs[1]{\texttt{\textbackslash#1}}
\newcommand\B{Some nonsense text which fills at least one line of a tabular called nonsense tabular with text. }
\begin{document}
\begin{Verbatim}[frame=lines]
\captionaboveof{table}{Hello.}
\begin{tabularx}{\linewidth}{@{} lX @{}}
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
\end{tabularx}
\end{Verbatim}
% \captionaboveof{table}{Hello.}
\begin{center}
\begin{tabularx}{\linewidth}{@{} lX @{}}
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
left column & \B\\
l & \B\\
\end{tabularx}
\end{center}
\end{document}参考资料:
如果只需要 \captionof,不需要强制 above 或 below,caption 宏包就提供这个命令,必须用在一个环境内,不过最好是用 \captionsetup{type=...},这样可以正确处理超链接。
\begin{center}
\captionsetup{type=table...}
\caption{...}
...
\end{center}如果需要强制设置 caption 的位置,而不管 \caption 是放在图片/文字前面还是后面,那 \captionaboveof 的功能不是这个(至少现在的版本不是)。如果需要类似的功能,floatrow 宏包可以全局设置 caption 的位置,也可用它的 floatrow 环境配合 \ffigbox 等。
其实我是想自己翻译
texdoc xltabular这份.pdf文档,不过它对应的.tex源文件xltabular-doc.tex用到了\captionaboveof这个命令。然而我发现一个有意思的点,就是\captionaboveof这个命令居然不在浮动体table里面,而是使用了它之后直接跟上tabularx环境,而我找到\captionaboveof这个命令的定义后,却不懂其中的\@captionabovetrue,所以就有了这个问题。不过现在回想起来,我为什么不直接把作者写的用xltabular-doc.tex加一个ctex宏包,而非用ctexart呢?嗐!