0

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}

enter image description here

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 1

3

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:

enter image description here

\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}
4
  • Thanks Zarko! But how to get rid of those vertical thin white lines in the header?
    – Coder
    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).
    – Zarko
    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.
    – Coder
    Apr 14, 2020 at 6:45
  • @Coder, than you use your complicated code as it is. It can not be implemented in tabularx.
    – Zarko
    Apr 14, 2020 at 6:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .