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.

Minimal CODE

\documentclass{article}
\usepackage
{%
    array,
    calc,
    amsmath,
    longtable,
    varwidth%
}

\newsavebox\TBox
\newcolumntype{B}[1]
{%
    @{}%
    >{\begin{lrbox}{\TBox}\varwidth{\linewidth}}%
    m{#1\linewidth-1.5\arrayrulewidth}%
    <{%
            \endvarwidth\end{lrbox}\fboxrule=0pt%
            \fboxsep=15pt\fbox{\usebox\TBox}%
     }%
    @{}%
}

\begin{document}

\begin{longtable}{|*2{B{0.5}|}}\hline
\begin{align}
a &= b
\end{align} 
& c \tabularnewline\hline
\end{longtable}

\end{document}

How to avoid & conflict when using \begin{align} in a tabular cell?

share|improve this question
    
Put the environment into braces {...}. However there will be a problem with the equationnumber. A number makes no real sense to me. Do you really need it? –  Herbert Jan 8 '11 at 15:53
    
@Herbert, my real scenario is to create INPUT-OUTPUT table. Input cell contains the LaTeX code and the OUTPUT cell contains the corresponding output. When I want to show \begin{align}, the output should provide the proper output. :-) –  xport Jan 8 '11 at 15:56
    
If you want to create INPUT-OUTPUT table, maybe you should just use minipage instead of tabular. –  Leo Liu Jan 8 '11 at 16:47
    
the align environment is buggy when you want to cut off the surrounding white space, see page 74 in http://mirror.ctan.org/info/math/voss/mathmode/Mathmode.pdf. Use only the m column type without a parbox or minipage –  Herbert Jan 8 '11 at 17:52
add comment

1 Answer

up vote 1 down vote accepted

If you use \parbox or minipage within the cell, the & works as expected and you would get also the equation number. For example:

\begin{longtable}{|*2{B{0.5}|}}\hline
\parbox{.5\linewidth}{%
  \begin{align}
    a &= b
  \end{align}} 
  & c \tabularnewline\hline
\end{longtable}

longtable with align in cell

share|improve this answer
    
thanks for answering. Both Herbert's and your solutions work. –  xport Jan 8 '11 at 17:50
add comment

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.