# longtable as tabularx

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

• in preamble add package ltablex. For example see tex.stackexchange.com/questions/368444/… (answer in addendum). – Zarko May 9 '17 at 19:27
• you could use ltablex or ltxtable both of which combine tabularx and longtable, but really, I wouldn't. You do not need the complication of tabularx here you can simply calculate the width of your last column by subtracting the widths of the other columns from \textwidth – David Carlisle May 9 '17 at 19:31
• but the tabcolsep... how do I deal with it? – jlanza May 9 '17 at 19:33
• you know how many columns you have and each has two \tabcolsep so the last column is p{\dimexpr\textwidth-8\tabcolsep-5\arrayrulewidth-5.7cm-6cm-1.7cm} – David Carlisle May 9 '17 at 19:37
• @DavidCarlisle I like the idea. How can I set it like a formula for automatic calculation. Let's see it as a variable argument list of lenghts and then the size is automatically calculated – jlanza May 10 '17 at 14:24

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