Math & ScienceNumber for a row in a tabular environment?

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Bolzano82
Posts: 5
Joined: Tue Apr 17, 2012 5:46 pm

Number for a row in a tabular environment?

Post by Bolzano82 »

Hi.

I'm writing a document with some rather large calculations, and I use the tabular environment to align the equations (I feel I gain more control on the layout compared to e.g \begin{align}).

However, I want to give certain rows in the tabular environment a number corresponding to the \begin{equation}-numbers. Is there any way I can do this?

Minimal Working Example.

Code: Select all

\documentclass{article}

\begin{document}
\[
\begin{tabular}{rcl}
$a$ 
&$=$& $b$\\
&$=$& $c$\\
&$=$& $d$ (with number)\\
\end{tabular}
\]
\end{document}
Last edited by Stefan Kottwitz on Wed Apr 25, 2012 8:02 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Number for a row in a tabular environment?

Post by localghost »

Bolzano82 wrote:[…] (I feel I gain more control on the layout compared to e.g \begin{align}). […]
Can you elaborate a bit? If this environment is insufficient, try the alignat environment instead. Details can be found in the amsmath manual or in the excellent »Math mode« document.


Thorsten
Bolzano82
Posts: 5
Joined: Tue Apr 17, 2012 5:46 pm

Number for a row in a tabular environment?

Post by Bolzano82 »

Thanks for the suggestion, I will remember that one for next time.

The problem is I have already finished writing the document I am working with, and I don't want to change all my equations to alignat.

So there is no way to give an equation number to a tabular row? It's fine as I can live with wrapping my tabulars in a \begin{equation} environment and get an equation number for the entire table.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Number for a row in a tabular environment?

Post by localghost »

Bolzano82 wrote:[…] The problem is I have already finished writing the document I am working with, and I don't want to change all my equations to alignat. […]
It will not work without some modifications. And to use the {array} environment seems a bit smarter here.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}

\begin{document}
  \begin{equation}
    \begin{array}[b]{r@{\;=\;}l}
      a &   \\
        & b \\
        & c \\
        & d 
    \end{array}
  \end{equation}
\end{document}
You only have to gauge which modification is less time consuming.
Bolzano82
Posts: 5
Joined: Tue Apr 17, 2012 5:46 pm

Re: Number for a row in a tabular environment?

Post by Bolzano82 »

Okay, thanks for your help! The solution you suggested will be fine.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Number for a row in a tabular environment?

Post by Juanjo »

Bolzano82:

If you simply want to add an equation number to your tabular, it suffices a minimal change in your original code (see below). If you want to put the equation number at a specific row (say, the last one), then the align environment provides a simple solution. If you want a vertically centered equation number, then combine equation with split or aligned. See these alternatives here:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{equation}
  \begin{tabular}{rcl}
    $a$ 
    &$=$& $b$\\
    &$=$& $c$\\
    &$=$& $d$
  \end{tabular}
\end{equation}

\begin{align}
  a&= b \notag \\
   &= c \notag \\
   &= d
\end{align}

\begin{equation}
  \begin{aligned}
     a&= b \\
      &= c \\
      &= d
  \end{aligned}
\end{equation}

\begin{equation}
  \begin{split}
     a&= b \\
      &= c \\
      &= d
  \end{split}
\end{equation}

\end{document}
In my opinion, the AMS environments (align, aligned, split...) are much more better that array and, of course, tabular. For the purpose of comparison, just check the following simple example:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{equation}
  \begin{array}[b]{r@{\;=\;}l}
      \int_a^b f(x)\, dx 
        & \left[F(x)\right]_{x=a}^{x=b} \\
        & F(b)-F(a) 
  \end{array}
\end{equation}

\begin{align}
  \int_a^b f(x)\, dx 
    & = \left[F(x)\right]_{x=a}^{x=b} \notag \\
    & = F(b)-F(a)
\end{align}

\begin{equation}
  \begin{aligned}
    \int_a^b f(x)\, dx 
      & = \left[F(x)\right]_{x=a}^{x=b} \\
      & = F(b)-F(a)
  \end{aligned}
\end{equation}

\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply