添加 xepersian 会导致表格错误

添加 xepersian 会导致表格错误

添加\usepackage{xepersian}会使以下代码产生错误:

\documentclass{article}

\usepackage{booktabs,caption,dcolumn}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}  
\usepackage{lmodern}
\usepackage[hidelinks]{hyperref}    
\usepackage{textcomp}
\usepackage[svgnames]{xcolor}
\usepackage[noabbrev,capitalize]{cleveref}      
\usepackage{amsthm}
\usepackage{thmtools}    
\usepackage{titlesec}       

\newcolumntype{d}[1]{D{.}{.}{4}}% column type for figures with 4 decimals
\newcommand{\subhead}[1]{\multicolumn{1}{c}{#1}}% to format sub-headings of d-type columns
\begin{document}
\begin{table}
  \centering
  \caption{Caption}
  \begin{tabular}{cd{4}d{4}d{4}d{4}d{4}d{4}}
    \toprule 
    \textbf{File}&                       \multicolumn{3}{c}{\textbf{Logistic Regression}}&                    \multicolumn{3}{c}{\textbf{Support Vector Machine}}\\
    \cmidrule(rl){2-4} \cmidrule(rl){5-7} 
                 & \subhead{Sensitivity}& \subhead{Specificity}& \subhead{Total accuracy}& \subhead{Sensitivity}& \subhead{Specificity}& \subhead{Total accuracy}\\ 
    \midrule
         100     &                0.0790&                0.1692&                   0.2945&                0.3670&                0.7187&                    3.1815\\
         101     &             -  0.8651&               50.0476&                   5.9384&             -  9.0714&              297.0923&                   46.2143\\
         102     &              124.2756&             - 50.9612&                 -14.2721&              128.2265&             -630.5455&                 -381.0930\\
         103     &                0.0357&                1.2473&                   0.2119&                0.3593&             -  0.2755&                    2.1764\\
         104     &             - 17.9048&             - 37.1111&                   8.8591&             - 30.7381&             -  9.5952&                 -  3.0000\\
         105     &              105.5518&              232.1160&                 -94.7351&              100.2497&              141.2778&                 -259.7326\\
   \bottomrule
 \end{tabular}
\end{table}
\end{document}

有办法解决这个问题吗?

答案1

\newcolumntypewith的定义有错误dcolumn,正确的语法是 \newcolumntype{d}[1]{D{.}{.}{#1}}

.在输出中使用作为分隔符xepersian,结果为错误???,您可以将其替换为\newcolumntype{d}[1]{D{.}{\mbox{.}}{#1}}

\documentclass{article}

\usepackage{booktabs,caption,dcolumn}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}  
\usepackage{lmodern}
\usepackage[hidelinks]{hyperref}    
\usepackage{textcomp}
\usepackage[svgnames]{xcolor}
\usepackage[noabbrev,capitalize]{cleveref}      
\usepackage{amsthm}
\usepackage{thmtools}    
\usepackage{titlesec}  
\usepackage{xepersian} 
\settextfont{Amiri}    

\newcolumntype{d}[1]{D{.}{\mbox{.}}{#1}}% column type for figures with 4 decimals
\newcommand{\subhead}[1]{\multicolumn{1}{c}{#1}}% to format sub-headings of d-type columns

\begin{document}

\begin{latin}
\begin{table}
  \centering
  \caption{Caption}
  \begin{tabular}{cd{4}d{4}d{4}d{4}d{4}d{4}}
    \toprule 
    \textbf{File}&                       \multicolumn{3}{c}{\textbf{Logistic Regression}}&                    \multicolumn{3}{c}{\textbf{Support Vector Machine}}\\
    \cmidrule(rl){2-4} \cmidrule(rl){5-7} 
                 & \subhead{Sensitivity}& \subhead{Specificity}& \subhead{Total accuracy}& \subhead{Sensitivity}& \subhead{Specificity}& \subhead{Total accuracy}\\ 
    \midrule
         100     &                0.0790&                0.1692&                   0.2945&                0.3670&                0.7187&                    3.1815\\
         101     &             -  0.8651&               50.0476&                   5.9384&             -  9.0714&              297.0923&                   46.2143\\
         102     &              124.2756&             - 50.9612&                 -14.2721&              128.2265&             -630.5455&                 -381.0930\\
         103     &                0.0357&                1.2473&                   0.2119&                0.3593&             -  0.2755&                    2.1764\\
         104     &             - 17.9048&             - 37.1111&                   8.8591&             - 30.7381&             -  9.5952&                 -  3.0000\\
         105     &              105.5518&              232.1160&                 -94.7351&              100.2497&              141.2778&                 -259.7326\\
   \bottomrule
 \end{tabular}
\end{table}
\end{latin}
\end{document}

结果

在此处输入图片描述

答案2

我猜,这个xepersian包做成.了数学活动字符,是为了固定数字的顺序。

您可以在数学模式中通过以下方式定义“正常”版本的周期

\DeclareMathSymbol{\decimalperiod}{\mathord}{letters}{"3A}

但是,您还必须在环境中包含表格latin。我还修复了包加载的顺序(删除了无用的lmodern)。

\documentclass{article}

\usepackage{fontspec}
\usepackage{booktabs,caption,dcolumn}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{titlesec}
\usepackage{textcomp}
\usepackage[svgnames]{xcolor}
\usepackage[hidelinks]{hyperref}
\usepackage[noabbrev,capitalize]{cleveref}

\usepackage{xepersian} 
\settextfont{Amiri}    

\DeclareMathSymbol{\decimalperiod}{\mathord}{letters}{"3A}

\newcolumntype{d}[1]{D{.}{\decimalperiod}{4}}% column type for figures with 4 decimals
\newcommand{\subhead}[1]{\multicolumn{1}{c}{#1}}% to format sub-headings of d-type columns

\begin{document}

\begin{table}
  \centering
  \caption{Caption}
\begin{latin}
  \begin{tabular}{cd{4}d{4}d{4}d{4}d{4}d{4}}
    \toprule 
    \textbf{File}&                       \multicolumn{3}{c}{\textbf{Logistic Regression}}&                    \multicolumn{3}{c}{\textbf{Support Vector Machine}}\\
    \cmidrule(rl){2-4} \cmidrule(rl){5-7} 
                 & \subhead{Sensitivity}& \subhead{Specificity}& \subhead{Total accuracy}& \subhead{Sensitivity}& \subhead{Specificity}& \subhead{Total accuracy}\\ 
    \midrule
         100     &                0.0790&                0.1692&                   0.2945&                0.3670&                0.7187&                    3.1815\\
         101     &             -  0.8651&               50.0476&                   5.9384&             -  9.0714&              297.0923&                   46.2143\\
         102     &              124.2756&             - 50.9612&                 -14.2721&              128.2265&             -630.5455&                 -381.0930\\
         103     &                0.0357&                1.2473&                   0.2119&                0.3593&             -  0.2755&                    2.1764\\
         104     &             - 17.9048&             - 37.1111&                   8.8591&             - 30.7381&             -  9.5952&                 -  3.0000\\
         105     &              105.5518&              232.1160&                 -94.7351&              100.2497&              141.2778&                 -259.7326\\
   \bottomrule
 \end{tabular}
\end{latin}
\end{table}
\end{document}

在此处输入图片描述

siunitx不是dcolumn你会得到更好的结果,没有任何问题.

\documentclass{article}

\usepackage{fontspec}
\usepackage{booktabs,caption,siunitx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{titlesec}
\usepackage{textcomp}
\usepackage[svgnames]{xcolor}
\usepackage[hidelinks]{hyperref}
\usepackage[noabbrev,capitalize]{cleveref}

\usepackage{xepersian} 
\settextfont{Amiri}    

\newcommand{\subhead}[1]{\multicolumn{1}{c}{#1}}% to format sub-headings of d-type columns

\begin{document}

\begin{table}
\centering
\caption{Caption}

\begin{latin}
\begin{tabular}{
 @{}
 l
 S[table-format=-2.4]
 S[table-format=-2.4]
 S[table-format=-2.4]
 S[table-format=-2.4]
 S[table-format=-3.4]
 S[table-format=-3.4]
 @{}
}
\toprule 
\textbf{File} &
  \multicolumn{3}{c}{\textbf{Logistic Regression}} &
  \multicolumn{3}{c}{\textbf{Support Vector Machine}} \\
\cmidrule(rl){2-4} \cmidrule(rl){5-7} 
&
  \subhead{Sensitivity} &
  \subhead{Specificity} &
  \subhead{Total accuracy} &
  \subhead{Sensitivity} &
  \subhead{Specificity}&
  \subhead{Total accuracy} \\
\midrule
100 &   0.0790 &   0.1692 &   0.2945 &   0.3670 &    0.7187 &    3.1815 \\
101 &  -0.8651 &  50.0476 &   5.9384 &  -9.0714 &  297.0923 &   46.2143 \\
102 & 124.2756 & -50.9612 & -14.2721 & 128.2265 & -630.5455 & -381.0930 \\
103 &   0.0357 &   1.2473 &   0.2119 &   0.3593 &   -0.2755 &    2.1764 \\
104 & -17.9048 & -37.1111 &   8.8591 & -30.7381 &   -9.5952 &   -3.0000 \\
105 & 105.5518 & 232.1160 & -94.7351 & 100.2497 &  141.2778 & -259.7326 \\
\bottomrule
\end{tabular}
\end{latin}
\end{table}
\end{document}

在此处输入图片描述

相关内容