我需要此代码能够无错误地进行编译:
\documentclass{article}
\usepackage{tabularx}
\usepackage{amsmath, mathdots, paralist}
\usepackage{ltablex} % uncommenting this line will work
\begin{document}
\begin{tabularx}{\textwidth}{lX}
% & influential variables &
\textbf{Setting 1:} & This is my description $X_{\text{bla}} \in \{1, \hdots , 20\}$.\\
\textbf{Setting 2:} & This splits into
\begin{compactitem}
\item First item
\item Second item
\end{compactitem} \\
\end{tabularx}
\end{document}
我收到错误Something's wrong--perhaps a missing \item. \end{tabularx}
。如果我删除该行,\usepackage{ltablex}
它就会起作用。但是,我需要 ltablex 包,因此我正在寻找一种让上述代码可编译的可能性。有什么建议吗?
答案1
ltablex
变化确实太多了,如果你必须合并longtable
和tabularx
我可能会使用ltxtable
,但 99% 的时间我看到的表格设置为它们最好设置为列表,这样自然会扩展到全宽并自然地跨越页面,而不会出现和所做{lX}
的任何扭曲。tabularx
longtable
然而,ltablex
有一个\keepXColumns
可以使其更兼容:
\documentclass{article}
\usepackage{tabularx}
\usepackage{amsmath, mathdots, paralist}
\usepackage{ltablex} % uncommenting this line will work
\keepXColumns
\begin{document}
\begin{tabularx}{\textwidth}{lX}
% & influential variables &
\textbf{Setting 1:} & This is my description $X_{\text{bla}} \in \{1, \hdots , 20\}$.\\
\textbf{Setting 2:} & This splits into
\begin{compactitem}
\item First item
\item Second item
\end{compactitem} \\
\end{tabularx}
\end{document}
答案2
解决方法是将您的compactitem
环境插入合适大小的 \parbox 中。但是,环境的垂直间距存在一个小问题(见图)。可以使用enumitem
compact itemize 版本解决此问题。此外,enumitem
列表很容易定制。
\documentclass{article}
\usepackage{tabularx}
\usepackage{amsmath, mathdots, paralist}
\usepackage{ltablex} % uncommenting this line will work
\usepackage{enumitem}
\begin{document}
\begin{tabularx}{\textwidth}{lX}
% & influential variables &
\textbf{Setting 1:} & This is my description $X_{\text{bla}} \in \{1, \hdots , 20\}$.\\
\textbf{Setting 2:} & This splits into\par
\parbox{10cm}{%
\begin{compactitem}
\item First item
\item Second item
\end{compactitem}
}%
\\
\end{tabularx}
\begin{tabularx}{\textwidth}{lX}
% & influential variables &
\textbf{Setting 1:} & This is my description $X_{\text{bla}} \in \{1, \hdots , 20\}$.\\
\textbf{Setting 2:} & This splits into\par
\parbox{10cm}{%
\begin{itemize}[noitemsep, topsep=1pt, wide = 1em]
\item First item
\item Second item
\end{itemize}
}%
\\
\end{tabularx}
\end{document}