7

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?

Mr. Fegur
  • 173

2 Answers2

10

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}

Peter Grill
  • 223,288
8

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

David Carlisle
  • 757,742