2

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

6
  • 3
    in preamble add package ltablex. For example see tex.stackexchange.com/questions/368444/… (answer in addendum).
    – Zarko
    Commented May 9, 2017 at 19:27
  • 1
    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 Commented May 9, 2017 at 19:31
  • but the tabcolsep... how do I deal with it?
    – jlanza
    Commented May 9, 2017 at 19:33
  • 3
    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} Commented May 9, 2017 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
    Commented May 10, 2017 at 14:24

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .