# vertically central aligning the table cell contents

I need to centrally align the cell contents vertically. Below is the code for values of rows "channel bandwidth" and others, as well.

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{table}[h!]
\begin{center}
\begin{tabular}{ | p{3cm} | m{1cm} | c | c | c | c | c | c | }
\hline
Parameter & Units & \multicolumn{6}{|c|}{Values} \\
\hline
Channel Bandwidth & MHz & 1.25 & 2.5
& 5 & 10 & 15 & 20 \\
\hline
Frame duration & ms & \multicolumn{6}{|c|}{10} \\
\hline
Sub-frame duration & ms & \multicolumn{6}{|c|}{1}  \\
\hline
Sub-carrier spacing & kHz & \multicolumn{6}{|c|}{15} \\
\hline
Sampling Frequency & MHz & 1.92 & 3.84 & 7.68 & 15.36 & 23.04 & 30.72 \\
\hline
\end{tabular}
\end{center}

\end{table}
\end{document}

• Welcome to TeX.SE. – Mico May 20 at 10:12
• Please extend your code fragment to small but complete document, which will provide information about page layout.. Test of your code in standard article document class show, that for text in first column is enough place to be in one line. – Zarko May 20 at 10:59
• I've taken the liberty of (a) editing your code snippet to make it minimally compilable and (b) a screenshot that shows the resulting output. Feel free to edit if I've missed important aspects of your document setup. – Mico May 20 at 11:04

In order to vertically center the contents in the rows, replace p by m. In the second table, I have also applied a ragged right alignment to get rid of the large horizontal white spaces.

\documentclass{article}
\usepackage{array}
\usepackage{ragged2e}
\begin{document}

\begin{table}[h!]
\centering
\begin{tabular}{ | m{3cm} | m{1cm} | c | c | c | c | c | c | }
\hline
Parameter & Units & \multicolumn{6}{c|}{Values} \\
\hline
Channel Bandwidth & MHz & 1.25 & 2.5
& 5 & 10 & 15 & 20 \\
\hline
Frame duration & ms & \multicolumn{6}{c|}{10} \\
\hline
Sub-frame duration & ms & \multicolumn{6}{c|}{1}  \\
\hline
Sub-carrier spacing & kHz & \multicolumn{6}{c|}{15} \\
\hline
Sampling Frequency & MHz & 1.92 & 3.84 & 7.68 & 15.36 & 23.04 & 30.72 \\
\hline
\end{tabular}

\end{table}

\begin{table}[h!]
\centering
\begin{tabular}{ | >{\RaggedRight}m{3cm} | c | c | c | c | c | c | c | }
\hline
Parameter & Units & \multicolumn{6}{c|}{Values} \\
\hline
Channel Bandwidth & MHz & 1.25 & 2.5
& 5 & 10 & 15 & 20 \\
\hline
Frame duration & ms & \multicolumn{6}{c|}{10} \\
\hline
Sub-frame duration & ms & \multicolumn{6}{c|}{1}  \\
\hline
Sub-carrier spacing & kHz & \multicolumn{6}{c|}{15} \\
\hline
Sampling Frequency & MHz & 1.92 & 3.84 & 7.68 & 15.36 & 23.04 & 30.72 \\
\hline
\end{tabular}

\end{table}

\end{document}


Personally, I'd use an l type column for the first (and second) column and remove all of the vertical and most of the horizontal lines. Maybe you could also put the values of frame duration, sub-frame duration and sub-carrier spacing, that seem to be the same regardless of the channel bandwidth, into the caption of the table.

• Thanks for taking the time. The table works fine now. :) – Faru12 May 21 at 10:17

I think the main issue with your table is that the six numeric columns are not equally wide, and hence that the numbers 10, 1, and 15 are not placed in the middle of the space. To remedy this, I suggest you use a tabularx environment and use a centered version of the X column type for the six numeric columns. Conversely, I also suggest you use the basic l column type for the first two columns.

You should also replace all four instances of

\multicolumn{6}{|c|}{...}


with

\multicolumn{6}{c|}{...}


in order to avoid creating double-width vertical lines.

\documentclass{article}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}

\begin{table}[h!]
\setlength\extrarowheight{2pt}
\setlength\tabcolsep{4pt}

\begin{tabularx}{\textwidth}{ | l | l | *{6}{C|} }
\hline
Parameter           & Units& \multicolumn{6}{c|}{Values} \\
\hline
Channel Bandwidth   & MHz  & 1.25 & 2.5 & 5 & 10 & 15 & 20 \\
\hline
Frame duration      & ms   & \multicolumn{6}{c|}{10} \\
\hline
Sub-frame duration  & ms   & \multicolumn{6}{c|}{\phantom{0}1}  \\
\hline
Sub-carrier spacing & kHz  & \multicolumn{6}{c|}{15} \\
\hline
Sampling Frequency  & MHz  & 1.92 & 3.84 & 7.68 & 15.36 & 23.04 & 30.72 \\
\hline
\end{tabularx}
\end{table}
\end{document}

• Thanks for the help. It works fine now. :) – Faru12 May 21 at 10:17

I think it is worth pointing out that a lot of problems with tables can be avoided by reevaluating the design choices. I recommend reading The Data Prison and the booktabs documentation to get a general idea of what's good table typography. If you still encounter layout problems, don't hesitate to consider arranging your data differently.

With this in mind, the following layout is an option.

\documentclass{article}

\usepackage{array}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}
\centering
\sisetup{list-final-separator={, }}
\begin{tabular}{l r l}\toprule
Parameter   &   Unit    &   Values \\\midrule
channel bandwidth   &   \si{\mega\hertz}    &   \numlist{1.25; 2.5; 5; 10; 15; 20}  \\
frame duration  &   \si{\milli\second}  &   \num{10}    \\
sub-frame duration  &   \si{\milli\second}  &   \num{1}     \\
sub-carrier spacing &   \si{\kilo\hertz}    &   \num{15}    \\
sampling frequency  &   \si{\mega\hertz}    &   \numlist{1.92; 3.84; 7.68; 15.36; 23.04; 30.72} \\\bottomrule
\end{tabular}
\end{table}

\end{document}


• In addition to the booktabs package I used siunitx. It allows you to consistently typeset numbers and units. In this example, it doesn't do all that much, but it's a good idea to just always use it.
• Never use the option h!. If you don't want your table to float (i.e. move to a different place), then just don't put it into a floating environment (table). I would recomment not giving the placement option at all as a rule and only fiddle with float placement when the document is finished otherwise.
• You should not use the center environment inside of a float environment (table or figure) as it introduces additional vertical space. Use \centering instead.
• Try being consistent in your use of capital letters. I made all the parameter names lower case, though you may choose a different (consistent) convention.

If the values for the channel bandwidth and sampling frequency are not varied independently (as I suspect is the case here), it is better to move them next to each other so that they form their own little table.

\documentclass{article}

\usepackage{array}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}
\centering
\begin{tabular}{l r *{6}{S[table-format=2.2]}}\toprule
Parameter   &   Unit    &   \multicolumn{6}{l}{Values} \\\midrule
frame duration  &   \si{\milli\second}  &   10  \\
sub-frame duration  &   \si{\milli\second}  &   1   \\
sub-carrier spacing &   \si{\kilo\hertz}    &   15  \\
sampling frequency  &   \si{\mega\hertz}    &   1.92    &   3.84    &   7.68    &   15.36   &   23.04   &   30.72   \\
channel bandwidth   &   \si{\mega\hertz}    &   1.25    &   2.5 &   5   &   10  &   15  &   20  \\\bottomrule
\end{tabular}
\end{table}

\end{document}


Should you have more values so that this approach isn't feasible any more, it is probably better to just put those to parameters in their own table. In general, having data of the same kind in a column is preferable to having it in a row.

• Thanks, the table works fine now. – Faru12 May 21 at 10:17