表头中的数学模式(tabularx)

表头中的数学模式(tabularx)

我正在使用自定义类编辑文档。作者在表头中有数字,上面有横线,例如$0.58\bar3$。但是,当我尝试编译它时,出现以下错误:

! Package amsmath Error: \bar allowed only in math mode.
! Missing $ inserted.
! Missing } inserted.

我检查了一遍又一遍,我实际上并没有漏掉 $ 或 }。如果我注释掉该行,那么\bar一切都会好起来。

在表格中使用数学模式有什么秘诀吗?

ETA:尝试 MWE –

\documentclass{socsci}
\let\footnote=\endnote
\usepackage{longtable}
\usepackage{rotating}
\usepackage[flushleft]{threeparttable}
\usepackage{siunitx}
\sisetup{input-symbols  = {()},
     group-digits       = false}

\usepackage{epstopdf}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `basename #1 .tif`.png}
\widowpenalty10000
\clubpenalty10000
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{changepage}

\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\makeatletter 
\g@addto@macro{\UrlBreaks}{\do\/\do\-} 
\makeatother
\newcommand\fignote[1]{\captionsetup{font=footnotesize}\caption*{#1}}
\setlength\multlinegap{0pt} %For multi-line equations that are aligned to left margin

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc,decorations.pathmorphing,backgrounds,fit,petri,automata} 
\usetikzlibrary{datavisualization.formats.functions}
\usepackage{verbatim}
\usepackage{fancybox}
\usepackage{float}
\usepackage{natbib}

\tikzset{
 state/.style={
 rectangle,
 rounded corners,
 draw=black, very thick,
 minimum height=2em,minimum width=2cm,
 inner sep=2pt,
 text centered,
 },
}


\newcommand*{\LargerCdot}{\raisebox{-0.25ex}{\scalebox{1.2}{$\cdot$}}}


\begin{document}

%tab6
\begin{table*}[t!]
\begin{adjustwidth}{-1.5in}{}
\begin{threeparttable}
\caption{Network density.}
 \label{tab6}
\centering
\footnotesize
\begin{tabularx}{6.5in}{@{\extracolsep{\fill}}l*5{d{2.2}}} 
\toprule
Density & $\leq 0.50$ & $0.58\bar3$ & $0.66\bar6$ & $0.750$ & $>0.75$ \\ \midrule \addlinespace
 & \% & \% & \% & \% & \% \\
Disconnected & 16.27 & 0.23 & 0 & 0 & 0 \\
Weak & 26.61 & 0.70 & 0 & 0 & 0 \\
Unilateral & 51.45 & 51.98 & 15.76 & 2.80 & 0 \\
Strong & 5.67 & 47.09 & 84.24 & 97.20 & \ccell{100} \\ \midrule \addlinespace
Total \% & \ccell{100} & \ccell{100} & \ccell{100} & \ccell{100} & \ccell{100} \\
Total n & \ccell{25,376} & \ccell{27,456} & \ccell{7,920} & \ccell{4,576} & \ccell{208} \\
\bottomrule
\end{tabularx}
\end{threeparttable}
\end{adjustwidth}
\end{table*}

\end{document}

答案1

\bar您需要将指令中包含的内联数学术语括起来\ccell。题外话:我会使用\overline而不是\bar来表示重复的小数。

如果您要将列中的数字按小数点对齐,那么如果大多数数字实际上包含小数点,那么您将真正帮助您的读者。因此,0.00不要只写0,而要写 ,100.00不要只写100。并且,请将列结构定义为 ,d{3.2}而不是d{2.2}

以下可编译示例使用article文档类,因为我不知道socsci文档类来自哪里。

在此处输入图片描述

\documentclass{article}% {socsci} % where might socsci.cls be found?
\usepackage{amsmath,booktabs,dcolumn,caption}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand\ccell[1]{\multicolumn{1}{c}{#1}} % a wild guess...
\captionsetup{skip=0.5\baselineskip}
\begin{document}

\begin{table}[t!]
\setlength\tabcolsep{0pt} % let tabular* do all the work
\caption{Network density.} 
\label{tab6}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l*{5}{d{2.2}}} 
\toprule
Density & \ccell{$\leq 0.50$} & \ccell{$0.58\overline3$} 
        & \ccell{$0.66\overline6$} & \ccell{$0.750$} 
        & \ccell{$>0.75$} \\ 
\midrule
 & \ccell{\%} & \ccell{\%} & \ccell{\%} & \ccell{\%} & \ccell{\%} \\
\addlinespace
Disconnected & 16.27 &  0.23 &  0.00 &  0.00 &   0.00 \\
Weak         & 26.61 &  0.70 &  0.00 &  0.00 &   0.00 \\
Unilateral   & 51.45 & 51.98 & 15.76 &  2.80 &   0.00 \\
Strong       &  5.67 & 47.09 & 84.24 & 97.20 & 100.00 \\ 
\addlinespace
Total \%    & 100.00 &100.00 &100.00 &100.00 & 100.00 \\
\addlinespace
Total $n$ & \ccell{25,376} & \ccell{27,456} & \ccell{7,920} & \ccell{4,576} & \ccell{208} \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}

答案2

通过猜测您的(并非如此)MWE 中缺少什么以及省略我认为多余的内容,我得到了下表:

在此处输入图片描述

上表的代码为:

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs,makecell,multirow,tabularx}

\begin{document}
\begin{table*}[htb]
    \caption{Network density.}
\label{tab6}
    \centering
    \footnotesize
\begin{tabularx}{\textwidth}{@{\extracolsep{\fill}}l*5{S[table-format=>2.4]}}%
    \toprule
Density     & \leq 0.50 &{$~~0.58\bar3$}&{$~~0.66\bar6$}& 0.750 & >0.75 \\ 
    \midrule
            & {\%}      & {\%}          & {\%}          & {\%}  & {\%}  \\
Disconnected& 16.27     & 0.23          & 0             & 0     & 0     \\
Weak        & 26.61     & 0.70          & 0             & 0     & 0     \\
Unilateral  & 51.45     & 51.98         & 15.76         & 2.80  & 0     \\
Strong      & 5.67      & 47.09         & 84.24         & 97.20 & 100   \\ 
    \midrule 
Total \%    & {100}     & {100}         & {100}         & {100} & {100} \\
Total n     & {25,376}  & {27,456}      & {7,920}       & 4,576 & 208   \\
    \bottomrule
\end{tabularx}
\end{table*}
\end{document}

使用文章文档类我无法重现您的问题。

相关内容