xltabular 环境中的标题宽度

xltabular 环境中的标题宽度

我正在创建一个表,如下所示:

\usepackage{xltabular}
\begin{document}
\begin{xltabular}[l]{\textwidth}{X | X | X | X}
    \caption{Here is a long text that does not break and exceeds the page margin}
    \label{Table 1}
    Text 1  & Text 2  & Text 3 & Text 4  
\end{xltabular}
\end{document}

我怎样才能强制标题根据 \textwidth 断开?

谢谢!

答案1

在当前形式下,代码无法编译,而是会抛出错误消息

Extra alignment tab has been changed to \cr.

xltabular内部间接加载longtable包,从而使其等效\caption 于。由于标题现在位于跨越表的所有列的命令\multicolumn{n}{c}{\parbox{\LTcapwidth}{...}}内,因此必须在其后跟一个,以防止出现前面提到的错误消息。\multicolumn\\

在此处输入图片描述

\documentclass{article}
\usepackage{xltabular}

\begin{document}


\begin{xltabular}[l]{\textwidth}{|X | X | X | X|}
    \caption{1 Here is a long text that does not break and exceeds the page margin  2 here is a long text that does not break and exceeds the page margin}
    \label{Table 1}  \\
    Text 1  & Text 2  & Text 3 & Text 4  
\end{xltabular}

\end{document}

为了确保xltabular文档中所有标题都占据整个文本宽度,您可以将其添加\setlength{\LTcapwidth}{\linewidth}到文档的序言中。

在此处输入图片描述

\documentclass{article}
\usepackage{xltabular}
\setlength{\LTcapwidth}{\linewidth} % make sure the caption takes up the whole linewidth

\begin{document}
        

\begin{xltabular}[l]{\textwidth}{|X | X | X | X|}
    \caption{1 Here is a long text that does not break and exceeds the page margin  2 here is a long text that does not break and exceeds the page margin}
    \label{Table 1}  \\
    Text 1  & Text 2  & Text 3 & Text 4  
\end{xltabular}

\end{document}

相关内容