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.

Possible Duplicate:
Column padding in tables

I am trying to insert a matrix inside a table, and I am looking for a good way to do this. Usually when I write matrices in equations, I use array environment, so I naively defined an array inside tabular, and it sort of works. The only problem is that the matrix itself seems to take up a huge amount of space inside the cell. An example is

\begin{tabular}{|c|c|}
\hline
\textbf{EKF} & \textbf{UKF}\\
\hline
$Q = \left[ \begin{array}{cc} 0.1 & 0 \\ 0 & 0.1 \end{array}\right]$ & $Q = left[ \begin{array}{cc} 0.01 & 0 \\ 0 & 0.01  \end{array}\right]$\\
\hline
$R = 5 \times 10^{-3}$ & $R = 5 \times 10^{-5}$ \\
\hline
\end{tabular}

Is there any way to increase the spacing in the cell containing the matrix without that matrix taking up all the space?

share|improve this question

marked as duplicate by Werner, Kurt, Thorsten, Guido, Martin Schröder Jan 18 '13 at 7:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Welcome to TeX.sx! –  Kurt Jan 17 '13 at 23:24
add comment

2 Answers 2

up vote 5 down vote accepted

A couple of possibilities:

enter image description here

\documentclass{article}


\usepackage{array}

\begin{document}


\begingroup
\renewcommand{\arraystretch}{4}

 \begin{tabular}{|*2{>{\renewcommand{\arraystretch}{1}}c|}}
\hline
\textbf{EKF} & \textbf{UKF}\\
\hline
$Q = \left[ \begin{array}{cc} 0.1 & 0  \\ 0 & 0.1 \end{array}\right]$ & $Q = \left[ \begin{array}{cc} 0.01 & 0 \\ 0 & 0.01  \end{array}\right]$\\
\hline
$R = 5 \times 10^{-3}$ & $R = 5 \times 10^{-5}$ \\
\hline
\end{tabular}
\endgroup

\bigskip


 \begin{tabular}{|*2{>{\centering\arraybackslash}p{.3\textwidth}|}}
\hline
\textbf{EKF} & \textbf{UKF}\\
\hline
\[Q = \left[ \begin{array}{cc} 0.1 & 0  \\ 0 & 0.1 \end{array}\right]\] & \[Q = \left[ \begin{array}{cc} 0.01 & 0 \\ 0 & 0.01  \end{array}\right]\]\\
\hline
\[R = 5 \times 10^{-3}\] & \[R = 5 \times 10^{-5}\]\\
\hline
\end{tabular}

\end{document}

*{2}{c|} just repeats c| or in general the second argument (p{.3\textwidth} in this case) that many times, that is standard latex, not requiring any package.

> is extended syntax from the array package (which is part of the core LaTeX distribution) which inserts declarations into every cell in that column, in this case \centering\arraybackslash the \centering inserts \centering into each of the p column cells so the text centres. Unfortunately \centering locally defines \\ to be a newline command for centred text so it no longer ends a table row, \arraybackslash re-asserts the tabular/array definition of \\.

share|improve this answer
    
Thanks! Can you make a quick comment on how the statement |*2{>{\centering\arraybackslash}p{.3\textwidth}|} works? –  Mr. Fegur Jan 18 '13 at 0:25
1  
Too much for a comment I added a note to the answer –  David Carlisle Jan 18 '13 at 0:37
add comment

I think you should eliminate the vertical rules and use the booktabs package with vertical spacing controlled after each \\.

enter image description here

Furthermore, as egreg commented, you get better matrix spacing with a amsmath's bmatrix environment:

enter image description here

Code:

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

\begin{document}
\begin{tabular}{ c c }
\toprule
\textbf{EKF} & \textbf{UKF}\\
\midrule\\
\addlinespace[-2ex]
$Q = \begin{bmatrix}  0.1 & 0 \\ 0 &  0.1 \end{bmatrix}$ &
$Q = \begin{bmatrix} 0.01 & 0 \\ 0 & 0.01 \end{bmatrix}$\\
\addlinespace[1.5ex]
$R = 5 \times 10^{-3}$ & $R = 5 \times 10^{-5}$ \\
\bottomrule
\end{tabular}

\end{document}
share|improve this answer
add comment

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