Center only heading text in a table

It's easier to define the general alignment of the table, and use multicolum to center the header text:

\documentclass[10pt,a4paper]{article}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}

\begin{document}
\begin{table}
\caption{Title}
\centering
\begin{tabular}{|>{\raggedright\arraybackslash}m{23mm}|m{23mm}|m{60mm}|}
\hline
\multicolumn{1}{|>{\centering\arraybackslash}m{23mm}|}{\rowcolor{Gray}\textbf{Very long title}} 
    & \multicolumn{1}{>{\centering\arraybackslash}m{23mm}|}{\textbf{Very long title}} 
    & \multicolumn{1}{>{\centering\arraybackslash}m{60mm}|}{\textbf{Normal title}}\\
\hline
Text & Text 
    & Very very very very very very very very very very 
        very veryvery very very very very very very very long text \\
\hline
Very very very very very verryy very very very very very long text 
    & Very very very very very verryy very very very very very long text
    & Text \\
\hline
\end{tabular}
\end{table}
\end{document}

Edit: I have modified my answer to reflect your example.

  • Column 1 is left aligned, as asked, using \raggedright
  • Column 2 is justified (normal paragraphs) with the same content as the column 1
  • Column 3 is justified with a short title

Table


\documentclass[10pt,a4paper]{article}
\usepackage[table]{xcolor}
\usepackage{array,ragged2e}

\begin{document}

\begin{table} [!htb]
\caption{Title}
\centering
\begin{tabular}{| m{23pt} | m{60pt}|}\hline
\multicolumn{1}{c}{\cellcolor{black!30}\textbf{text}} & 
  \multicolumn{1}{c}{\cellcolor{black!30}\textbf{text}}\\\hline
Text & Text\\\hline
Text & T \\\hline
text & text\\\hline
text & t\\\hline
\end{tabular}
\end{table}

\end{document}

enter image description here

or for long headings:

\documentclass[10pt,a4paper]{article}
\usepackage[table]{xcolor}
\usepackage{array,ragged2e}

\begin{document}

\begin{table} [!htb]
\caption{Title}
\centering
\begin{tabular}{| m{23pt} | m{60pt}|}\hline
\rowcolor{black!30}\Centering\bfseries foo
  & \Centering\bfseries Her comes some extremely long text for the first heading\\\hline
Text & Text\\\hline
Text & T \\\hline
text & text\\\hline
text & t\\\hline
\end{tabular}
\end{table}

\end{document}

enter image description here

Tags:

Tables