我正在申请如何使横向多页表适合文本宽度在这个例子中,为了使 longtable 适合 textwidth:
\documentclass{article}
\usepackage{longtable}
\usepackage{lipsum}
\begin{document}
\lipsum[1][1-4]
%\resizebox{\textwidth}{!}{
\begingroup % localize the following settings
\setlength\LTcapwidth{\textwidth} % default: 4in (rather less than \textwidth...)
\setlength\LTleft{0pt} % default: \parindent
\setlength\LTright{0pt} % default: \fill
\begin{longtable}{@{\extracolsep{\fill}}|l|rcc|rcc|rcc|rcc|}
longtable aaaaa aaaa aaaa aaa aaaa & 11.11 & 2 & 0.000 & 22.22 & 2 & 0.000 & 333.33 & 2 & 0.137 & 44.44 & 2 & 0.000\\
\end{longtable}
\endgroup
%}
\end{document}
然而,结果显示我并没有成功:
怎么了?
我检查了@DavidCarlisle 的答案。但是,建议的操作会导致以下问题\cline
:
\begingroup % localize the following settings
\setlength\LTcapwidth{\textwidth} % default: 4in (rather less than \textwidth...)
\setlength\LTleft{0pt} % default: \parindent
\setlength\LTright{0pt} % default: \fill
\tiny
\setlength{\tabcolsep}{0.4pt}
\begin{longtable}{@{\extracolsep{\fill}}|p{3cm}|rcc|rcc|rcc|rcc|}
Sample&\multicolumn{3}{c|}{AAAA}&\multicolumn{3}{c|}{BBBB}&\multicolumn{3}{c|}{CCCC}&\multicolumn{3}{c|}{DDDDD}\\\cline{2-13}
lllllllllongtable & 11.11 & 2 & 0.000 & 22.22 & 2 & 0.000 & 33.33 & 2 & 00.00 & 44.44 & 2 & 0.000\\
\end{longtable}
\endgroup
如何避免这个问题?
答案1
\documentclass{article}
\usepackage{longtable}
\usepackage{lipsum}
\begin{document}
\lipsum[1][1-4]
%\resizebox{\textwidth}{!}{ never scale tables!
\begingroup % localize the following settings
\setlength\tabcolsep{2pt}
\footnotesize
\setlength\LTcapwidth{\textwidth} % default: 4in (rather less than \textwidth...)
\setlength\LTleft{0pt} % default: \fill
\setlength\LTright{0pt} % default: \fill
\begin{longtable}{@{\extracolsep{\fill}}|p{2cm}|rcc|rcc|rcc|rcc|@{}}
longtable aaaaa aaaa aaaa aaa aaaa & 11.11 & 2 & 0.000 & 22.22 & 2 & 0.000 & 333.33 & 2 & 0.137 & 44.44 & 2 & 0.000\\
\end{longtable}
\endgroup
%}
\end{document}
答案2
一个带有包及其同名环境的解决方案xltabular
,它将 的功能带入longtable
。tabularx
我加载了geometry
包,以获得更合适的边距:
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{longtable}
\usepackage{ragged2e}
\usepackage{xltabular}
\usepackage{lipsum}
\begin{document}
\lipsum[1][1-4]
\begingroup % localize the following settings
\setlength\LTcapwidth{\textwidth} % default: 4in (rather less than \textwidth...)
\setlength\LTleft{0pt} % default: \parindent
\setlength\LTright{0pt} % default: \fill
\begin{xltabular}{\linewidth}{|>{\RaggedRight\arraybackslash}X|rcc|rcc|rcc|rcc|}
longtable aaaaa aaaa aaaa aaa aaaa & 11.11 & 2 & 0.000 & 22.22 & 2 & 0.000 & 333.33 & 2 & 0.137 & 44.44 & 2 & 0.000\\
\end{xltabular}
\endgroup
\end{document}