Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

%% LyX 1.6.7 created this file.  For more info, see http://www.lyx.org/.
%% 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}
share|improve this question
1  
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

1 Answer 1

up vote 7 down vote accepted

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}
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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