How can I only make table headers center and bold?
The simplest way to do that is to use the makecell
package, which is done for formatting column heads. In addition, for free, you have that, by default, the contents of column heads are centred, both vertically and horizontally, and they can have line breaks. Here are two ways, with and without vertical rules:
\documentclass{article}
\usepackage{array, booktabs, caption}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{table description}
\label{t_sim}
\begin{tabular}{|l|l|}
\hline
\thead{Key} & \thead{Value} \\
\hline
$x$ & description of x \\
$y$ & description of y \\
$y$ & description of z \\
\hline
\end{tabular}
\end{table}
\vskip1cm
\begin{table}[!htbp]
\centering
\caption{table description}
\label{t_sim}
\begin{tabular}{ll}
\toprule
\thead{Key} & \thead{Value} \\
\midrule
$x$ & description of x \\
$y$ & description of y \\
$y$ & description of z \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
- Use
\centering
inside the\begin{table}...\end{table}
pair, this is safe, since it's inside a group and won't bleed into the following text... - Use
\multicolumn{1}{|c|}{\textbf{Key}}
for the first column and\multicolumn{1}{c|}{\textbf{Value}}
for the 2nd column. Note that the 2nd isc|
and not|c|
, otherwise the|
would be doubled. \textbf{Key}
etc. for bold font text
\documentclass{article}
\begin{document}
\begin{table}
\centering
\caption{table description}
\label{t_sim}
\begin{tabular}{|l|l|}
\hline
\multicolumn{1}{|c|}{\textbf{Key}} & \multicolumn{1}{c|}{\textbf{Value}} \\
\hline
$x$ & description of x \\
$y$ & description of y \\
$y$ & description of z \\
\hline
\end{tabular}
\end{table}
\end{document}
Here is a version using booktabs
and makecell
. The results are different with IEEEtran.cls
, however. (See below: this is why a Minimum Working Example is so important.)
\centering
is a better option than the center
environment within floats (e.g. table
, figure
etc.) as it avoid adding excessive vertical spacing.
\documentclass{article}
\usepackage{array,booktabs,makecell}
\renewcommand\theadfont{\bfseries}% bold tabular headers
\renewcommand\theadalign{cc}% centred tabular headers
\renewcommand\theadgape{}% booktabs rules already add vertical spacing
\begin{document}
\begin{table}
\centering% will not add additional vertical space as center will - since table already adds spacing, you do not want extra here
\caption{table decription}
\label{t_sim}
\begin{tabular}{*{2}{l}}
\toprule% professional horizontal rules of variable weight from booktabs
\thead{Key} & \thead{Value}\\
\midrule% professional horizontal rules of variable weight from booktabs
$x$ & description of x \\
$y$ & description of y \\
$y$ & description of z \\
\bottomrule% professional horizontal rules of variable weight from booktabs
\end{tabular}
\end{table}
\end{document}
Switching the class to IEEEtran.cls
produces this:
Here is the result shown with some dummy text to illustrate placement:
Here is the result with the conference
option for the class:
If you are preparing a manuscript for submission, don't bother formatting things as you want as you will need to stick to the required style provided by the class etc. anyway. If you are not preparing for submission, you will find life easier if you use a more general-purpose class designed for greater flexibility.