Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
\vspace{-5} does not compile. please provide a MWE –  Yossi Farjoun Nov 5 '10 at 11:57
    
It compiles for me. Done and thanks. –  Frank_Zafka Nov 5 '10 at 12:08
add comment

1 Answer

up vote 6 down vote accepted

The following code seems to align at equal signs. does this work or you?

\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 alignement was supposed to be different in the lower part than in the upper part, I added two extra tabular's nested inside multicols. 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.

share|improve this answer
    
It does. Can you perhaps explain what you did? Thanks. –  Frank_Zafka Nov 5 '10 at 12:09
1  
@RSoul: I added a short explanation, and re-indented the code so that it may be more readable. –  Yossi Farjoun Nov 5 '10 at 14:37
    
Brilliant. Thanks –  Frank_Zafka Nov 5 '10 at 14:55
1  
The spacing around the ='s are wrong –  daleif Jul 13 '11 at 8:15
1  
I used the alignment r@{\;{=}\;}l to provide a bit of whitespace around the equals signs. –  David Hall Feb 5 at 21:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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