1

I have a longtable in Overleaf, however I need to add 2 more columns, therefore I would like my longtable to fill the entire page. I just cannot find a way to alter my table. Any ideas?

Current picture of table enter image description here

Code of table

\begin{center}
\begin{longtable}{|p{0.13\textwidth}|p{0.22\textwidth}|p{0.42\textwidth}|p{0.42\textwidth}|p{0.42\textwidth}|p{0.42\textwidth}}
\caption{xxxxxxxxxx} \label{xxxxxx} \\

\hline \rowcolor{lightgray} \multicolumn{1}{|c|}{\textbf{xxxxx}} & \multicolumn{1}{c|}{\textbf{xxxxx}} & \multicolumn{1}{c|}{\textbf{xxxxxx}} & \multicolumn{1}{c|}{\textbf{(xxxxx}} & \multicolumn{1}{c|}{\textbf{xxxxxx}} \\ \hline 
\endfirsthead

\multicolumn{3}{c}%
{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
\hline \rowcolor{lightgray} \multicolumn{1}{|c|}{\textbf{xxxx}} & \multicolumn{1}{c|}{\textbf{xxxx}} & \multicolumn{1}{c|}{\textbf{xxxxx}} & \multicolumn{1}{c|}{\textbf{(xxxx}} & \multicolumn{1}{c|}{\textbf{xxxx}} \\ \hline 
\endhead

\hline \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\endfoot

\hline \hline
\endlastfoot

\multirow{6}{*}{\rotatebox[origin=c]{90}{\textbf{Direct}}} & Method & x & 
Advantages: \par
(1) xxx \par
(2) xxx \par
Disadvantages: \par
(1) xxx \par
(2) xxx \par
& x   \\ 
 & Method & x & 
 Advantages: \par
(1) xxx \par
(2) xxx \par
Disadvantages: \par
(1) xxx \par
(2) xxx \par
& x \\ 
 & Method & x & 
 Advantages: \par
(1) xxx \par
(2) xxx \par
Disadvantages: \par
(1) xxx \par
(2) xxx \par
& x\\ 
 & Method & x & 
 Advantages: \par
(1) Tx \par
(2) x \par
Disadvantages: \par
(1) x  \par
(2) x \par \\
 & Method & x & 
  Advantages: \par
(1) xxx \par
(2) xxx \par
Disadvantages: \par
(1) x \par
(2) xxx \par
& x  \\
 & Method & x & 
 Advantages: \par
(1) xxx \par
(2) xxx \par
Disadvantages: \par
(1) xxx \par
(2) xxx \par
& x  \\
\multirow{1}{*}{\rotatebox[origin=c]{90}{\textbf{Indirect}}} & Method & x & 
Advantages: \par
    (1) x \par 
    (2) xx \par
Disadvantages: \par 
    (1) x \par
    (2) x \par
    (3) x. \par 
& x  \\
% & x & x & 
%  Advantages: \par
% (1) xxx \par
% % (2) xxx \par
% Disadvantages: \par
% (1) xxx \par
% (2) xxx \par
% x \\ \hline
 
\multirow{2}{*}{\rotatebox[origin=c]{90}{\textbf{Independent}}}  & Method & x & 
Advantages: \par
(1) xxx \par
(2) xxx \par
Disadvantages: \par
(1) xxx \par
(2) xxx \par
& x \\
 & Method & x & 
 Advantages: \par
(1) xxx \par
(2) xxx \par
Disadvantages: \par
(1) xxx \par
(2) xxx \par
& x  \\ \hline
\end{longtable}
\end{center}

PACKAGES

\documentclass[a4paper]{report} 
\usepackage{multirow} %table
\usepackage{xcolor,colortbl}
\usepackage{pdflscape}
\usepackage{longtable}
\usepackage{graphicx}

Example after using code by Zarko enter image description here

8
  • 1
    Welcome to SE. Please provide a Minimal working example: a compilable piece of code that contains just enough to show your problem. There are a lot of packages here that are probably irrelevant for the problem at hand.
    – Miyase
    Jun 6, 2022 at 17:47
  • @Miyase Thank you for the comment! I reduced the list of packages to just the relevant ones.
    – majapo
    Jun 6, 2022 at 17:54
  • Thanks, but your code is still incomplete (no \begin{document}?) and it's fragmented into several parts. Keep it in one piece so that people can copy-paste it easily.
    – Miyase
    Jun 6, 2022 at 17:56
  • you are forcing the columns to be wider than needed withp{0.22\textwidth} alsonever use center with longtable Jun 6, 2022 at 17:58
  • 1
    clearly you can not have 4 columns that are .42\textwidth wide and have the total be less than \textwidth and so fit on the page. That is simple arithmetic, nothing particularly about longtable Jun 6, 2022 at 18:34

1 Answer 1

0

I suggest using xltabular, a combination of tabularx and longtable packages, instead of longtable:

\documentclass[arpaper]{report}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor}
\usepackage{ragged2e}
\usepackage{rotating}
\usepackage{makecell, multirow, xltabular}
\renewcommand\theadfont{\bfseries\small}
\newcolumntype{R}{>{\RaggedRight}X}
\usepackage{pdflscape}

\usepackage{lipsum}

\begin{document}
\begin{landscape}
    \setlength\LTcapwidth\linewidth
    \settowidth\rotheadsize{\textbf{Independent}}
    \setlength\extrarowheight{2pt}
\begin{xltabular}{\linewidth}{| c | *{6}{R|}}
\caption[blabla]{\lipsum*[66]}
\label{tab:primer}                              \\  
    \hline
    \rowcolor{lightgray}
\thead{Category}
    &   \thead{Tehnique}
        &   \thead{Description}
            &   \thead{Dis)advantages}
                &   \thead{Example}              
                    &   \thead{xxxxx}
                        &   \thead{xxxxxx}      \\
    \hline
\endfirsthead
\caption[]{\lipsum*[66] (Cont.)}                \\
    \hline
    \rowcolor{lightgray}
\thead{xxxxx}
    &   \thead{xxxxx}
        &   \thead{xxxxxx}
            &   \thead{xxxxx}
                &   \thead{xxxxxx}
                    &   \thead{xxxxx}
                        &   \thead{xxxxxx}      \\
    \hline
\endhead
    \hline 
\multicolumn{7}{r}{\small\emph{Continued on next page}} \\ 
    \endfoot
    \hline
\endlastfoot
\multirow{3}{*}[3ex]{\rothead{Direct}}
    & Method 
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx 
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx         \\
    \hline
\multirow{6}{*}[3ex]{\rothead{Indirect}}
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx 
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx         \\
    \hline
\multirow{6}{*}[1ex]{\rothead{Independent}}
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx  
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx             \\
    \hline
\multirow{6}{*}[3ex]{\rothead{Indirect}}
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx  
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx             \\
\multirow{6}{*}[2ex]{\rothead{Direct}}
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx         \\
    \hline
\multirow{6}{*}[3ex]{\rothead{Indirect}}
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx         \\
\end{xltabular}
    \end{landscape}
\end{document}

enter image description here

Addendum: Regarding your comment(s): at width of columns you are restricted with text width. So you cannot define any width of column. Some reasonable measure which you can take are:

  • use smaller font, for example \small or \footnotesize )I don't recommend smaller)
  • change ratio between column width
  • for text in the first column header use use abbreviation, for example C.
\documentclass[arpaper]{report}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor}
\usepackage{ragged2e}
\usepackage{rotating}
\usepackage{makecell, multirow, xltabular}
\renewcommand\theadfont{\bfseries\small}
\newcolumntype{C}{>{\Centering}X}
\newcolumntype{R}{>{\RaggedRight}X}
\usepackage{pdflscape}

\usepackage{lipsum}

\begin{document}
\begin{landscape}
    \setlength\LTcapwidth\linewidth
    \settowidth\rotheadsize{\textbf{Independent}}
    \setlength\extrarowheight{2pt}
    \setlength\tabcolsep{3pt}
    \small
\begin{xltabular}{\linewidth}{|      >{\hsize=0.2\hsize}C |
                                *{2}{>{\hsize=0.7\hsize}R|}
                                *{4}{>{\hsize=1.10\hsize}R|}}
\caption[blabla]{\lipsum*[66]}
\label{tab:primer}                              \\
    \hline
    \rowcolor{lightgray}
\thead{C.}
    &   \thead{Tehnique}
        &   \thead{Description}
            &   \thead{Dis)advantages}
                &   \thead{Example}
                    &   \thead{xxxxx}
                        &   \thead{xxxxxx}      \\
    \hline
\endfirsthead
\caption[]{\lipsum*[66] (Cont.)}                \\
    \hline
    \rowcolor{lightgray}
\thead{xxxxx}
    &   \thead{xxxxx}
        &   \thead{xxxxxx}
            &   \thead{xxxxx}
                &   \thead{xxxxxx}
                    &   \thead{xxxxx}
                        &   \thead{xxxxxx}      \\
    \hline
\endhead
    \hline
\multicolumn{7}{r}{\small\emph{Continued on next page}} \\
    \endfoot
    \hline
\endlastfoot
\multirow{11}{*}{\rothead{Direct}}
    & \lipsum[1][1-1]
        & \lipsum[1][1-2]
            &   \lipsum[1][1-3]
                &   \lipsum[1][1-4]Method
                    &   \lipsum[66]
                        &   \lipsum[66]     \\
    \hline
\multirow{6}{*}[4ex]{\rothead{Indirect}}
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx         \\
    \hline
\multirow{6}{*}[1ex]{\rothead{Independent}}
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx             \\
    \hline
\multirow{6}{*}[3ex]{\rothead{Indirect}}
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx             \\
    \hline
\multirow{6}{*}[2ex]{\rothead{Direct}}
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx         \\
\end{xltabular}
    \end{landscape}
\end{document}

enter image description here

If you able to use (recent version of) tabularray package, than the table code is far simpler and not require manual tweaking of \multirow cells since in your table are not needed. For example:

\documentclass[arpaper]{report}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{xcolor}
\usepackage{rotating}
\usepackage{makecell}
\usepackage{tabularray}

\usepackage{pdflscape}

\usepackage{lipsum}

\begin{document}
\begin{landscape}
\begin{longtblr}[
caption = {\lipsum*[66]},
  entry = {blabla},
  label = {tab:primer}           
                ]{hlines, vlines,
                 colspec = {Q[c,m] 
                            *{2}{X[0.70, l,h]}
                            *{4}{X[1.15, l,h]}
                            },
                  colsep = 3pt,
                 cell{2-Z}{1} = {cmd=\rotcell[cc]},
                  row{1} = {font=\footnotesize\bfseries, c, bg=lightgray},
                 rowhead = 1,
                 vspan=even}
%%%% COLUMNS HEADERS
Cat.
    &   Tehnique 
        &   Description 
            &   advantages 
                &   Example 
                    &   xxxxx 
                        &   xxxxxx              \\
%%%% BODY 
Direct
    & \lipsum[1][1-1]
        & \lipsum[1][1-2]
            &   \lipsum[1][1-3]
                &   \lipsum[1][1-4]
                    &   \lipsum[66]
                        &   \lipsum[66]     \\
Indirect
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx         \\
Independent
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx             \\
Indirect
    & Method
        & x &   Advantages: \par
                (1) xxx \par
                (2) xxx \par
                Disadvantages: \par
                (1) xxx \par
                (2) xxx
                & Method
                    & x &   Advantages: \par
                            (1) xxx \par
                            (2) xxx \par
                            Disadvantages: \par
                            (1) xxx \par
                            (2) xxx             \\
\end{longtblr}
    \end{landscape}
\end{document}

enter image description here

7
  • This is great! Do you know by any change if it is possible to (1) change the width of the columns and/or (2) fill the page more (enlarge the table to the right and left of the page)?
    – majapo
    Jun 7, 2022 at 12:18
  • @majapo, width of X columns is determined by LaTeX so, that table has prescribed width. It can be increased on two ways: (i) by reducing width non X columns, or (ii) locally enlarge \textheight of page. Also may be a possibility to change widths ratios between columns but for this suggestion you need to provide more realistic content of table.
    – Zarko
    Jun 7, 2022 at 12:52
  • as you can see I have added a picture as an example. The issue is that columns 4 - 7 require more space, because the text falls off the page. Therefore, I think that I should (1) change the width of the first 3 columns and/or fill the table over the entire page (on the left and right). P.S. I took your code as an example!
    – majapo
    Jun 7, 2022 at 17:53
  • what is in the first column? Why is its column header empty? You can also use smaller font size ..
    – Zarko
    Jun 7, 2022 at 18:08
  • That is the category (direct, indirect or independent), excellent observation - I forgot to include the column header. I am afraid that a smaller font size will make it hard to read, especially once I print it out (I must do this for my thesis).
    – majapo
    Jun 8, 2022 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.