如何使表格仅第一行居中?

如何使表格仅第一行居中?

很抱歉打扰您,但我尝试制作这样的表格:在此处输入图片描述

第一行居中,其他行可以左对齐或右对齐。

和我的代码:

\begin{table*}[!htbp]
\caption{Speech content guidance for SoHRI.}\label{tab:6}
\centering
\begin{tabular}
{| m{4.7cm} | >{\centering}m{1.2cm} | m{1.2cm}<{\centering}| m{1.4cm} <{\centering}| m{1.4cm} <{\centering}| m{1.4cm}<{\centering}|m{1.4cm}<{\centering}|}
\hline
\multirow{2}*{\textbf{Action}} & \multirow{2}{=}{\textbf{Ground Truth}} & \multirow{2}*{$\bar{E}_{M}$} & \multicolumn{4}{c|}{$L_{i}(\%)$} \\
        \cline{4-7}
        ~ & ~ & ~ & \textbf{Formal} & \textbf{Relaxed}& \textbf{Sad} & \textbf{Negligent} \\
\hline
\textbf{A01:} right arm swipe to the left
&$-$&$-$0.2354&87.50{\%}&12.50{\%}&0{\%}&0{\%}\\
\hline
\textbf{A02:} right arm swipe to the right
&$+$&0.2238&90.63{\%}&9.37{\%}&0{\%}&0{\%}\\
\hline
\textbf{A03:} right hand wave
&$+$&0.1934&75.00{\%}&25.00{\%}&0{\%}&0{\%}\\
\hline
\end{tabular}
\end{table*}

像这样编译: 在此处输入图片描述

我只知道如何使整个列居中..所以有人可以帮忙吗?

答案1

我对格式做了一些改动。请注意,“Negligent”的宽度大于 1.2 厘米。

\documentclass[twocolumn]{article}
\usepackage{array,multirow}
\usepackage{showframe}
\begin{document}

\begin{table*}[tp]% table* does not support [hb], and [!] is pointless
\caption{Speech content guidance for SoHRI.}\label{tab:6}
\centering
\begin{tabular}
{| m{5cm} |c|r|r|r|r|r|r|}
\hline
\multirow{2}*{\textbf{Action}} & \multirow{2}*{\parbox[c]{1.4cm}{\centering\textbf{Ground Truth}}} &
  \multicolumn{1}{c|}{\multirow{2}*{$\bar{E}_{M}$}} & \multicolumn{4}{c|}{$L_{i}(\%)$} \\
\cline{4-7}
~ & ~ & ~ & \makebox[1.2cm]{\textbf{Formal}} & \makebox[1.2cm]{\textbf{Relaxed}}
  & \makebox[1.2cm]{\textbf{Sad}} & \makebox[1.2cm]{\textbf{Negligent}} \\
\hline
\textbf{A01:} right arm swipe to the left
&$-$&$-$0.2354&87.50{\%}&12.50{\%}&0{\%}&0{\%}\\
\hline
\textbf{A02:} right arm swipe to the right
&$+$&0.2238&90.63{\%}&9.37{\%}&0{\%}&0{\%}\\
\hline
\textbf{A03:} right hand wave
&$+$&0.1934&75.00{\%}&25.00{\%}&0{\%}&0{\%}\\
\hline
\end{tabular}
\end{table*}

\end{document}

演示


在这个解决方案中,我测量了“疏忽”的宽度并分裂了“地面真相”。

\documentclass[twocolumn]{article}
\usepackage{array,multirow}
\usepackage{showframe}
\begin{document}

\begin{table*}[tp]% table* does not support [hb], and [!] is pointless
\caption{Speech content guidance for SoHRI.}\label{tab:6}
\centering
\sbox0{\textbf{Negligent}}% measuare width
\begin{tabular}
{| m{4cm} |c|r|r|r|r|r|r|}
\hline
\multirow{2}*{\textbf{Action}} & \textbf{Ground} &
  \multicolumn{1}{c|}{\multirow{2}*{$\bar{E}_{M}$}} & \multicolumn{4}{c|}{$L_{i}(\%)$} \\
\cline{4-7}
~ & \textbf{Truth} & ~ & \makebox[\wd0]{\textbf{Formal}} & \makebox[\wd0]{\textbf{Relaxed}}
  & \makebox[\wd0]{\textbf{Sad}} & \makebox[\wd0]{\textbf{Negligent}} \\
\hline
\textbf{A01:} right arm swipe to the left
&$-$&$-$0.2354&87.50{\%}&12.50{\%}&0{\%}&0{\%}\\
\hline
\textbf{A02:} right arm swipe to the right
&$+$&0.2238&90.63{\%}&9.37{\%}&0{\%}&0{\%}\\
\hline
\textbf{A03:} right hand wave
&$+$&0.1934&75.00{\%}&25.00{\%}&0{\%}&0{\%}\\
\hline
\end{tabular}
\end{table*}

\end{document}

答案2

这是您想要的吗?我不认为%所有单元格中的都是必要的,因为它是在中指定的\multicolumn{4}{c}{...}

\documentclass[twocolumn]{article}
\usepackage[showframe]{geometry}
\usepackage{tabularx, caption, multirow, makecell, siunitx}
\renewcommand{\theadfont}{\normalsize\bfseries}

\begin{document}

\begin{table*}[!htbp]
  \setlength{\extrarowheight}{2pt}
\caption{Speech content guidance for SoHRI.}\label{tab:6}
\centering
\setlength{\tabcolsep}{4pt}
\begin{tabularx}{\linewidth}{|>{\hsize=1.6\hsize}X | >{\hsize =0.4\hsize\centering}X |S[table-format=-1.4]|*{4}{r|}}
\hline
\multirow{2}{=}[-1ex]
{\textbf{Action}} & & {\multirow{2}{*}[-1ex]{$ \bar{E}_{M}$}} & \multicolumn{4}{c|}{$L_{i}\,(\%)$}% $}}
 \\
        \cline{4-7}
        ~ & \multirow{-2}{*}[-0.2ex]{\thead{Ground\\ Truth}} & ~ & \thead{Formal} & \thead{Relaxed}& \thead{Sad} & \thead{Negligent} \\
\hline
\textbf{A01:} right arm swipe to the left
&$-$& -0.2354 & 87.50 & 12.50 & 0 & 0 \\
\hline
\textbf{A02:} right arm swipe to the right
&$+$& 0.2238& 90.63 & 9.37 & 0 & 0 \\
\hline
\textbf{A03:} right hand wave
&$+$& 0.1934 & 75.00 & 25.00 & 0 & 0 \\
\hline
\end{tabularx}
\end{table*}

\end{document} 

在此处输入图片描述

相关内容