2

给定以下 LaTeX 表格,如何使所有单元格都具有粗体样式?

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}
4

2 回答 2

3

您可以使用 设置表格参数中每一列>{...}的格式,请参阅表格,强调一列或一行

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

使用*{num}{str}语法使其更短且更具可读性:

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

即“两次向左冲洗并加粗”,然后“四次居中加粗”。(请注意,\bf 已弃用。)

您的 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}

您还可以设置整行的格式在这种情况下不太有趣)-例如参见How to change a whole row of a table


注意:您可以使用使单个单元格再次正常\normalfont{}

于 2016-09-26T09:11:19.680 回答
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}
于 2016-10-23T13:51:39.177 回答