3

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

Bernard
  • 271,350
J. Doe
  • 137
  • longtable is the same as tabular replace your c and l columns (which are one-line cells) by p{3cm} or whatever width you need. Also (unrelated) don't put longtable in a center environment. – David Carlisle Oct 07 '18 at 23:11
  • did you intend \\ where you have // in the shortstack? – David Carlisle Oct 07 '18 at 23:13
  • @DavidCarlisle that's such a silly mistake. I should've noticed it. Many thanks. – J. Doe Oct 07 '18 at 23:25
  • @DavidCarlisle I have replaced the

    \begin{longtable}{lcccl} with

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

    However that still does not wrap the texts to fit the column width. I have attached a picture with the original post.

    – J. Doe Oct 07 '18 at 23:28
  • you know how big your page is (you have not provided an example document so we do not know) choose suitable column widths the text will wrap to the specified column widths and the widths add up to whatever you make them add up to. – David Carlisle Oct 08 '18 at 07:04
  • @DavidCarlisle I don't think that is the issue. I intentionally made the table a lot smaller than the page, as can be seen from the heading row of the table. After a few trial and error I found out that this was caused by \shortstack function. While that function is in use, it prevents text wrapping. A better way to do this is by using \newline. – J. Doe Oct 08 '18 at 07:21
  • \shortstack works in longtable exactly as it works outside longtable, each cell in the stack is one line, so that's not really a longtable issue. But you have not provided an example that anyone can run so hard to debug your code. You should edit the question to fix the example code so it is a complete small document that shows the issue. (as Bernard did in his answer) – David Carlisle Oct 08 '18 at 09:00
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – samcarter_is_at_topanswers.xyz Nov 01 '18 at 00:09

1 Answers1

5

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

Bernard
  • 271,350