2

I would like to have a table where the cell content of the first table row is centered. Then I would like to have a separator line between both columns starting from the second row. I have also managed something, however I would be interested if there is a better and nicer way. However, centering the first row with \centering unfortunately only worked for the first column.

Here is my code:

\begin{table}[H]
\setlength\extrarowheight{5pt}
\caption{Table}
    \centering
\begin{tabular}{ m{7.5cm} m{7.5cm} }  
        \hline
       \rowcolor[HTML]{EFEFEF} 
        \textbf{Column1}     &    \textbf{Column2}      \\ \hline \hline
\end{tabular}
 \begin{tabular}{ m{7.5cm} | m{7.5cm} }
    Text Here   & Text Here  \\ \hline
    Text Here   & Text Here 
    \end{tabular}
\end{table}
1
  • Welcome to tex.sx. Commented Dec 5, 2022 at 14:15

2 Answers 2

1

Do you mean like this?

\documentclass{article}

\usepackage{array}
\usepackage[table]{xcolor}

\begin{document}
\begin{table}%[H]
\setlength\extrarowheight{5pt}
\caption{Table}
    \centering
\begin{tabular}{ >{\centering\arraybackslash}m{7.5cm} >{\centering\arraybackslash}m{7.5cm} }  
        \hline
       \rowcolor[HTML]{EFEFEF} 
        \textbf{Column1}     &    \textbf{Column2}      \\ \hline \hline
\end{tabular}
 \begin{tabular}{ m{7.5cm} | m{7.5cm} }
    Text Here   & Text Here  \\ \hline
    Text Here   & Text Here 
    \end{tabular}
\end{table}
\end{document}

enter image description here

Or with a single tabular:

\begin{tabular}{ m{7.5cm} | m{7.5cm} }  
        \hline
       \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{c}{\textbf{Column1}}     &    \multicolumn{1}{c}{\textbf{Column2}}      \\ \hline \hline
    Text Here   & Text Here  \\ \hline
    Text Here   & Text Here 
\end{tabular}
1

Here is a way to create that table with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{caption}
\usepackage{nicematrix}

\begin{document}

\begin{table}
\setlength\extrarowheight{5pt}
\caption{Table}
\centering
\begin{NiceTabular}{ m[c]{7.5cm} | m[c]{7.5cm} }
    \Hline
    \Block[fill=[HTML]{EFEFEF}]{1-2}{}
    \textbf{Column1} & \textbf{Column2} \\ \Hline\Hline
    Text Here        & Text Here        \\ \Hline
    Text Here        & Text Here 
    \end{NiceTabular}
\end{table}

\end{document}

Output of the above code

You must log in to answer this question.

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