[Tex/LaTex] longtable as tabularx

longtablelongtabutablestabularx

I want to use longtable as tabularx, that is setting the width of the table and using the X cell type.

\begin{tabularx}{\textwidth}{|>{\footnotesize}L{5.7cm}|>{\footnotesize}L{6cm}|>{\footnotesize}C{1.7cm}|>{\footnotesize}X|}

I want something similar but with longtable as the table is extending multiple pages.

I have found tabu package but it seems that it is deprecated and people is advicing not to use it.

Any help

Best Answer

Based on @DavidCarlisle suggestion, here is my solution:

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\newcount\totalcol
\totalcol=3
\newdimen\cola
\cola=10cm
\newdimen\colb
\colb=2cm
\newdimen\colc
\colc=\dimexpr\textwidth-\tabcolsep*\totalcol*2-\arrayrulewidth*(1+\totalcol)-\cola-\colb\relax

\begin{longtable}{|L{\cola}|C{\colb}|L{\colc}|}
\hline
\multicolumn{3}{|c|}{\large\textbf{My Title}}\\
\hline
\centering\small{A} & \centering\small{B} & \centering\arraybackslash\small{C}\\
\hline
\endhead
\vspace{10pt}\\
\hline
\endfoot
%\input{data/books}

\end{longtable}

There problably should be an automated way of doing it, but it worked for me.

Related Question