1

I tried to align this table. My code

\documentclass[border=2]{standalone}
\usepackage{amsmath}
\begin{document}
\begin{tabular}{c c c}
1 & $=$ & 1 \\ 
$2 + 3 +4$ & $=$ & $1+8$ \\ 
$5+6+7+8+9$ & $=$ & $8+27$ \\ 
$10+11+12+13+14+15+16$ & $=$ & $27+64$ 
\end{tabular} 
\end{document}

enter image description here

I see the signs = are far from the left and the right. How can I align this table with another way?

3

Since the material should be in math mode, I suggest using an array environment instead of a tabular environment. If nothing else, it saves you from having to enter lots of $ characters by hand.

Observe that the array has only two explicit columns. The middle column, with all the = symbols, is generated automatically and needn't be typed by you. The @{{}={}} in the array header instructs LaTeX to insert an = symbol between the first and second column, with spacing that's appropriate for an operator of type mathrel.

enter image description here

\documentclass{article}
\usepackage{array}
\begin{document}
\[  % start display math mode
\begin{array}{c @{{}={}} c}
1 &  1 \\
2 + 3 +4  & 1+8 \\
5+6+7+8+9 & \phantom{0}8+27 \\
10+11+12+13+14+15+16  & 27+64
\end{array}
\]
\end{document}

Addendum to address the OP's follow-up inquiry: If the two columns of the array environment should be right-aligned instead of centered, just change the column specifier from c (for "center") to r (for "right"):

enter image description here

\documentclass{article}
\usepackage{array}
\begin{document}
\[
\begin{array}{r @{{}={}} r}  % <-- note the "r" column specifiers
1 &  1 \\
2 + 3 +4  & 1+\phantom{0}8 \\
5+6+7+8+9 & 8+27 \\
10+11+12+13+14+15+16  & 27+64
\end{array}
\]
\end{document}

If, on the other hand, you want to keep the center alignment but shove the entire array to the right-hand edge of the text block, the following code will do what you want (the horizontal line is just there to illustrate the width of the text block):

enter image description here

\documentclass{article}
\usepackage{array}
\begin{document}
\hrule % just to illustrate width of text block
\hspace{\fill} 
$ % use inline-math rather than display-math mode
\begin{array}{c @{{}={}} c@{}}
1 &  1 \\
2 + 3 +4  & 1+8 \\
5+6+7+8+9 & \phantom{0}8+27 \\
10+11+12+13+14+15+16  & 27+64
\end{array} $
\end{document}
  • Well remembered: @{{}={}} is nice! – Sigur Jul 23 '15 at 9:25
  • @Mico How can I align \[ \begin{array}{c @{{}={}} c} 1 & 1 \\ 3+5 & 8 \\ 7+9+11 & 27 \\ 13+15+17+19 & 64\\ 21+23+25+27+29&125 \end{array} \] to the right? – minthao_2011 Jul 23 '15 at 10:09
  • @minthao_2011 - Please clarify what you mean by "align ... to the right": Do you want to shove the entire array to the right, or should one or the other column (or both columns) be right-aligned? – Mico Jul 23 '15 at 10:43
  • @Mico Alingn to the right of the digits in unit. – minthao_2011 Jul 23 '15 at 11:12
  • @Mico I want to shove the entire array to the right. – minthao_2011 Jul 23 '15 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.