在 Latex 中的表中添加空单元格

在 Latex 中的表中添加空单元格

我想在表格中放置一些空单元格,以便我的表格第一行有数字,而下一行第一个单元格仅为空。

我也使用了桌子下面的注释,但是出现了无法解决的错误。

\begin{table}
 \begin{center}
  \begin{threeparttable}
    \caption{Sample of table}
     \begin{tabular}{c | c | c |  c}
        \toprule
         \textbf{$Set$}  & \textbf{$d_t$} 
      &\textbf{$d_{mt}$}  & \textbf{$d_{ms}$} 
        \midrule

         A    & 122    &30    & 6.0003\\
              &(3)     &(27)  &(5)\\
         B    & 150    &26    &4  \\
              &(4)     &(2)   &(3)\\
         C    & 5      & 1.5  & 1 \\
              &(4)     &(1)   &(2)\\

        \bottomrule
     \end{tabular}
    \begin{tablenotes}
      \small
      \item This is where authors provide additional information about
      the data, including whatever notes are needed.
    \end{tablenotes}
  \end{threeparttable}
   \end{center}
\end{table}

答案1

\documentclass{book}
\usepackage{threeparttable}

\usepackage[hmargin=3cm]{geometry}   
\usepackage{booktabs}
\usepackage{array}
\usepackage{threeparttable}
\usepackage{graphicx}

\newcommand{\tabhead}[1]{\textbf{#1}}
\newcommand{\rothead}[1]{\rotatebox{45}{\tabhead{#1}}}
\begin{document}


\begin{table}
 \begin{center}
  \begin{threeparttable}
    \caption{Sample of table}
     \begin{tabular}{c | c | c |  c}
        \toprule
         \textbf{$Set$}  & \textbf{$d_t$}  &\textbf{$d_{mt}$}  & \textbf{$d_{ms}$} \\ % you missed \\ 
        \midrule
         A    & 122    &30    & 6.0003\\
              &(3)     &(27)  &(5)\\
         B    & 150    &26    &4  \\
              &(4)     &(2)   &(3)\\
              &        &      & \\
              &        &      & \\
         C    & 5      & 1.5  & 1 \\
              &(4)     &(1)   &(2)\\
        \bottomrule
     \end{tabular}
    \begin{tablenotes}
      \small
      \item This is where authors provide additional information about
      the data, including whatever notes are needed.
    \end{tablenotes}
  \end{threeparttable}
   \end{center}
\end{table}

\end{document}

答案2

除了添加缺失\\部分(正如评论中指出的那样,这是错误消息的最初原因)之外,我还对表代码做了一些调整。所有更改都在以下 MWE 中进行了注释:

在此处输入图片描述

\documentclass{book}
\usepackage{threeparttable}

\usepackage[hmargin=3cm]{geometry}   
\usepackage{booktabs}
\usepackage{array}
%\usepackage{threeparttable} Do not load packages more than once.


\begin{document}


\begin{table}
\centering  % Removed the center environment since it adds vertical white space. Instead you can use the \centering command
  \begin{threeparttable}
    \caption{Sample of table}
     \begin{tabular}{c  c  c   c} % horizontal lines from the booktabs package are intended to be used without vertical lines. I thus removed vertical lines.
        \toprule
         \textbf{Set}  & \boldmath $d_t$ 
      & \boldmath$d_{mt}$  & \boldmath $d_{ms}$ \\ % added missing \\ back in, Removed math mode from "set". Do not use math mode for text. Replaced \textbf around the other column headers with \boldmath
        \midrule

         A    & 122    &30    & 6.0003\\
              &(3)     &(27)  &(5)\\
         B    & 150    &26    &4  \\
              &(4)     &(2)   &(3)\\
         C    & 5      & 1.5  & 1 \\
              &(4)     &(1)   &(2)\\

        \bottomrule
     \end{tabular}
    \begin{tablenotes}[flushleft]\setlength\labelsep{0pt} % added to improve the alignment of the table notes.
      \small
      \item{} This is where authors provide additional information about
      the data, including whatever notes are needed.
    \end{tablenotes}
  \end{threeparttable}
\end{table}


\end{document}

相关内容