4

I'm trying to build a table with multiple numbered equations inside, hence I used the align environment. On the other hand, I need to color some cells, so I included the xcolor package with the table option. However, I can't build the following MWE:

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{amsmath}

\begin{document}
\begin{tabular}{p{0.5\textwidth}}
    {\begin{align}
        S &= 4 \pi r ^2 \\
        V &= 4/3 \pi r^3
    \end{align}}
\end{tabular}
\end{document}

Misplaced \omit. \end{align} is the error I get. Removing the table option makes it disappear. I tried to investigate the xcolor docs but it's not clear to me what that option does. How do you solve this?

EDIT: I apologize for the delay, had to finish the document swiftly and forgot I had posted the question here. I see that my MWE turned up so minimal that it confused some of you, so have just modified it a little. I certainly needed the align environment, for I wanted to display several equations in one cell.

4
  • The problem is with the colortbl package
    – egreg
    Nov 21, 2014 at 22:41
  • @egreg yes but... Nov 21, 2014 at 22:45
  • if it's only for one line, why is align necessary? (i ask because a lot of people use align when they really should be using equation.) Nov 21, 2014 at 23:11
  • 1
    @barbarabeeton we complain enough when people don't make examples minimal, can hardly complain when they do. Nov 21, 2014 at 23:17

2 Answers 2

7

This possibly does the right thing.

\documentclass{article}

\usepackage{amsmath}
\usepackage{colortbl}


\begin{document}
\begin{tabular}{p{0.5\textwidth}}
    {\makeatletter\CT@everycr{\the\everycr}\begin{align}
        S &= \pi r ^2
    \end{align}}
\end{tabular}
\end{document}
2
  • Could someone briefly explain what was breaking it and what does \makeatletter\CT@everycr{\the\everycr} do? Is it safe to replace \usepackage{colortbl} with my original \usepackage[table]{xcolor}?
    – Noitaenola
    Dec 30, 2014 at 3:22
  • @Noitaenola you can use xcolor's table option (it is same as colortbl internally) what it is doing is setting the everycr hook that is run at the start of each table row so that it just does the "normal" everycr without the commands that insert the coloured bands. They were messing up align. Dec 30, 2014 at 10:03
1

I used equation inside a minipage.

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{amsmath}

\begin{document}
\begin{tabular}{p{0.5\textwidth}}
  \cellcolor{yellow}\begin{minipage}{.5\textwidth}\begin{equation}      S = \pi r ^2    \end{equation}\end{minipage}\\

\end{tabular}
\end{document}

Edited

After see David´s comment to use without minipage I tried and it worked too (must have made some mistake before). So here is another code and the result with and without using minipage.

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{amsmath}

\begin{document}
\begin{tabular}{p{0.5\textwidth}}
  \cellcolor{yellow}\begin{equation}      S = \pi r ^2    \end{equation}\\ 
  \cellcolor{red}\begin{minipage}{.5\textwidth}\begin{equation}      S = \pi r ^2    \end{equation}\end{minipage}\\

\end{tabular}
\end{document}

And the result. First row without minipage, second row with minipage. There´s difference on the vertical space.

enter image description here

3
  • I think it needs the approach by David Carlisle to make it work with align.
    – Smarzaro
    Nov 21, 2014 at 23:15
  • why would you use minipage here? You get the same output without it and just using equation. Nov 22, 2014 at 1:16
  • David, you´re right. I must have made something wrong compiling without minipage. Tried again and it worked. I will edit the answer.
    – Smarzaro
    Nov 22, 2014 at 1:31

You must log in to answer this question.

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