[Tex/LaTex] How to set longtable width to text width so that the text in cell wraps around automatically

borderlongtableoverlaptableswrap

Hi I usually use tabular to create my table. However I am currently in the process of creating a unavoidable huge multi-page table in landscape more. I am using TeXstudio 2.12.10. However I am having several issues with landscape longtable that after many hours of trying, I can to seem to fix. I was hoping that something can advice me with the following issues I am currently facing:

Prob 2: when I write long sentences on "samples" (column 4) "notes" (column 5), the text just keeps on going outside of the page border rather than wrapping around. Which brings us to problem number 2,

Prob 1: I cannot set the width of the table to \textwidth to limit the size of the table

Prob 3: \shortstack option that I implemented perfectly on tabular does not appear to work here as it is not dividing up the lines.

I am happy for the first 3 rows to be smalls as they will contain only a few words, but the last 2 columns must be able to wrap text around with the use of something like shortstack so I can write in different lines. Any advice. I have attempted the following 1, 2, 3 advice without a solution. Please do let me know if you have questions. With the codes provided below I get something like this:

enter image description here

%%%%%%%%%%%% latex code %%%%%%%%%%%%
\begin{landscape}
\begin{center}

\begin{longtable}{lcccl}

    \caption{A simple longtable example}                                \\
    \hline
    reference & technique & geometry & suspension   & notes             \\
    \hline
    \endfirsthead
    \multicolumn{5}{c}%
    {\tablename\ \thetable\ -- \textit{continued from previous page}} \\
    \hline
    reference & technique & geometry & suspension   & notes \\
    \hline
    \endhead
    \hline \multicolumn{5}{r}{\textit{continued on next page}} \\
    \endfoot
    \hline
    \endlastfoot

    \citet{AbbottEtAl_Experimental_1991}        & MR    & Couette   
    & \shortstack{particles: PMMA // $ \bar{\phi} = 39, 45, 50, 55, 60\% $} 
    & \shortstack{sample contained both unimodal and un-sieved particles \\ shows migration time scale is independent of $ \eta_f $ \\ presents transient concentration profiles of $ \bar{\phi} = 50\%$ \\ presents steady state migration profiles of $ \bar{\phi} = 45, 50 , 55\%$}\\        

\end{longtable}
\end{center}
\end{landscape}

Following the advice provided below I have amended

\begin{longtable}{lcccl}

with

\begin{longtable}{ p{3cm} p{1cm} p{2cm} p{3cm} p{5cm} }

While this DOES limit the table size, it does still does not wrap the text around.

enter image description here

Best Answer

Here is a solution with the xltabular package which mixes the properties of longtable and tabularx in its xltabular environment. I also use makecelland multirow:

\documentclass{article}
\usepackage{geometry}
\usepackage{lscape}
 \usepackage{array, ltablex, caption, multirow, makecell}
\usepackage{xltabular} 
\usepackage{natbib}
\newcommand\nl{\newline}

\begin{document}

 \begin{landscape}
\setlength{\extrarowheight}{3pt}
\begin{xltabular}{\linewidth}{lccc >{\arraybackslash}X}

    \caption{A simple longtable example}                                \\
    \hline
    reference & technique & geometry & suspension   & notes             \\
    \hline
    \endfirsthead
    \multicolumn{5}{c}%
    {\tablename\ \thetable\ -- \textit{continued from previous page}} \\
    \hline
    reference & technique & geometry & suspension   & notes \\
    \hline
    \endhead
    \hline \multicolumn{5}{r}{\textit{continued on next page}} \\
    \endfoot
    \hline
    \endlastfoot

    \citet{AbbottEtAl_Experimental_1991}        & MR    & Couette   
    & \multirowcell{2}{particles: PMMA \\ $ \bar{\phi} = 39, 45, 50, 55, 60\,\% $}
    & sample contained both unimodal and un-sieved particles \nl shows migration time scale is independent of $ \eta_f $
    \nl presents transient concentration profiles of $ \bar{\phi} = 50\%$ \nl presents steady state migration profiles of $ \bar{\phi} = 45, 50 , 55\,\%$
\end{xltabular}
\end{landscape}

\end{document} 

enter image description here