表列数据组织不正确-latex

表列数据组织不正确-latex

我是 Latex 新手。我创建了一个表格。但是,它不是我所期望的。

在此处输入图片描述

我希望它居中且分隔良好,如下所示(此表格是在 MS Word 中构建的),

在此处输入图片描述

\begin{table}[htb] % <--- "here", "top", "bottom"
\centering
    \setcellgapes{2pt}
    \makegapedcells
\caption{Sample result of N. UzZaman and Mumit’s Bangla soundex table}
    \begin{tabularx}{\linewidth}{@{} lcc @{}}
    \toprule
    \toprule
\makecell[lb]{Input}
            & \makecell[b]{Encoded}
                                & \makecell[b]{Suggestion}\\
    \midrule
\textbengali{খুমাড়}  & kumar        & \textbengali{কুমার}\\
\textbengali{পাসান}  & pasan        & \textbengali{পাষাণ}\\
    \bottomrule
    \bottomrule
    \end{tabularx}
  \label{table3}
\end{table}

由于文档太大,我无法在这里发布整个代码。我添加了我使用的以下软件包。

\usepackage{xcolor}
\usepackage{listings}
\usepackage{booktabs}
\usepackage{array}
\usepackage{float}
\usepackage{graphicx}  
\usepackage[utf8]{inputenc}
\usepackage{polyglossia}
\usepackage{fontspec}
\setmainlanguage{english}
\setotherlanguage{bengali}
\newfontfamily\bengalifont[Script=Bengali]{Vrinda}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{makecell, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{amsmath}

答案1

测试以下内容:

\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs, makecell, tabularx}
    \setcellgapes{2pt}
    \makegapedcells
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}

\usepackage[skip=1ex]{caption}

\begin{document}
\begin{table}[htb]
\caption{Sample result of N. UzZaman and Mumit’s Bangla soundex table}
    \begin{tabularx}{\linewidth}{LCC}
    \toprule
\makecell[lb]{Input}
        & \makecell[b]{Encoded}
                    & \makecell[b]{Suggestion}\\
    \midrule
some bengali text %\textbengali{খুমাড়}
    & kumar         & some bengali text \\  %\textbengali{কুমার}\\
some bengali text %\textbengali{পাসান}
    & pasan         & some bengali text \\  %\textbengali{পাষাণ}\\
    \bottomrule
    \end{tabularx}
  \label{table3}
\end{table}

\begin{table}[htb]
\centering
\caption{Sample result of N. UzZaman and Mumit’s Bangla soundex table}
    \begin{tabular}{lcc}
    \toprule
\makecell[lb]{Input}
        & \makecell[b]{Encoded}
                    & \makecell[b]{Suggestion}\\
    \midrule
some bengali text %\textbengali{খুমাড়}
    & kumar         & some bengali text \\  %\textbengali{কুমার}\\
some bengali text %\textbengali{পাসান}
    & pasan         & some bengali text \\  %\textbengali{পাষাণ}\\
    \bottomrule
    \end{tabular}
  \label{table3}
\end{table}

\end{document}

它给:

在此处输入图片描述

正如您的问题下方的评论中所提到的,tabularx应该至少有一个类型为X或派生自的列,X如上面的代码中所使用(LC)。

离题:看看以下链接是否对您有帮助:

相关内容