3

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: The right column is not centering vertically.

  • 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
0

with help of the makecell package:

enter image description here

\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}
0

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
\end{tabular}%\quad}
\caption{\textbf{Conversion from set to binary representation}}\label{table:setToBin}
\end{table}

\end{document}

enter image description here

0

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

\linespread{1.667}

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$ \\
\addlinespace
$S_1 = \begin{Bmatrix} 1 & 2 \end{Bmatrix}$ &
  $S_1 = \begin{bmatrix} 0 & 0 & 1 & 1 \end{bmatrix} = 3$ \\
\addlinespace
$S_2 = \begin{Bmatrix} 1 \end{Bmatrix}$ &
  $S_2 = \begin{bmatrix} 0 & 0 & 0 & 1 \end{bmatrix} = 1$ \\
\addlinespace
$S_3 = \begin{Bmatrix} 1 & 3 \end{Bmatrix}$ &
  $S_3 = \begin{bmatrix} 0 & 1 & 0 & 1 \end{bmatrix} = 5$ \\
\addlinespace
$S_4 = \begin{Bmatrix} 4 \end{Bmatrix}$ &
  $S_4 = \begin{bmatrix} 1 & 0 & 0 & 0 \end{bmatrix} = 8$ \\
\bottomrule
\end{tabular}

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

\end{table}

\end{document}

Final note: there should be no \textbf in the body of \caption; such formatting decision are best done on a global basis with the caption package.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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