如何修复 Latex 中的多列标题

如何修复 Latex 中的多列标题

我正在尝试构建一个带有多列标题的表格

但看起来不对

多列中的行看起来遗漏了

我尝试了不同的方法,但这是我得到的最好的结果

在此处输入图片描述

这是我的剧本

\begin{table*}[htbp]
    \caption{AutoML platforms used in the healthcare domain research.}
    \begin{center}
        \begin{tabular}{|c|c|c|c|c|c|c|}
            \hline
            \multirow{2}{*}\textbf{\thead{Dataset\\Format}}&
            \multirow{2}{*}\textbf{\thead{Dataset\\Type}} & \multirow{2}{*}\textbf{\thead{Disease/\\Speciality}} & 
            \multirow{2}{*}\textbf{{Research}} & \multicolumn{3}{|c|}\textbf{\thead{AutoML}}\\ \cline{5-7} &&&&\textbf{\thead{Commercial}}&   \textbf{\thead{Open Source}}
            & \textbf{\thead{Health Related}}\\
            \hline


            \multirow{9}{*}{Unstructured}&Audio&Hearing Aid&\cite{689}&\textcolor{mygreen}{\checkmark}&\textcolor{red}{\ding{53}}&\textcolor{red}{\ding{53}}\\
            

        \end{tabular}
        \label{table_1}
    \end{center}
\end{table*}

我在这里做错了什么?

答案1

  • 您应该将您的代码片段扩展为 MWE,以便我们可以测试它并重现您的问题。
  • 由于您没有提供 MWE,因此不清楚是否使用以下含义\begin{table*}[htbp]:您有两列文档,并且其书写有错误,即应该是\begin{table*},或者您有一列文档,并且您应该写\begin{table}[htbp]
  • 在代码片段中,第一个表中有很多错误:遗漏了预期单元格内容周围的花括号:
    • 最终\multirow{2}{*}\textbf{\thead{Dataset\\Format}}应该是\multirow{2}{*}{\textbf{\thead{Dataset\\Format}}},但更正确的是\multirow{2}{*}{\thead{Dataset\\Format}},在文档序言中\renewcommand\theadfont{\bfseries}
    • 而不是\multicolumn{3}{|c|}\textbf{\thead{AutoML}}最终应该是\multicolumn{3}{|c|}{\textbf{\thead{AutoML}}},但更正确的是\multicolumn{3}{c|}{\thead{AutoML}}

考虑两列文档的 MWE:

\documentclass[a4paper, twocolumn]{article}
\usepackage{pifont} 
\usepackage[table]{xcolor}
\usepackage{ multirow, makecell,xcolor}
\renewcommand\theadfont{\bfseries} % <---
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table*}[htbp]
    \caption{AutoML platforms used in the healthcare domain research.}
    \centering
\begin{tabular}{|c|c| c|c| c|c| c|}
    \hline
\multirow{2}{*}{\textbf{\thead{Dataset\\Format}}}  
    & \multirow{2}{*}{\textbf{\thead{Dataset\\Type}}} 
        & \multirow{2}{*}{\textbf{\thead{Disease/\\Speciality}}}  
            & \multirow{2}{*}{\textbf{Research}} 
                & \multicolumn{3}{c|}{\textbf{\thead{AutoML}}}    \\  % <---
    \cline{5-7} 
    &&&&  \textbf{\thead{Commercial}}
       & \textbf{\thead{Open Source}}
       & \textbf{\thead{Health Related}}\\
        \hline
\multirow{1}{*}{Unstructured}
    & Audio
    & Hearing Aid
    & \cite{689}
    & \textcolor{teal}{\ding{51}}
    & \textcolor{red}{\ding{53}}
    & \textcolor{red}{\ding{53}}\\
\end{tabular}
        \label{table_1}
    \end{table*}
\end{table}

在此处输入图片描述

(红线表示页面布局)

如您所见,您的表格比文本宽度宽,因此您应该考虑采取一些措施使表格变窄或使文本宽度大于包的宽度geometry

使表格变窄的一种可能性是减少\tabcolsep、删除垂直线以及删除表格开始和结束处的单元格填充@{}

\documentclass[a4paper, twocolumn]{article}
\usepackage{pifont} 
\usepackage[table]{xcolor}
\usepackage{multirow, makecell}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{}
\NewExpandableDocumentCommand\mrc{O{1}m}
    {\multirow{#1}{*}{#2}}

\begin{document}
    \begin{table*}
\setlength\tabcolsep{4pt}
\setcellgapes{3pt}
\makegapedcells
    \caption{AutoML platforms used in the healthcare domain research.}
    \label{table_1}
    \centering
\begin{tabular}{@{} cc cc cc c  @{}}
    \hline
\mrc[2.4]{\thead{\shortstack{Dataset\\Format}}}
    & \mrc[2.4]{\thead{\shortstack{Dataset\\Type}}}
        & \mrc[2.4]{\thead{\shortstack{Disease/\\Speciality}}}
            & \mrc[2.4]{\thead{Research}}
                & \multicolumn{3}{c}{\thead{AutoML}}    \\  \cline{5-7}
    &
        &
            &
                & \thead{Commercial}
                    & \thead{Open Source}
                        & \thead{Health Related}        \\
        \hline
\multirow{1}{*}{Unstructured}
    & Audio
        & Hearing Aid
            & \cite{689}
                & \textcolor{teal}{\ding{51}}
                    & \textcolor{red}{\ding{53}}
                        & \textcolor{red}{\ding{53}}    \\
\end{tabular}
    \end{table*}
\end{document}

在此处输入图片描述

答案2

在此处输入图片描述

\documentclass[10pt,a4paper]{article}

\usepackage{ multirow, makecell,xcolor}
\renewcommand\theadfont{\bfseries}


\begin{document}
    \begin{table*}[!h]
        \caption{AutoML platforms used in the healthcare domain research.}
\centering
            \noindent\makebox[\textwidth]{%
                \begin{tabular}{ccccccc}
                \hline
                \thead{\shortstack{Dataset\\Format}}
                    &\thead{\shortstack{Dataset\\Type}} 
                        & \thead{\shortstack{Disease/\\Speciality}} 
                            &\thead{Research} 
                                & \multicolumn{3}{c}{\thead{AutoML}}\\ \cline{5-7}
                    &
                        &
                            &
                                &\thead{Commercial}
                                    &\thead{Open Source}
                                        &\thead{Health Related}\\
                \hline
            \end{tabular}
        }
            \label{table_1}
    \end{table*}
\end{document}

答案3

具有(且{NiceTabular}处于nicematrix横向模式)。

\documentclass[landscape]{article}

\usepackage{nicematrix}
\usepackage{pifont}
\usepackage{caption}
\usepackage{xcolor}

\begin{document}

\begin{table*}[htbp]
\caption{AutoML platforms used in the healthcare domain research.}
\centering
\NiceMatrixOptions{cell-space-limits=3pt}
\begin{NiceTabular}{ccccccc}[hvlines]
\Block{2-1}<\bfseries>{Dataset\\Format}
    & \Block{2-1}<\bfseries>{Dataset\\Type}
        & \Block{2-1}<\bfseries>{Disease/\\Speciality}  
            & \Block{2-1}<\bfseries>{Research}
                & \Block{1-3}<\bfseries>{AutoML}    \\ 
    &&&& \bfseries Commercial
       & \bfseries Open Source
       & \bfseries Health Related\\
Unstructured
    & Audio
    & Hearing Aid
    & \cite{689}
    & \textcolor{teal}{\ding{51}}
    & \textcolor{red}{\ding{53}}
    & \textcolor{red}{\ding{53}}\\
\end{NiceTabular}
\label{table_1}
\end{table*}

\end{document}

您需要多次编译(因为nicematrix使用 PGF/Tikz 节点)。

上述代码的输出

相关内容