[Tex/LaTex] create table with only header bold and center

tables

How to create a table using latex – only it's 1st row bold and center and others are left side and normal.

\begin{table}


\renewcommand{\arraystretch}{1.5}


\caption[m1]{ m2}


\label{Hardware}\centering

\begin{tabular}{|c|c|c|c|}

\hline

a & b & c & d  \\ \hline

a  & b  & c & d\\ \hline

a & b & c & d \\ \hline

\end{tabular}

\end{table}

Best Answer

Tabular does not have a concept of a header. If you want to have one, you have to modify the first row yourself. As Mico pointed out

\begin{tabular}{|l|l|l|l|}
\hline
\multicolumn{1}{c}{\bfseries <Header 1>} & \multicolumn{1}{c}{\bfseries <Header 2>} & \multicolumn{1}{c}{\bfseries <Header 3>} & \multicolumn{1}{c}{\bfseries <Header 4>} \\ \hline
a & b & c & d \\ \hline
a & b & c & d \\ \hline
\end{tabular}

Of course, this is somewhat verbose and cumbersome. Two possible simplifications:

  1. First possibility: Define a macro for this

    \newcommand*{\thead}[1]{\multicolumn{1}{c}{\bfseries #1}}
    

    and then use it:

    \begin{tabular}{|l|l|l|l|}
    \hline
    \thead{<Header 1>} & \thead{<Header 2>} & \thead{<Header 3>} & \thead{<Header 4>} \\ \hline
    a & b & c & d \\ \hline
    a & b & c & d \\ \hline
    \end{tabular}
    
  2. Second possibiliy: Alternatively, use the tabu package, which allows to specify individual row formating via the \rowfont command

    \begin{tabu}{|l|l|l|l|}
    \hline
    \rowfont[c]{\bfseries} <Header 1> & <Header 2> & <Header 3> & <Header 4> \\ \hline
    a & b & c & d \\ \hline
    a & b & c & d \\ \hline
    \end{tabu}