将加减号放在单元格的第二行

将加减号放在单元格的第二行

我有一张很大的表格,需要在其中指定std值。如果我使用常规值,\pm表格就会溢出边框。

矩阵如下:

\documentclass[sigconf,natbib=false]{acmart}
\usepackage[utf8]{inputenc}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{diagbox}

\title{Test}
\author{Michael Sidorov}
\date{September 2021}

\begin{document}

\begin{table*}
  \centering
  \renewcommand{\arraystretch}{1.2}
  \begin{tabular}{|l||*{3}{c|}}
    \hline
    \backslashbox{\textbf{Model}}{\textbf{Data Set}} & \multicolumn{3}{c|}{\textbf{Data Set 1}} \\
    \hline
    \textbf{Metric} & 
    \textbf{P} & \textbf{$F_1$} & \textbf{R} \\
    \hline\hline
    $A$ & $0.59\pm0.004$ & $0.58\pm0.0017$ & $0.58\pm0.002$ \\ \hline
  \end{tabular}
  \caption{Table 1}
\end{table*}
\maketitle

\section{Introduction}

\end{document}

我的问题: 我怎样才能将\pm符号放在平均值下面,如下所示:

在此处输入图片描述

提前致谢。

答案1

\usepackage{makecell}是你的朋友:

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{diagbox}
\usepackage{makecell}

\begin{document}

\begin{table*}
  \centering
  \renewcommand{\arraystretch}{1.2}
  \begin{tabular}{|l||*{3}{c|}}
    \hline
    \backslashbox{\textbf{Model}}{\textbf{Data Set}} & \multicolumn{3}{c|}{\textbf{Data Set 1}} \\
    \hline
    \textbf{Metric} &
    \textbf{P} & \textbf{$F_1$} & \textbf{R} \\
    \hline\hline
    $A$ & \makecell{$0.59$\\ $\pm0.004$} & \makecell{$0.58$\\$\pm0.0017$} & \makecell{$0.58$\\$\pm0.002$} \\ \hline
  \end{tabular}
  \caption{Table 1}
\end{table*}

\end{document}

答案2

添加另一行包含pm值的内容并减少最后两行之间的间距。

b

\documentclass[sigconf,natbib=false]{acmart}

\usepackage{diagbox}
\usepackage{multirow}

\title{Test}
\author{Michael Sidorov}
\date{S\today}

\begin{document}
    
\begin{table*}
    \centering
    \renewcommand{\arraystretch}{1.2}
    \begin{tabular}{|c||*{3}{l|}}
        \hline
        \backslashbox{\textbf{Model}}{\textbf{Data Set}} &\multicolumn{3}{c|}{\textbf{Data Set 1}}  \\      \hline
        \textbf{Metric}         &\multicolumn{1}{c|}{\textbf{P}}&\multicolumn{1}{c|}{\textbf{$F_1$}}& \multicolumn{1}{c|}{\textbf{R}}\\     \hline\hline
        \multirow{2}{*}{$A$}    & $0.59$                        & $0.58$                            & $0.58$                        \\[-5pt]
                                & $\pm0.004$                    & $\pm0.0017$                       & $\pm0.002$                    \\ \hline
    \end{tabular}
    \caption{Table 1}
\end{table*}

\maketitle

\section{Introduction}

\end{document}

答案3

使用新的 LaTeX-3 包tabularraysiunitx针对S列类型(通过选项调用)和稍微重新设计的表格线。通过定义新的子选择器,每秒在表体中si={...}绘制并减少:\hlinerowsep

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{diagbox, siunitx}

\usepackage[skip=1ex,
            font=small,
            labelfont=bf
            ]{caption}
\usepackage{cprotect}   % for use verb in caption

\begin{document}
    \begin{table}
\ExplSyntaxOn
\NewChildSelector{eachtwo}
  {
    \int_step_inline:nnnn {3}{2}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff
%
\cprotect\caption{Table is written by ose of the \verb+tabularray+ package}
    \centering
\begin{tblr}{hline{1,3,Z} = 1pt, hline{2} = {solid},
             hline{eachtwo} ={solid},
             vlines,
             colspec  = {l *{3}{Q[c, m, si={table-format=+1.4}] } },
             row{1,2} = {font=\bfseries},
             row{eachtwo} = {belowsep=-4pt},
             }
\diagbox{Model}{Data Set}
        & \SetCell[c=3]{c} {{{Data Set 1}}}
                    &               &           \\
Metric & {{{P}}}    & {{{$F\textsubscript{1}}}}     
                                    & {{{R}}}   \\
\SetCell[r=2]{l}    $A$
        & 0.59      & 0.58          &   0.58    \\
        & \pm 0.004 & \pm 0.0017    & \pm 0.002 \\
\SetCell[r=2]{l}    $B$
        & 0.59      & 0.58          &   0.58    \\
        & \pm 0.004 & \pm 0.0017    & \pm 0.002 \\
\SetCell[r=2]{l}    $C$
        & 0.59      & 0.58          &   0.58    \\
        & \pm 0.004 & \pm 0.0017    & \pm 0.002 \\
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

相关内容