# Vertical centering of matrices inside table

I'm trying to center my table contents both vertically and horizontally. The table contains both Bmatrix and bmatrix elements. Only the first column is completely centered. The second column is only horizontally centered even though I set both columns using m{...}:

\begin{table}[h]
\centering
\begin{tabular}{|>{\centering\arraybackslash}m{5cm}|>{\centering\arraybackslash}m{5cm}|}
\hline
\textbf{Set Representation} & \textbf{Binary Representation} \\ \hline
$U = \begin{Bmatrix} 1 & 2 & 3 & 4 \end{Bmatrix}$          & $U = \begin{bmatrix} 1 & 1 & 1 & 1 \end{bmatrix} = 15$                \$.5cm] \hline S_1 = \begin{Bmatrix} 1 & 2 \end{Bmatrix} & S_1 = \begin{bmatrix} 0 & 0 & 1 & 1 \end{bmatrix} = 3 \\[.5cm] \hline S_2 = \begin{Bmatrix} 1 \end{Bmatrix} & S_2 = \begin{bmatrix} 0 & 0 & 0 & 1 \end{bmatrix} = 1 \\[.5cm] \hline S_3 = \begin{Bmatrix} 1 & 3 \end{Bmatrix} & S_3 = \begin{bmatrix} 0 & 1 & 0 & 1 \end{bmatrix} = 5 \\[.5cm] \hline S_4 = \begin{Bmatrix} 4 \end{Bmatrix} & S_4 = \begin{bmatrix} 1 & 0 & 0 & 0 \end{bmatrix} = 8 \\[.5cm] \hline \end{tabular}%\quad} \caption{\textbf{Conversion from set to binary representation}}\label{table:setToBin} \end{table} The result looks like this: • Welcome to TeX.SX! Please don't post code fragments. Instead, put your fragments into a complete compilable document that shows the problem. – BambOo Oct 10 '18 at 20:17 ## 3 Answers with help of the makecell package: \documentclass{article} \usepackage{amsmath} \usepackage{makecell} \usepackage[skip=1ex, font=bf]{caption} \begin{document} \begin{table}[htb] \[\setcellgapes{5pt}\makegapedcells % <--- for vertical space around cells contents \begin{array}{|c|c|} \hline \textbf{Set Representation} & \textbf{Binary Representation} \\ \hline U = \begin{Bmatrix} 1 & 2 & 3 & 4 \end{Bmatrix} & U = \begin{bmatrix} 1 & 1 & 1 & 1 \end{bmatrix} = 15 \\ \hline S_1 = \begin{Bmatrix} 1 & 2 \end{Bmatrix} & S_1 = \begin{bmatrix} 0 & 0 & 1 & 1 \end{bmatrix} = 3 \\ \hline S_2 = \begin{Bmatrix} 1 \end{Bmatrix} & S_2 = \begin{bmatrix} 0 & 0 & 0 & 1 \end{bmatrix} = 1 \\ \hline S_3 = \begin{Bmatrix} 1 & 3 \end{Bmatrix} & S_3 = \begin{bmatrix} 0 & 1 & 0 & 1 \end{bmatrix} = 5 \\ \hline S_4 = \begin{Bmatrix} 4 \end{Bmatrix} & S_4 = \begin{bmatrix} 1 & 0 & 0 & 0 \end{bmatrix} = 8 \\ \hline \end{array}%$
\caption{Conversion from set to binary representation}
\label{table:setToBin}
\end{table}
\end{document}

According to the answer: here of @StevenB.Segletes you can use \belowbaseline command of stackengine package:

\documentclass[12pt,a4paper]{article}

\usepackage{amsmath}
\usepackage{array}
\usepackage{stackengine}
\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{|>{\centering\arraybackslash}m{5cm}|>{\centering\arraybackslash}m{5cm}|}
\hline
\textbf{Set Representation} & \textbf{Binary Representation}\\ \hline
$U = \begin{Bmatrix} 1 & 2 & 3 & 4 \end{Bmatrix}$        & \belowbaseline[-3pt]{$U = \begin{bmatrix} 1 & 1 & 1 & 1 \end{bmatrix} = 15$ }              \\[.5cm] \hline
$S_1 = \begin{Bmatrix} 1 & 2 \end{Bmatrix}$           & \belowbaseline[-3pt]{$S_1 = \begin{bmatrix} 0 & 0 & 1 & 1 \end{bmatrix} = 3$ }             \\[.5cm] \hline
$S_2 = \begin{Bmatrix} 1 \end{Bmatrix}$                  &  \belowbaseline[-3pt]{$S_2 = \begin{bmatrix} 0 & 0 & 0 & 1 \end{bmatrix} = 1$   }           \\[.5cm] \hline
$S_3 = \begin{Bmatrix} 1 & 3 \end{Bmatrix}$             &\belowbaseline[-3pt]{ $S_3 = \begin{bmatrix} 0 & 1 & 0 & 1 \end{bmatrix} = 5$  }           \\[.5cm] \hline
$S_4 = \begin{Bmatrix} 4 \end{Bmatrix}$                  & \belowbaseline[-3pt]{$S_4 = \begin{bmatrix} 1 & 0 & 0 & 0 \end{bmatrix} = 8$    }          \\[.5cm] \hline
\caption{\textbf{Conversion from set to binary representation}}\label{table:setToBin}
\end{table}

\end{document}

I can only reproduce the matrices with oversized delimiters if I use

With

\usepackage[doublespacing]{setspace}

the delimiters have the correct size.

You can insert a strut in the first column; moreover I suggest to use w{c}{5cm}, if you want fixed size, instead of the m specifier, but I don't think it's sound, so I propose a different realization with booktabs.

\documentclass{article}
\usepackage{amsmath,array}
\usepackage{booktabs} % for the second table
\usepackage{caption}
\usepackage[doublespacing]{setspace}

\usepackage{lipsum} % for mock text

\captionsetup{font=bf}

\newcommand{\bs}{\vphantom{$\Big|$}}

\begin{document}

\lipsum[3]

\begin{table}[!htp]
\centering
\begin{tabular}{| >{\bs}w{c}{5cm} | w{c}{5cm} |}
\hline
\textbf{Set Representation} & \textbf{Binary Representation} \\
\hline
$U = \begin{Bmatrix} 1 & 2 & 3 & 4 \end{Bmatrix}$ &
$U = \begin{bmatrix} 1 & 1 & 1 & 1 \end{bmatrix} = 15$ \\
\hline
$S_1 = \begin{Bmatrix} 1 & 2 \end{Bmatrix}$ &
$S_1 = \begin{bmatrix} 0 & 0 & 1 & 1 \end{bmatrix} = 3$ \\
\hline
$S_2 = \begin{Bmatrix} 1 \end{Bmatrix}$ &
$S_2 = \begin{bmatrix} 0 & 0 & 0 & 1 \end{bmatrix} = 1$ \\
\hline
$S_3 = \begin{Bmatrix} 1 & 3 \end{Bmatrix}$ &
$S_3 = \begin{bmatrix} 0 & 1 & 0 & 1 \end{bmatrix} = 5$ \\
\hline
$S_4 = \begin{Bmatrix} 4 \end{Bmatrix}$ &
$S_4 = \begin{bmatrix} 1 & 0 & 0 & 0 \end{bmatrix} = 8$ \\
\hline
\end{tabular}

\caption{Conversion from set to binary representation}\label{table:setToBin}

\end{table}

\begin{table}[!htp]
\centering
\begin{tabular}{ cc }
\toprule
\textbf{Set Representation} & \textbf{Binary Representation} \\
\midrule
$U = \begin{Bmatrix} 1 & 2 & 3 & 4 \end{Bmatrix}$ &
$U = \begin{bmatrix} 1 & 1 & 1 & 1 \end{bmatrix} = 15$ \\
$S_1 = \begin{Bmatrix} 1 & 2 \end{Bmatrix}$ &
$S_1 = \begin{bmatrix} 0 & 0 & 1 & 1 \end{bmatrix} = 3$ \\
$S_2 = \begin{Bmatrix} 1 \end{Bmatrix}$ &
$S_2 = \begin{bmatrix} 0 & 0 & 0 & 1 \end{bmatrix} = 1$ \\
$S_3 = \begin{Bmatrix} 1 & 3 \end{Bmatrix}$ &
$S_3 = \begin{bmatrix} 0 & 1 & 0 & 1 \end{bmatrix} = 5$ \\
$S_4 = \begin{Bmatrix} 4 \end{Bmatrix}$ &
$S_4 = \begin{bmatrix} 1 & 0 & 0 & 0 \end{bmatrix} = 8$ \\