2

Given the following LaTeX table, how can I make all cells have a bold style?

MWE:

\documentclass{article}
\begin{document}
    \begin{table}[ht]%
        \centering
        \caption[Data description]{Dataset description}
        \begin{tabular}{|l|l|c|c|c|c|}
            \hline
             &Dataset      &Samples&Numerical&Categorical&Class\\ \hline
            1&Horse        & 300   &  7      & 16        & 2   \\ \hline
            2&Ionosphere   & 351   & 32      &  1        & 2   \\ \hline
            3&Band         & 540   & 13      &  6        & 2   \\ \hline
            4&Australian+MV& 621   &  3      & 11        & 2   \\ \hline
            5&Hepatitis    & 155   &  2      & 17        & 2   \\ \hline
            6&Credit       & 690   &  3      & 12        & 2   \\ \hline
        \end{tabular}
        \label{tab:data}
    \end{table}
\end{document}
BrechtDeMan
  • 6,589
  • 4
  • 24
  • 25
Ahmed Hamed
  • 25
  • 1
  • 6

2 Answers2

3

You can set the formatting of each column in the tabular argument with >{...}, see Tabular, make a column or a row emphasized:

\begin{tabular}{|>{\bfseries}l|>{\bfseries}l|>{\bfseries}c|>{\bfseries}c|>{\bfseries}c|>{\bfseries}c|}

Use the *{num}{str} syntax to make it shorter and more readable:

\begin{tabular}{*{2}{|>{\bfseries}l} *{4}{|>{\bfseries}c} |}\hline

I.e. 'two times flush left and bold', then 'four times centred and bold'. (Note that \bf is deprecated.)

Your MWE:

\documentclass{article}

\usepackage{array} % otherwise you get "Error: Illegal character in array arg."

\begin{document}
    \begin{table}[ht]%
        \centering
        \caption[Data description]{Dataset description}
        \begin{tabular}{*{2}{|>{\bfseries}l} *{4}{|>{\bfseries}c} |}\hline
             &Dataset      &Samples&Numerical&Categorical&Class\\ \hline
            1&Horse        & 300   &  7      & 16        & 2   \\ \hline
            2&Ionosphere   & 351   & 32      &  1        & 2   \\ \hline
            3&Band         & 540   & 13      &  6        & 2   \\ \hline
            4&Australian+MV& 621   &  3      & 11        & 2   \\ \hline
            5&Hepatitis    & 155   &  2      & 17        & 2   \\ \hline
            6&Credit       & 690   &  3      & 12        & 2   \\ \hline
        \end{tabular}
        \label{tab:data}
    \end{table}

\end{document}

You can also set the formatting of a whole row (less interesting in this case) - see for instance How to change a whole row of a table.


Note: you can make a single cell normal again by using \normalfont{}.

Community
  • 1
  • 1
BrechtDeMan
  • 6,589
  • 4
  • 24
  • 25
0
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{table}[ht]%
% If you want all in bold face then enclose it between {\ bf  }
    \centering {\bf
    \caption[Data description]{Dataset description}
    \begin{tabular}{|l|l|c|c|c|c|}\hline            
       & Dataset      & Samples & Numerical & Categorical & Class\\\hline
        1 & Horse        & 300   &  7      & 16        & 2   \\\hline
        2 & Ionosphere   & 351   & 32      &  1        & 2   \\\hline
        3 & Band         & 540   & 13      &  6        & 2   \\\hline
        4 & Australian+MV& 621   &  3      & 11        & 2   \\\hline
        5 & Hepatitis    & 155   &  2      & 17        & 2   \\\hline
        6 & Credit       & 690   &  3      & 12        & 2   \\\hline
    \end{tabular}
    \label{tab:data}
vaman
  • 1