6

I have the following (Non-working) example.

\renewcommand*{\arraystretch}{1.8}
\begin{longtable}{lcl}
    \caption{Summary of proven determinants for falling}\\ \toprule
    \label{tab:FallPredictionVariables}
    \textbf{Author} &\textbf{Subject count (M:F)} & \textbf{Determinants}\\
    \midrule

    \noindent Author 1 &
    1780 (?) & 
    \begin{itemize}%[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
        \item Recent falls (last 2 months)
        \item Agitation
        \item Frequent toileting
        \item Visual impairment
    \end{itemize}\\

    \noindent Author 2 &
    311 (?) &
    \begin{itemize}%[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
        \item Posture sway
        \item Two or more falls in previous year
        \item Low hand grip strength
        \item Depressive state of mind
    \end{itemize}\\
        \bottomrule

\end{longtable}

However, it works OK outside a longtable environment:

\renewcommand*{\arraystretch}{1.8}
\begin{table}
\centering
    \caption{Summary of proven determinants for falling} 
    \label{tab:FallPredictionVariables}
    \begin{tabular}{lcp{60mm}}
    \toprule
    \textbf{Author} &\textbf{Subject count (M:F)} & \textbf{Determinants}\\
    \midrule

    \noindent Author 1 &
    1780 (?) & 
    \begin{itemize}[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
        \item Recent falls (last 2 months)
        \item Agitation
        \item Frequent toileting
        \item Visual impairment
    \end{itemize}\\

    \noindent Author 2 &
    311 (?) &
    \begin{itemize}[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
        \item Posture sway
        \item Two or more falls in previous year
        \item Low hand grip strength
        \item Depressive state of mind
    \end{itemize}\\
        \bottomrule

        \end{tabular}

\end{table}

As you can see in the picture below, it does what I'm expecting (except there is some vertical space over the first item that I would like to remove, and the solutions posted in How to reduce vertical space itemize environment inside table only seem to work for tabularx environments).

enter image description here

I'm unable to make my code work inside longtable, and I really need it (the complete table is very long).

Any ideas for both things:

  1. To be able to have itemize inside longtable environment
  2. Eliminate the extra space for the first item

PS: This is the preamble for both examples:

\documentclass[a4paper,twoside,11pt,openright]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{longtable}  
\usepackage[inline]{enumitem}   
\usepackage{booktabs}

\begin{document}
...
\end{document}
7
  • code snippets a good, but MWE are better :)
    – cmhughes
    May 17, 2013 at 18:04
  • @cmhughes I'm really having a hard time telling the difference when to post the complete MWE or just the code snippet for the sake of space... I don't know if what I just did is the best approach May 17, 2013 at 18:05
  • related: A list inside a table
    – cmhughes
    May 17, 2013 at 18:12
  • 1
    @MarioS.E.: Most of us can't debug code by eyes alone. We have to copy and paste into a document, see what happens, poke it, see what happens, curse it, see what happens, etc. ... With an MWE we can get more quickly to the poking-and-cursing stage. Without it we have to manually type repetitive things like \documentclass...\begin{document}... and so on. Also we have to guess what packages are being loaded (especially annoying with multi-library packages like tikz and pgfplots), and it's a barrier to actually solving the problem. So MWE is always good if you want easy help. :-) May 17, 2013 at 19:00
  • To the question: couldn't multiple rows work just as easily? May 17, 2013 at 19:03

3 Answers 3

5

Without a full MWE, I've taken some code from Przemysław Scherwentke's answer:

enter image description here

\documentclass{report}
\usepackage{longtable}% http://ctan.org/pkg/longtable
\usepackage{array,booktabs,enumitem}% http://ctan.org/pkg/{array,booktabs,enumitem}
\newcolumntype{P}[1]{>{\endgraf\vspace*{-\baselineskip}}p{#1}}

\begin{document}

\renewcommand*{\arraystretch}{1.8}
\begin{longtable}{p{4cm}p{4cm}P{6cm}}
  \caption{Summary of proven determinants for falling}\label{tab:FallPredictionVariables} \\
  \toprule
  \textbf{Author} &\textbf{Subject count (M:F)} & \multicolumn{1}{l}{\textbf{Determinants}} \\
  \midrule

  \noindent Author 1 &
  1780 (?) & 
  \begin{itemize}[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
    \item Recent falls (last 2 months)
    \item Agitation
    \item Frequent toileting
    \item Visual impairment
  \end{itemize}\\

  \noindent Author 2 &
  311 (?) & 
  \begin{itemize}[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
    \item Posture sway
    \item Two or more falls in previous year
    \item Low hand grip strength
    \item Depressive state of mind
  \end{itemize}\\
  \bottomrule
\end{longtable}

\end{document}

The P{<len>} column type (thanks to array) inserts a "vertical unskip" so that the first item aligns properly with the remainder of the table.

The assumption is that the last P-column only contains lists, of course. If not, a separate \multicolumn has to be issued like with the heading Determinants.

6
  • Will it break properly at the end of a page? May 17, 2013 at 19:22
  • @Werner This \newcolumntype is a beautiful solution to obtain globally that I had changed locally. To remember! May 17, 2013 at 19:28
  • @Werner this is indeed a good practical solution to the problem at hand, but what are your thoughts about the original question? Is is possible to have an itemize inside a longtable environment? May 17, 2013 at 19:30
  • @MarioS.E.: As you can see I'm using itemize inside a longtable. It will break properly across rows, but not within a row (if you have a long itemize, say).
    – Werner
    May 17, 2013 at 19:34
  • @Werner thanks! that's the confirmation I was hoping :) May 17, 2013 at 19:45
7

The following is a working example. Because lcr are for one-line entries, itemize shouldn't work with them. Compare the first part, improved, with the second, unchanged.

\documentclass[a4paper,twoside,11pt,openright]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{longtable}  
%\usepackage[inline]{enumitem}   
\usepackage{enumitem}   
\usepackage{booktabs}


\begin{document}

\renewcommand*{\arraystretch}{1.8}
%\begin{longtable}{lcl}
\begin{longtable}{p{4cm}p{4cm}p{6cm}}
    \caption{Summary of proven determinants for falling}\\ \toprule
    \label{tab:FallPredictionVariables}
    \textbf{Author} &\textbf{Subject count (M:F)} & \textbf{Determinants}\\
    \midrule

    \noindent Author 1 &
    1780 (?) & \vspace{-\baselineskip}
    \begin{itemize}[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
        \item Recent falls (last 2 months)
        \item Agitation
        \item Frequent toileting
        \item Visual impairment
    \end{itemize}\\

    \noindent Author 2 &
    311 (?) &
    \begin{itemize}%[label={--},noitemsep,leftmargin=*,topsep=0pt,partopsep=0pt]
        \item Posture sway
        \item Two or more falls in previous year
        \item Low hand grip strength
        \item Depressive state of mind
    \end{itemize}\\
        \bottomrule

\end{longtable}

\end{document}

enter image description here

1
  • 1
    Thanks for the "\vspace{-\baselineskip}" part, that seems to solve a similar issue I had. Nov 7, 2017 at 15:58
4

I thought you could achieve this effect without having to hack an itemize. Just use multiple rows of the table:

\documentclass{report}
\usepackage{longtable}% http://ctan.org/pkg/longtable
\usepackage{array,booktabs}

\begin{document}

\begin{longtable}{p{4cm}p{4cm}>{-- }p{6cm}}
  \caption{Summary of proven determinants for falling}\label{tab:FallPredictionVariables} \\
  \toprule
  \textbf{Author} &\textbf{Subject count (M:F)} & \multicolumn{1}{l}{\textbf{Determinants}} \\
  \midrule

  \noindent 
  Author 1 & 1780 (?) & Recent falls (last 2 months) \\
           &          & Agitation                    \\
           &          & Frequent toileting           \\ 
           &          & Visual impairment            \\[1.8\baselineskip]

  Author 2 & 311 (?)  & Posture sway                 \\
           &          & Two or more falls in previous year \\
           &          & Low hand grip strength \\
           &          & Depressive state of mind \\               
\end{longtable}
\end{document}

sample code output

2

You must log in to answer this question.

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