# Vertically and horizontally centre cell contents in tabular

I have searched a lot and have found so many other similar questions but no answer helped. I have the following table code:

\renewcommand{\arraystretch}{3}
\begin{table}[h!]
\resizebox{\columnwidth}{!}{
\centering
\begin{tabular}{||c c c c c c||}
\hline
\multicolumn{1}{||>{\centering\columncolor{lightgray}}c}
{Number} & \multicolumn{1}{>{\centering\columncolor{lightgray}[\dimexpr\tabcolsep + 1pt\relax]}c} {List A} & \multicolumn{1}{>{\centering\columncolor{lightgray}[\dimexpr\tabcolsep + 1pt\relax]}c} {List B} & \multicolumn{1}{>{\centering\columncolor{lightgray}[\dimexpr\tabcolsep + 1pt\relax]}c} {List C} & \multicolumn{1}{>{\centering\columncolor{lightgray}[\dimexpr\tabcolsep + 1pt\relax]}c} {List D} & \multicolumn{1}{>{\centering\columncolor{lightgray}}c||} {\makecell{List E\\ List F}}\\ [0.7ex]
\hline\hline
1 & AAAA & BBBB & CCCC & DDDD & EF\\\hline
2 & aaaa  & bbbb & cccc & dddd & ef\\\hline
3 & \makecell{1111\\2222} & \makecell{3333\\4444}  & 5555 & 6666 & 7788\\\hline

\end{tabular}
}
\end{table}


As it can be observed each cell content is not vertically centred. How do I make each cell content vertically and horizontally centred?

## 1 Answer

Welcome to TeX.SE!

• please, always provide MWE (Minimal Working Example), a complete small document, which reproduce your problem
• with help of the cellspace and tabularx package you after cleanup your code you can obtain:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{cellspace, makecell, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\setlength\cellspacetoplimit{7pt}
\setlength\cellspacebottomlimit{7pt}
\addparagraphcolumntypes{C}

\begin{document}
\begin{table}[ht]
\begin{tabularx}{\linewidth}{|| *6{SC} ||}
\hline
\rowcolor{lightgray}
Number
& List A    & List B    & List C    & List D    & \makecell{List E\\ List F}    \\
\hline\hline
1  & AAAA      & BBBB      & CCCC      & DDDD      & EF      \\  \hline
2  & aaaa      & bbbb      & cccc      & dddd      & ef      \\  \hline
3  & \makecell{1111\\2222}
& \makecell{3333\\4444}
& 5555      & 6666      & 7788    \\
\hline
\end{tabularx}
\end{table}
\end{document}

• Thanks Zarko! But how to get rid of those vertical thin white lines in the header? Apr 14, 2020 at 5:21
• @Coder, what yo see are pdf viewer artifacts (image is taken from Sumatra, in Acrobat viewers are not visible). Apr 14, 2020 at 6:40
• @ It is true but in my main code, using [\dimexpr\tabcolsep + 1pt\relax]}c} used to fix it however I don't know how to implement that snippet in your code. Apr 14, 2020 at 6:45
• @Coder, than you use your complicated code as it is. It can not be implemented in tabularx. Apr 14, 2020 at 6:47