10

I have a macro that creates itemize environment in it. The issue is that I have extra space after the itemize environment when used in longtable. How to remove the space?

\documentclass{memoir}
\usepackage{enumitem}
\usepackage{longtable}
\usepackage{booktabs}

\newcommand{\fuda}[2]{%
Functions:%
\begin{itemize}[nosep]
#1%
\end{itemize}
Data:%
\begin{itemize}[nosep]
#2%
\end{itemize}
}
\begin{document}
\begin{longtable}{p{0.3\textwidth}|p{0.7\textwidth}}
\caption[List of components]{List of functions and data allocated to each component} \label{d_plan} \\
\toprule
\textbf{Components} & \textbf{Functions and Data} \\\midrule
\textbf{Registration} & \fuda{
\item Register capabilities of the device
\item Unregister capabilities of the device
\item Register context representation 
}{
\item  Interface List 
\item Capability List
\item  Protocol List
\item Representation List}
\\\bottomrule
\end{longtable}
\end{document}

enter image description here

ADDED

The solution that uses -\baselineskip: works with article class, but not with memoir class.

3 Answers 3

16

A p column entry in a table ends with essentially

\unskip \strut \par \egroup \hfil

so after your list you get a \strut added which appears on a newline. You can back-up with -\baselineskip:

Sample output

\documentclass{article}
\usepackage{enumitem}
\usepackage{longtable}
\usepackage{booktabs}

\newcommand{\fuda}[2]{%
Functions:%
\begin{itemize}[nosep]
#1%
\end{itemize}
Data:%
\begin{itemize}[nosep]
#2%
\end{itemize}}

\begin{document}

\begin{longtable}{p{0.25\textwidth}|p{0.7\textwidth}}
\caption[List of components]{List of functions and data allocated to each component} \label{d_plan} \\
\toprule
\textbf{Components} & \textbf{Functions and Data} \\\midrule
\textbf{Registration} &\fuda{\item Register capabilities of the device
\item Unregister capabilities of the device
\item Register context representation 
}{\item  Interface List 
\item Capability List
\item  Protocol List
\item Representation List}\vspace*{-\baselineskip}
\\\bottomrule
\end{longtable}

\end{document}

The same applies to p cells in ordinary tables.

Added in the memoir class the definition of \@endpbox is a little difference and you will need to write

 \vspace*{-\baselineskip}\leavevmode

instead of just the \vspace* command.

1
  • This solution works with article, but with memoir it doesn't work.
    – prosseek
    Oct 31, 2013 at 18:27
6

enter image description here

\documentclass{memoir}
\usepackage{enumitem}
\usepackage{longtable}
\usepackage{booktabs}

\newcommand{\fuda}[2]{%
Functions:%
\begin{itemize}[nosep]
#1%
\end{itemize}
Data:%
\begin{itemize}[nosep]
#2%
\end{itemize}}

\begin{document}

\begin{longtable}{p{0.25\textwidth}|p{0.7\textwidth}}
\caption[List of components]{List of functions and data allocated to each component} \label{d_plan} \\
\toprule
\textbf{Components} & \textbf{Functions and Data} \\\midrule
\textbf{Registration} &\fuda{\item Register capabilities of the device
\item Unregister capabilities of the device
\item Register context representation 
}{\item  Interface List 
\item Capability List
\item  Protocol List
\item Representation List}
\vspace{-\baselineskip}\mbox{}
\\\bottomrule
\end{longtable}

\end{document}
4

Or you can use a minipage.

\newcommand{\fuda}[2]{%
\begin{minipage}[t]{\linewidth}
Functions:%
\begin{itemize}[nosep]
#1%
\end{itemize}
Data:%
\begin{itemize}[nosep]
#2%
\end{itemize}
\end{minipage}}

Full code:

\documentclass{memoir}
\usepackage{enumitem}
\usepackage{longtable}
\usepackage{booktabs}

\newcommand{\fuda}[2]{%
\begin{minipage}[t]{\linewidth}
Functions:%
\begin{itemize}[nosep]
#1%
\end{itemize}
Data:%
\begin{itemize}[nosep]
#2%
\end{itemize}
\end{minipage}}

\begin{document}

\begin{longtable}{p{0.25\textwidth}|p{0.7\textwidth}}
\caption[List of components]{List of functions and data allocated to each component} \label{d_plan} \\
\toprule
\textbf{Components} & \textbf{Functions and Data} \\\midrule
\textbf{Registration} &\fuda{\item Register capabilities of the device
\item Unregister capabilities of the device
\item Register context representation
}{\item  Interface List
\item Capability List
\item  Protocol List
\item Representation List}
\\\bottomrule
\end{longtable}

\end{document}

enter image description here

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.