[Tex/LaTex] Make last column take all remaining space in longtable

longtabletables

I want to create a table using longtable where all columns have a fixed length except the last one, which should take all remaining space. The table itself should be full page width.

I tried the following with longtable, but it is not working:

\documentclass{article}

\usepackage{longtable}
\usepackage{tabu}
\usepackage{array}
\usepackage{booktabs}

\setlength\parindent{0pt}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}

\begin{document}

\begin{longtable}[h]{p{2cm}l@{\extracolsep{\fill}}}
\toprule
Icon   & Description \\
\midrule
Icon 1 & Means this and that \\
Icon 2 & Means some other thing \\
\bottomrule
\end{longtable}

\end{document}

With tabu I would achieve something like this as follows:

\begin{tabu} to \textwidth {p{2cm}X}

Here's an online example: https://es.sharelatex.com/project/555e01773b14e98f7d55ed84

How to do the same using longtable?

Edit: I know I can do this with other environments. The question is specifically whether this can be achieved with longtable.

Best Answer

You can use the ltablex package, which brings the functionalities of longtable in tabularx environments:

\documentclass{article}

\usepackage[ nomarginpar]{geometry}%showframe,
\usepackage{ragged2e}
\usepackage{array}
\usepackage{ltablex}
\keepXColumns
\usepackage{booktabs}
\usepackage{lipsum}

\setlength\parindent{0pt}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\raggedbottom
\begin{document}

\begin{tabularx}{\linewidth}{p{2cm}>{\arraybackslash}X}
  \caption{A demo of the possibilities of \texttt{ltablex}}
  \\ \toprule
  Icon & Description\medskip
  \endfirsthead
  \midrule
  Icon & Description\medskip% \
  \endhead
  \midrule
  \endfoot
  \bottomrule
  \endlastfoot%\\
         & \lipsum[1] \\
  \midrule
  Icon 1 & Means this and that \lipsum[2] \\
  Icon 2 & Means some other thing\lipsum[3] \\
  Icon 3 & Means this and that \lipsum[4] \\
  Icon 4 & Means some other thing\lipsum[5]
\end{tabularx}

\end{document} 

enter image description here

Related Question