[Tex/LaTex] fit longtable to textwidth

fitlongtableresizetablestextwidth

I am applying How to fit landscape multi-page table to textwidth to fit longtable to textwidth in this example:

\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}

However, the outcome shows I haven't been successful:

enter image description here

What is wrong?

I check the answer of @DavidCarlisle. However, the proposed manipulations cause a problem with \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

enter image description here

How to avoid this problem?

Best Answer

\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}