14

I am trying to align an equals sign between two sets of cells. The first table here doesn't want to align, whilst the second table does. Is there a more elegant way of doing this?

\documentclass{article}
\begin{document}
\begin{table}
\centering              
\begin{tabular}{c c c c}
\hline
1 & 167 & 1 & 144 \\               
2 & 194 & 2 & 167 \\                
\multicolumn{2}{r}{Chi-square = .19} & \multicolumn{2}{r}{Chi-square = 5.74} \\
\multicolumn{2}{r}{\emph{p} = .999} & \multicolumn{2}{r}{\emph{p} = .332} \\
\hline                              
\end{tabular}
\end{table} 
\end{document}

This one is aligned:

\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{c c c c}
\hline                              
1 & 160 & 1 & 160 \\              
2 & 160 & 2 & 179 \\                 
\multicolumn{2}{r}{Chi-square=2.73}&\multicolumn{2}{r}{Chi-square=5.28} \\
\multicolumn{2}{r}{ p=.741}&\multicolumn{2}{r}{ p=.383} \\
\hline                              
\end{tabular}
\end{table} 
\end{document}
9

The following code seems to align at equal signs:

\begin{tabular}{c c c c}
\hline
1 & 167 & 1 & 144 \\               
2 & 194 & 2 & 167 \\                
\multicolumn{2}{c}{
  \begin{tabular}{r@{=}l}
     Chi-square & .19\\
       \emph{p} & .999
  \end{tabular}
} & 
\multicolumn{2}{c}{
  \begin{tabular}{r@{=}l}
    Chi-square & 5.74 \\
       \emph{p} & .332
  \end{tabular}
}\\
\hline                              
\end{tabular}

alt text


Explanation: Since the alignment was supposed to be different in the lower part than in the upper part, I added two extra tabular's nested inside \multicolumns. These two tabulars use the column definition r@{=}l, which means that there are two columns, aligned right and left and between them I want an equal sign (and no padding). Since the equal sign is the separator between the columns, it will be aligned by definition. The typical use that one sees in examples that use the @{} column separator is @{.} for aligning numbers by their decimal point.

  • 1
    The spacing around the ='s are wrong – daleif Jul 13 '11 at 8:15
  • 2
    I used the alignment r@{\;{=}\;}l to provide a bit of whitespace around the equals signs. – David Hall Feb 5 '14 at 21:28

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.