所有表格的格式?

所有表格的格式?

我有一张这样的桌子:

\documentclass[12pt,a4paper,oneside]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{here}

\begin{document}
   \begin{table}[H]
    \centering
     \caption{Copas}\label{tab1}
      \begin{tabular}{|p{3cm}|c|c|c|c|c|c|}
      \hline
       & H & M & H & M & H & M \\
      \hline
      Vasos & 1,5 & 1,0 & 4,0 & 2,0 & 3,8 & 2,0 \\
      \hline
      Copas & 2,0 & 1,5 & 3,8 & 2,0 & 3,8 & 2,0 \\
      \hline
      \end{tabular}
      \end{table}
\end{document}

可以为所有表格设置一种格式吗?例如,我希望所有单元格都采用这种格式\textsf{...},但我不想为每个单词都采用这种格式。

答案1

您可以定义一个新的列类型,例如,K它使用\sffamily和原始c类型,这需要array包。

\sffamily是持久的字体声明,而不是版本\textsf{...},仅限于该{...}对。

\newcolumntype{K}{>{\sffamily\arraybackslash}c}

我怀疑垂直线是否有必要,但我保留了它们。

顺便说一句,在这种情况下,可以使用|*{6}{c|}或重复列规范|*{6}{K|}

\documentclass[12pt,a4paper,oneside]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage{here} % Useful???
\usepackage{array}

\newcolumntype{K}{>{\sffamily\arraybackslash}c}

\begin{document}
\begin{table}
  \centering
  \caption{Copas}\label{tab1}
  \begin{tabular}{|p{3cm}|*{6}{K|}}
    \hline
    & H & M & H & M & H & M \\
    \hline
    Vasos & 1,5 & 1,0 & 4,0 & 2,0 & 3,8 & 2,0 \\
    \hline
    Copas & 2,0 & 1,5 & 3,8 & 2,0 & 3,8 & 2,0 \\
    \hline
  \end{tabular}
\end{table}

\begin{table}


\centering
  \caption{Copas}\label{tab2}
  \begin{tabular}{|p{3cm}|*{6}{K|}}
    \cline{2-7}
    \multicolumn{1}{c|}{} & H & M & H & M & H & M \\
    \hline
    Vasos & 1,5 & 1,0 & 4,0 & 2,0 & 3,8 & 2,0 \\
    \hline
    Copas & 2,0 & 1,5 & 3,8 & 2,0 & 3,8 & 2,0 \\
    \hline
  \end{tabular}

\end{table}


\end{document}

软件包的一些改进booktabs

\documentclass[12pt,a4paper,oneside]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{booktabs}

\newcolumntype{K}{>{\sffamily\arraybackslash}c}

\begin{document}
\begin{table}
  \centering
  \caption{Copas}\label{tab1}
  \begin{tabular}{|p{2cm}|*{6}{K|}}
    \hline
    & H & M & H & M & H & M \\
    \hline
    Vasos & 1,5 & 1,0 & 4,0 & 2,0 & 3,8 & 2,0 \\
    \hline
    Copas & 2,0 & 1,5 & 3,8 & 2,0 & 3,8 & 2,0 \tabularnewline
    \hline
  \end{tabular}
\end{table}

\begin{table}
  \centering
  \caption{Copas}\label{tab2}

  \begin{tabular}{|p{2cm}|*{6}{K|}}
    \cline{2-7}
    \multicolumn{1}{c|}{} & H & M & H & M & H & M \tabularnewline
    \hline
    Vasos & 1,5 & 1,0 & 4,0 & 2,0 & 3,8 & 2,0 \tabularnewline
    \hline
    Copas & 2,0 & 1,5 & 3,8 & 2,0 & 3,8 & 2,0 \tabularnewline
    \hline
  \end{tabular}

\end{table}


\begin{table}
  \centering
  \caption{Copas}\label{tab3}

  \begin{tabular}{p{2cm}*{6}{K}}
    \toprule
    \multicolumn{1}{c}{} & H & M & H & M & H & M \tabularnewline
    \midrule
    Vasos & 1,5 & 1,0 & 4,0 & 2,0 & 3,8 & 2,0 \tabularnewline
    \midrule
    Copas & 2,0 & 1,5 & 3,8 & 2,0 & 3,8 & 2,0 \tabularnewline
    \midrule
  \end{tabular}

\end{table}

\end{document}

在此处输入图片描述

相关内容