Graphics, Figures & TablesAligning table contents to equal sign

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
dmuthu_cse
Posts: 97
Joined: Fri Sep 04, 2009 4:56 pm

Aligning table contents to equal sign

Post by dmuthu_cse »

Dear all,

Please help me in aligning my table's column to the "=" sign.

I have a table of two columns, 2nd column has some equations, which should be aligned to the "=" sign. Like the one which we will get, if we use equation environment.

i am attaching the code,

Code: Select all

\begin{table}[!ht]
\centering
\begin{tabular}{cl}\toprule
\textbf{$B$'s Pure Strategy} & \textbf{$A$'s expected payoff}\\ \midrule
I	& $(2-10)x_1 +1=x_1+1$\\
II	& $(1-0)x_1 = 0 + x_1$\\
III & $(0-3) x_1 + 3 = -3x_1 + 3$\\
IV & $(-2-2) x_1 + 2 = - 4 x_1 + 2$\\ \bottomrule
\end{tabular}
\end{table}
Anticipating for your suggestions.

Regards,
Muthu

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Aligning table contents to equal sign

Post by gmedina »

Hi,

you could try something like this:

Code: Select all

\documentclass{article} 
\usepackage{amsmath,booktabs,array}

\begin{document}

\begin{table}[!ht]
  \centering
  \begin{tabular}{c>{$}r<{$}@{\;=\;}>{$}l<{$}}\toprule
    \textbf{$B$'s Pure Strategy} & \multicolumn{2}{c}{\textbf{$A$'s expected payoff}}\\   
    \midrule
    I & (2-10)x_1 +1 & x_1+1\\
    II & (1-0)x_1 & 0 + x_1\\
    III & (0-3) x_1 + 3 &  -3x_1 + 3\\
    IV & (-2-2) x_1 + 2& - 4 x_1 + 2\\ 
    \bottomrule
\end{tabular}
\end{table}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Aligning table contents to equal sign

Post by frabjous »

I guess the easiest way given the code you already have would be to introduce another column with = as a separator between the second and third columns:

Code: Select all

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[!ht]
\centering
\begin{tabular}{cr@{ = }l}
\toprule
\textbf{$B$'s Pure Strategy} & \multicolumn{2}{l}{\textbf{$A$'s expected payoff}}\\ \midrule
I    & $(2-10)x_1 +1$   &$x_1+1$\\
II   & $(1-0)x_1$       & $0 + x_1$\\
III  & $(0-3) x_1 + 3$  & $-3x_1 + 3$\\
IV   & $(-2-2) x_1 + 2$ & $- 4 x_1 + 2$\\ \bottomrule
\end{tabular}
\end{table}
\end{document}
A more elegant solution would likely come from the align, aligned or alignat environments from the amsmath packages, but I'm feeling a bit too lazy to work that up right now. Maybe someone else will.

EDIT: Ugh! Foiled again by gmedina's quicker and better solution.
dmuthu_cse
Posts: 97
Joined: Fri Sep 04, 2009 4:56 pm

Re: Aligning table contents to equal sign

Post by dmuthu_cse »

Hello,

Thanks for ur quick response..

now the table is looking good.

Regards
Muthu
Post Reply