4

I'm mystified by why I can't generate a simple tabular set of equations using tabular. As far as I can tell my code follows the example in the documentation exactly, simply substituting some slightly more complex expressions for the entries in the table.

\documentclass[]{report}

\usepackage{wasysym}

\begin{document}

$$
\begin{tabular}{lcr}
z_{\earth}(t) &= 0 \\
z_{\venus}(t) &=  R_{\venus} e^{2\pi i \Omega_{\astrosun} t} & + r_{\venus} e^{2\pi i (\omega_{\venus} t +  k_{\venus})} \\
z_{\mercury}(t) &=  R_{\mercury} e^{2\pi i \Omega_{\astrosun} t} & + r_{\mercury} e^{2\pi i (\omega_{\mercury} t + k_{\mercury})} \\
z_{\mars}(t) &= R_{\mars} e^{2\pi i (\Omega_{\mars} t + K_{\mars})} & + r_{\mars} e^{2\pi i \Omega_{\astrosun} t} \\
z_{\jupiter}(t) &= R_{\jupiter} e^{2\pi i (\Omega_{\jupiter} t + K_{\jupiter})} & + r_{\jupiter} e^{2\pi i \Omega_{\astrosun} t} \\
z_{\saturn}(t) &= R_{\saturn} e^{2\pi i (\Omega_{\saturn} t + K_{\saturn})} & + r_{\saturn} e^{2\pi i \Omega_{\astrosun} t}
\end{tabular}
$$

\end{document}

Why is my table getting errors? How do I get it to work?

orome
  • 10,459

3 Answers3

5

I suggest using an array environment instead of tabular, with care being taken to align the = and (if present) + symbols.

enter image description here

\documentclass{report}
\usepackage{wasysym}
\usepackage{array}              % for "\newcolumntype" macro
\newcolumntype{C}{>{{}}c<{{}}}  % dedicated column type for "+" symbols
\begin{document}    
\[  % please don't use "$$ ... $$" in a LaTeX document
\renewcommand\arraystretch{1.8} % for a more open look
\setlength\arraycolsep{0pt}     % no default inter-column spacing
\begin{array}{r @{{}={}} lCl}
z_{\earth}(t) & 0 \\
z_{\venus}(t) &  R_{\venus} e^{2\pi i \Omega_{\astrosun} t}   
  & + & r_{\venus} e^{2\pi i (\omega_{\venus} t + k_{\venus})} \\
z_{\mercury}(t) &  R_{\mercury} e^{2\pi i \Omega_{\astrosun} t} 
  & + & r_{\mercury} e^{2\pi i (\omega_{\mercury} t + k_{\mercury})} \\
z_{\mars}(t) & R_{\mars} e^{2\pi i (\Omega_{\mars} t + K_{\mars})} 
  & + & r_{\mars} e^{2\pi i \Omega_{\astrosun} t} \\
z_{\jupiter}(t) & R_{\jupiter} e^{2\pi i (\Omega_{\jupiter} t + K_{\jupiter})} 
  & + & r_{\jupiter} e^{2\pi i \Omega_{\astrosun} t} \\
z_{\saturn}(t) & R_{\saturn} e^{2\pi i (\Omega_{\saturn} t + K_{\saturn})} 
  & + & r_{\saturn} e^{2\pi i \Omega_{\astrosun} t}
\end{array}
\]
\end{document}
Mico
  • 506,678
  • That works nicely. Can you elaborate a bit on the magic you did there? – orome Aug 25 '16 at 21:37
  • 1
    @raxacoricofallapatorius - The parameter \arraycolsep is set to 0pt as we're providing our own customized spacing. The @{{}={}} directive automatically inserts a correctly spaced = symbol between columns 1 and 2 (of type r and l, respectively. By "correctly spaced", I mean spacing appropriate for an object of type math-rel. The >{{}}c<{{}} column type may be a bit intimidating looking, at least at first glance. What it does, in conjunction with the zero-width intercolumn space, is to create the right spacing for the column that contains the + symbols. – Mico Aug 25 '16 at 21:43
4

Using amsmath align*:

enter image description here

\documentclass[]{report}

\usepackage{amsmath}
\usepackage{wasysym}

\begin{document}


\begin{align*}
z_{\earth}(t) &= 0 \\
z_{\venus}(t) &=  R_{\venus} e^{2\pi i \Omega_{\astrosun} t}  + r_{\venus} e^{2\pi i (\omega_{\venus} t +  k_{\venus})} \\
z_{\mercury}(t) &=  R_{\mercury} e^{2\pi i \Omega_{\astrosun} t}  + r_{\mercury} e^{2\pi i (\omega_{\mercury} t + k_{\mercury})} \\
z_{\mars}(t) &= R_{\mars} e^{2\pi i (\Omega_{\mars} t + K_{\mars})}  + r_{\mars} e^{2\pi i \Omega_{\astrosun} t} \\
z_{\jupiter}(t) &= R_{\jupiter} e^{2\pi i (\Omega_{\jupiter} t + K_{\jupiter})}  + r_{\jupiter} e^{2\pi i \Omega_{\astrosun} t} \\
z_{\saturn}(t) &= R_{\saturn} e^{2\pi i (\Omega_{\saturn} t + K_{\saturn})}  + r_{\saturn} e^{2\pi i \Omega_{\astrosun} t}
\end{align*}

\end{document}
David Carlisle
  • 757,742
3

The errors are mainly due to using tabular instead of array.

The easiest way to set the equations is with alignat*:

\documentclass{report}
\usepackage{amsmath}
\usepackage{wasysym}

\begin{document}

\begin{alignat*}{2}
z_{\earth}(t) &= 0 \\
z_{\venus}(t) &=  R_{\venus} e^{2\pi i \Omega_{\astrosun} t}
 && + r_{\venus} e^{2\pi i (\omega_{\venus} t +  k_{\venus})} \\
z_{\mercury}(t) &=  R_{\mercury} e^{2\pi i \Omega_{\astrosun} t}
 && + r_{\mercury} e^{2\pi i (\omega_{\mercury} t + k_{\mercury})} \\
z_{\mars}(t) &= R_{\mars} e^{2\pi i (\Omega_{\mars} t + K_{\mars})}
 && + r_{\mars} e^{2\pi i \Omega_{\astrosun} t} \\
z_{\jupiter}(t) &= R_{\jupiter} e^{2\pi i (\Omega_{\jupiter} t + K_{\jupiter})}
 && + r_{\jupiter} e^{2\pi i \Omega_{\astrosun} t} \\
z_{\saturn}(t) &= R_{\saturn} e^{2\pi i (\Omega_{\saturn} t + K_{\saturn})}
 && + r_{\saturn} e^{2\pi i \Omega_{\astrosun} t}
\end{alignat*}

\end{document}

enter image description here

Explanation. We set up two sets of “left-aligned and right-aligned” pairs of columns. The first alignment point is at the equals signs, the second one at the plus signs. The second right-aligned column is empty.

Contrary to align*, alignat* does not insert horizontal spaces between the column pairs. Contrary to array, it uses display math mode automatically.

If you need to give a number to the whole block, do

\begin{equation}
\begin{alignedat}{2}
z_{\earth}(t) &= 0 \\
z_{\venus}(t) &=  R_{\venus} e^{2\pi i \Omega_{\astrosun} t}
 && + r_{\venus} e^{2\pi i (\omega_{\venus} t +  k_{\venus})} \\
<...same code as before...>
\end{alignedat}
\end{equation}

If you have to give a number to each line, change alignat* into alignat.

A final recommendation: never use $$ in LaTeX. Never. See Why is \[ ... \] preferable to $$ ... $$? for more information.

egreg
  • 1,121,712