# A matrix inside a table [duplicate]

Possible Duplicate:

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?

-

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

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

A couple of possibilities:

\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 \\.

-
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
Too much for a comment I added a note to the answer –  David Carlisle Jan 18 '13 at 0:37

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

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

## Code:

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

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