# Aren't the sectioning commands supposed to work inside longtable?

Using sectioning commands such as section, subsection inside a longtable produce the following error:

! LaTeX Error: Something's wrong--perhaps a missing \item.


Is this normal?

Here is the code (created with LyX):

% Preview source code

%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage{longtable}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

\makeatother

\usepackage{babel}

\begin{document}
\begin{longtable}{|>{\centering}p{0.3\textwidth}|>{\raggedright}p{0.4\textwidth}|}
\hline
\section*{Name} & \section*{Description}\tabularnewline
\hline
\hline

a & b
\tabularnewline
\hline
a & b

\tabularnewline
\hline
a & b

\tabularnewline
\hline
\end{longtable}
\end{document}

-
Actually, I never heard of using \section commands inside longtable.... In this post I found a workaround that worked. –  henrique Jun 8 '11 at 12:09
@henrique I find it useful to have some cells containing headings (the astrisk versions to avoid having them in TOC). I checked the post you gave, but it's too complex, and Ulrike's solution below is simple & working. –  John Kirollos Jun 8 '11 at 14:07

Protect them:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage{longtable}

\begin{document}
\begin{longtable}{|p{0.3\textwidth}|p{0.4\textwidth}|}
\protect\section*{Name} & \protect\section*{Description}
\end{longtable}
\end{document}

-
Thanks, it's working, however, I couldn't do it in LyX (\section precedes \protect), but this is an unrelated issue. –  John Kirollos Jun 8 '11 at 14:01
@John: You can try to make \section robust with \usepackage{etoolbox}\robustify{\section}. (I don't know if this has unwanted side effects.) –  Ulrike Fischer Jun 9 '11 at 7:58
very nice post, I am working on a book that has 32 longtables and I was wondering if there is a way to add section and subsections to it and it worked. –  Raama Jun 8 '12 at 11:31