[Tex/LaTex] center alignment of headers in table

tablestabularx

I have the following part table:

\begin{table}[!h]
\centering
\begin{adjustbox}{width=1\textwidth}
\small
\begin{tabular}{|l||l|} 
\hline
\textbf{Element Name} & \textbf{Description} \\
\hline
SemiMajorAxis & The length of the semi-major axis $a$, $b$ and $c$ of the 3D \\\hline
\end{tabular} 
\end{adjustbox}
\caption[A description of the XML elements containing the ellipsoid information]{A description of the XML elements containing the information of the ellipsoid.}
\label{tab:XML_defs}
\end{table}

I would like to align the name "Element Name" and "Description" at the center of the cell without affecting the rest of the rows.

Best Answer

You need to replace

\textbf{Element Name} & 
\textbf{Description}

with

\multicolumn{1}{|c||}{\textbf{Element Name}} & 
\multicolumn{1}{c|}{\textbf{Description}}

Instead of using \adjustbox to cram the table into width of the text block, do consider using a tabularx environment instead of the tabular environment and using a column of type X for the second column. Text in an X column will can wrap, as needed. You may also want to consider giving the table a more "open" look, by getting rid of all vertical lines and using horizontal lines more sparingly. In the following screenshot, the second table is drawn with the help of the line-drawing macros of the booktabs package.

enter image description here

\documentclass{article}
\usepackage{tabularx,booktabs}  

\begin{document}
\begin{table}[!h]

\begin{tabularx}{\textwidth}{|l||X|} 
\hline
\multicolumn{1}{|c||}{\textbf{Element Name}} & 
\multicolumn{1}{c|}{\textbf{Description}} \\
\hline
SemiMajorAxis & The length of the semi-major axis $a$, $b$ and $c$ of the 3D \\
\hline
\end{tabularx} 
\caption[A description of the XML elements containing the ellipsoid information]{A description of the XML elements containing the information of the ellipsoid.}
\label{tab:XML_defs}

\bigskip\bigskip
\begin{tabularx}{\textwidth}{lX} 
\toprule
\textbf{Element Name} & \textbf{Description} \\
\addlinespace
SemiMajorAxis & The length of the semi-major axis $a$, $b$ and $c$ of the 3D \\
\bottomrule
\end{tabularx} 
\caption{Another, more ``open'' form of the same table}
\end{table}
\end{document}
Related Question