5

any suggestions to make this long table looks better

my code and output :

  \documentclass[preprint,12pt,authoryear]{elsarticle}

    %-----------------------------------------------------------------------------------------
 \usepackage[margin=2cm]{geometry}
 \usepackage[figurename=Fig.]{caption}
\usepackage{tabulary}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{varioref}
\usepackage{multirow}
\usepackage{commath}
\usepackage{array,multirow}
\usepackage{threeparttable}  
 \usepackage{longtable}
 \usepackage{tabulary}
 \usepackage{booktabs}
 \usepackage{float}
  \usepackage{caption}
  \usepackage{subcaption}
  \usepackage{rotating}
  \usepackage{graphicx}
  \usepackage{setspace}
  \usepackage{varioref}  
  \usepackage[colorlinks,allcolors=blue]{hyperref}
  \usepackage[nameinlink,noabbrev]{cleveref} 
  \crefname{equation}{eq.}{eq.}
  \usepackage{amssymb}
 \usepackage{amsthm}
 \usepackage[utf8]{inputenc}
 \usepackage{ragged2e}
 \usepackage{booktabs, makecell, multirow, xltabular}
 \renewcommand\theadfont{\bfseries}
 \renewcommand\theadgape{}
 \newcolumntype{R}{>{\RaggedRight}X}
\newcommand\mcc[1]{\multicolumn{3}{c}{\emph{#1}}}
 %--------------------------------------------------------------------------------------------


   \usepackage{enumitem}


     \begin{document}

     \begingroup
     \setlist[itemize]{nosep, wide,
                 before=\vspace{-\baselineskip},
                after=\vspace{-\baselineskip}
                 }
    \begin{xltabular}{\linewidth}{@{} >{\small\bfseries%
                                  \raggedright\arraybackslash%
                                   \hsize=0.5\hsize}X
                                 >{\hsize=0.5\hsize}R
                                 >{\hsize=0.5\hsize}R
                               @{}}
    % table preamble
    \caption{Add caption}
    \label{tab:addlabel}                        \\
    \toprule
    \thead{Student}
      &   \thead{Description of\\ Key Variables}
        &   \thead{Survey Q}    \\
     \midrule
    \endfirsthead
    %\caption[]{Add caption (cont.)}                       \\
      \toprule

       \bottomrule
      \endlastfoot
     % table body
    \mcc{Mental}                       \\
     \cmidrule{1-3}
   WHO
     & Continuous 0 to 3. Average across the following statements. Over the last two weeks: 
   (1) I have felt cheerful and in good spirits; (2) I have felt calm and
  relaxed; (3) I have felt active and vigorous; (4) I woke up feeling fresh and rested and (5) 
      My 
     daily life has been filled with things that interest me. 

            &   \multirow{2}{=}
         {
          \begin{itemize}
           \item   Response options: (0) not at all, (1) some or little of the time, (2) occasionally or a moderate amount of time and (3) most of the time      
     \end{itemize}   
        }       \\
    \addlinespace[2pt]          
      Hopkins
           &   Continuous 0 to 3. Average across 23 statements. Over the last two weeks have 
        you 
         experienced: (1)
         feeling suddenly scared for no reason, (2) feeling fearful, (3) faintness, dizziness or weakness, (4) nervousness or shakiness inside, (5) heart pounding or racing, (6) trembling, (7) feeling tense or keyed up,
          (8) headache, (9) a spell of terror or panic, (10) feeling restless or can't sit still, (11) feeling low in energy or slowed down, (12) blaming yourself for things, (13) crying easily, (14) loss of sexual interest or pleasure, (15) poor appetite, (16) difficulty falling or staying asleep, (17) feeling hopeless about the future, (18) feeling lonely, (19) feeling of being trapped or caught, (20) worrying too much about things, (21) feeling no
         interest in things, (22) feeling everything is an effort, (23) feeling of worthlessness.
&   \multirow{2}{=}
    {
 \begin{itemize}
            \item  Response options are:(0) not at all, (1) some or little of the time, (2) occasionally or a moderate amount of time (3) most of the time.    
  \end{itemize}   
    }       \\
\addlinespace[2pt] 
\midrule
\mcc{Social cohesion}                    \\
\cmidrule{1-3}
        Problems
&   Continuous 0 to 2. Have you had any problems with the other households in this dwelling? 
    \vspace{2\baselineskip}
    &   \multirow{2}{=}{%
        \begin{itemize}
    \item   Response options: (0) no problems, (1) some problems, (2) many problems

        \end{itemize}   }       \\
\addlinespace[6pt]
\end{xltabular} 
\endgroup
    \end{document}

enter image description here enter image description here

3
  • Maybe you could make the first column not so wide, so the last two would be wider?
    – Bernard
    Commented Feb 20, 2022 at 9:25
  • @Bernard - The reason the first column is so wide is that the \hsize numbers sum to 1.5 instead of to 3. The quickest (though not necessarily best) fix would be to change the definition of the second column from >{\hsize=0.5\hsize}R to >{\hsize=1.5\hsize}R.
    – Mico
    Commented Feb 20, 2022 at 10:10
  • Does it need to all be in a single table? Perhaps some of the enumerated lists could be completely separate lists (just in the text) or tables? Commented Feb 20, 2022 at 18:03

3 Answers 3

3
  • I wonder
    • why you prescribe width to firs column. There are to much (disturbing) space between it and next column.
    • why you use multirow if no one cells need it?
  • Your table, as present in question, can be fit on one package (after redesign of columns).
  • A solution with xltabular can be:
\documentclass[preprint,12pt,authoryear]{elsarticle}
\usepackage[margin=2cm]{geometry}

\usepackage{microtype}  % new
\usepackage[figurename=Fig.]{caption}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, xltabular}
    \renewcommand\theadfont{\bfseries}
    \renewcommand\theadgape{}
\newcommand\mcc[1]{\multicolumn{3}{c}{\emph{#1}}}

\usepackage{enumitem}

\begin{document}
     \begingroup
\setlist[itemize]{nosep, wide,
             before=\vspace{-\baselineskip},
            after=\vspace{-\baselineskip}
             }
\begin{xltabular}{\linewidth}{@{} >{\bfseries}l XX @{}}
    % table preamble
\caption{Add caption}
\label{tab:addlabel}                                    \\
    \toprule
\thead{Student}
    &   \thead{Description of\\ Key Variables}
        &   \thead{Survey Q}                            \\
    \midrule
\endfirsthead
\caption[]{Add caption (cont.)}                         \\
    \toprule
\thead{Student}
    &   \thead{Description of\\ Key Variables}
        &   \thead{Survey Q}                            \\
\endhead
    \midrule
    \multicolumn{3}{r}{\footnotesize\textit{Continued on next page}}
\endfoot
    \bottomrule
      \endlastfoot
% table body
    \mcc{Mental}                                        \\
    \midrule    
    WHO
    & Continuous 0 to 3. Average across the following statements. Over the last two weeks:
   (1) I have felt cheerful and in good spirits; 
   (2) I have felt calm and
  relaxed; 
    (3) I have felt active and vigorous; 
    (4) I woke up feeling fresh and rested and 
    (5) My daily life has been filled with things that interest me.
        &   \begin{itemize}
        \item   Response options: (0) not at all, (1) some or little of the time, (2) occasionally or a moderate amount of time and (3) most of the time
            \end{itemize}                               \\
    \addlinespace
Hopkins
     &   Continuous 0 to 3. Average across 23 statements. Over the last two weeks have
        you experienced: 
        (1) feeling suddenly scared for no reason, 
        (2) feeling fearful, 
        (3) faintness, dizziness or weakness, 
        (4) nervousness or shakiness inside, 
        (5) heart pounding or racing, 
        (6) trembling, 
        (7) feeling tense or keyed up,
        (8) headache, 
        (9) a spell of terror or panic, 
        (10) feeling restless or can't sit still, 
        (11) feeling low in energy or slowed down, 
        (12) blaming yourself for things, 
        (13) crying easily, 
        (14) loss of sexual interest or pleasure, 
        (15) poor appetite, 
        (16) difficulty falling or staying asleep, 
        (17) feeling hopeless about the future, 
        (18) feeling lonely, 
        (19) feeling of being trapped or caught, 
        (20) worrying too much about things, 
        (21) feeling no interest in things, 
        (22) feeling everything is an effort, 
        (23) feeling of worthlessness.
        &   \begin{itemize}
        \item  Response options are:(0) not at all, (1) some or little of the time, (2) occasionally or a moderate amount of time (3) most of the time.
            \end{itemize}                                   \\
    \midrule
    \mcc{Social cohesion}                                   \\
    \midrule
Problems
    &   Continuous 0 to 2. Have you had any problems with the other households in this dwelling?
        &   \begin{itemize}
        \item   Response options: 
            (0) no problems, 
            (1) some problems, 
            (2) many problems
            \end{itemize}                                   \\
    \addlinespace[6pt]
\end{xltabular}
    \endgroup
\end{document}

enter image description here

** Addendum:** A solution with use of the \tabularray package:

\documentclass[preprint,12pt,authoryear]{elsarticle}
\usepackage[margin=2cm]{geometry}

\usepackage{microtype}  % new
\usepackage[figurename=Fig.]{caption}
\usepackage{ragged2e}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, varwidth}

\usepackage{enumitem}

\begin{document}
     \begin{table}[ht]
\setlist[itemize]{nosep, 
                  wide,
                  after=\end{minipage},                  % <---
                  before=\begin{minipage}[t]{\linewidth} % <---
                 }
\caption{Add caption}
\label{tab:addlabel}                                    
\begin{tblr}{colspec={@{} Q[l, font=\bfseries] 
                          X[2,j]
                          X[j]
                     @{}},
             row{1} = {font=\bfseries, c, m},
             measure = vbox
             }
    % table preamble
    \toprule
Student 
    &   {Description of\\ Key Variables}
        &   Survey Q                        \\
% table body
    \midrule
\SetCell[c=3]{c, font=\itshape}     Mental 
    &   &                                   \\
    \midrule    
WHO
    & Continuous 0 to 3. Average across the following statements. Over the last two weeks:
    (1) I have felt cheerful and in good spirits; 
    (2) I have felt calm and relaxed; 
    (3) I have felt active and vigorous; 
    (4) I woke up feeling fresh and rested and 
    (5) My daily life has been filled with things that interest me.
        &   \begin{itemize}
        \item   Response options: (0) not at all, (1) some or little of the time, (2) occasionally or a moderate amount of time and (3) most of the time
            \end{itemize}                   \\
Hopkins
     &   Continuous 0 to 3. Average across 23 statements. Over the last two weeks have
        you experienced: 
        (1) feeling suddenly scared for no reason, 
        (2) feeling fearful, 
        (3) faintness, dizziness or weakness, 
        (4) nervousness or shakiness inside, 
        (5) heart pounding or racing, 
        (6) trembling, 
        (7) feeling tense or keyed up,
        (8) headache, 
        (9) a spell of terror or panic, 
        (10) feeling restless or can't sit still, 
        (11) feeling low in energy or slowed down, 
        (12) blaming yourself for things, 
        (13) crying easily, 
        (14) loss of sexual interest or pleasure, 
        (15) poor appetite, 
        (16) difficulty falling or staying asleep, 
        (17) feeling hopeless about the future, 
        (18) feeling lonely, 
        (19) feeling of being trapped or caught, 
        (20) worrying too much about things, 
        (21) feeling no interest in things, 
        (22) feeling everything is an effort, 
        (23) feeling of worthlessness.
        &   \begin{itemize}
        \item  Response options are:(0) not at all, (1) some or little of the time, (2) occasionally or a moderate amount of time (3) most of the time.
            \end{itemize}                   \\
    \midrule
\SetCell[c=3]{c, font=\itshape}     Social cohesion 
    &   &                                   \\
    \midrule
Problems
    &   Continuous 0 to 2. Have you had any problems with the other households in this dwelling?
        &   \begin{itemize}
        \item   Response options: 
            (0) no problems, 
            (1) some problems, 
            (2) many problems
            \end{itemize}                   \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

enter image description here

3
  • When using X-type columns of varying widths, the main thing to keep track of is that the sum of the \hsize widths must equal the number of X-type columns. Your table has 3 X-type columns, but the \hsize lengths add up to 1.5, not 3. Moreover, there seems to be no good reason for not using the l column type for the first column. The first main recommendation, then, is that you use onle two X (or R) columns and set their relative widths to 1.333 and 0.667, respectively.

  • Next, there's an unusually high amount of code clutter in the third columns. For sure, do get rid of the \multirow wrapper. And, since each itemized list has only one \item statement, I think you can get of the itemize wrapper as well.

  • Finally, I'd wouln't use any bold-facing in the header row and column. It simply isn't needed -- and might needlessly cause a distraction as bold-facing can come across as (typographically) vulgar.

enter image description here

\documentclass[preprint,12pt,authoryear]{elsarticle} 
%---------------------------------------------------------------------
\usepackage[margin=2cm]{geometry}
\usepackage[figurename=Fig.]{caption}
\usepackage{tabulary}
\usepackage{tabularx}
%%%\usepackage{tabulary}
\usepackage{varioref}
\usepackage{multirow}
\usepackage{commath}
\usepackage{array,multirow}
\usepackage{threeparttable}  
 \usepackage{longtable}
 %%%\usepackage{tabulary}
 %%%\usepackage{booktabs}
 \usepackage{float}
  \usepackage{caption}
  \usepackage{subcaption}
  \usepackage{rotating}
  \usepackage{graphicx}
  \usepackage{setspace}
  %%%\usepackage{varioref}  
  \usepackage[colorlinks,allcolors=blue]{hyperref}
  \usepackage[nameinlink,noabbrev]{cleveref} 
  \crefname{equation}{eq.}{eq.}
  \usepackage{amssymb}
 \usepackage{amsthm}
 \usepackage[utf8]{inputenc}
 \usepackage{ragged2e}
 \usepackage{booktabs, makecell, multirow, xltabular}
 \renewcommand\theadfont{\bfseries}
 \renewcommand\theadgape{}
 \newcolumntype{R}{>{\raggedright\arraybackslash}X}
\newcommand\mcc[1]{\multicolumn{3}{c}{\emph{#1}}}
   
%--------------------------------------------------------------------

\usepackage{enumitem}

\begin{document}

\begingroup
\setlist[itemize]{nosep, wide=0pt,
                 before={\begin{minipage}[t]{\hsize}\raggedright},
                 after={\end{minipage}}
                 }

\begin{xltabular}{\linewidth}{@{} 
        l
        >{\hsize=1.333\hsize}R  % 1.333+0.667=2
        >{\hsize=0.667\hsize}R
        @{}}

% table preamble
    \caption{Add caption}
    \label{tab:addlabel} \\
    \toprule
    Student
    & Description of Key Variables
    & Survey Q   \\
    \midrule
    \endfirsthead
    %\caption[]{Add caption (cont.)}  \\
      
    \bottomrule
    \endlastfoot

% table body
\mcc{Mental} \\
\cmidrule{1-3}
WHO
& Continuous 0 to 3. Average across the following statements. Over the last two weeks: (1) I have felt cheerful and in good spirits; (2) I have felt calm and relaxed; (3) I have felt active and vigorous; (4) I woke up feeling fresh and rested and (5) My daily life has been filled with things that interest me. 
& Response options: (0)~not at all, (1) some or little of the time, (2)~occasionally or a moderate amount of time and (3) most of the time. \\
\addlinespace          
Hopkins
& Continuous 0 to 3. Average across 23 statements. Over~the last two weeks have you experienced: (1)~feeling suddenly scared for no reason, (2) feeling fearful, (3)~faintness, dizziness or weakness, (4)~nervousness or shakiness inside, (5) heart pounding or racing, (6)~trembling, (7) feeling tense or keyed up, (8)~headache, (9) a spell of terror or panic, (10)~feeling restless or can't sit still, (11) feeling low in energy or slowed down, (12) blaming yourself for things, (13)~crying easily, (14) loss of sexual interest or pleasure, (15) poor appetite, (16) difficulty falling or staying asleep, (17) feeling hopeless about the future, (18)~feeling lonely, (19) feeling of being trapped or caught, (20) worrying too much about things, (21)~feeling no interest in things, (22) feeling everything is an effort, (23) feeling of worthlessness.
& Response options: (0)~not at all, (1)~some or little of the time, (2)~occasionally or a moderate amount of time (3)~most of the time.  \\
\addlinespace
\midrule
\mcc{Social cohesion} \\
\cmidrule{1-3}
Problems
& Continuous 0 to 2. Have you had any problems with the other households in this dwelling? 
& Response options: (0)~no problems, (1)~some problems, (2)~many problems \\
\end{xltabular} 
\endgroup
\end{document}
2

If you change your code only here:

\begin{xltabular}{\linewidth}{@{} >{\small\bfseries%
            \raggedright\arraybackslash%
            \hsize=0.15\hsize}X
        >{\hsize=0.8\hsize}R
        >{\hsize=0.4\hsize}R
        @{}}
    % table preamble

you have this result:

enter image description here

(as you dont need the third column more large).

2
  • 1
    The \hsize sum in your code comes to 1.35. I think the outcome would be more robust if the \hsize sum were 3, which is the number of X-type columns.
    – Mico
    Commented Feb 20, 2022 at 10:07
  • 2
    Help! Gurus in action. Commented Feb 20, 2022 at 10:14

You must log in to answer this question.

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