![具有多个标题的表格](https://linux22.com/image/433144/%E5%85%B7%E6%9C%89%E5%A4%9A%E4%B8%AA%E6%A0%87%E9%A2%98%E7%9A%84%E8%A1%A8%E6%A0%BC.png)
我正在尝试获取下表,其中前两行是标题
我正在使用以下代码,但它不起作用
\PassOptionsToPackage{table, dvipsnames}{xcolor}
\documentclass[runningheads]{llncs}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{graphicx}
\begin{document}
\begin{table}[t]
\centering
\scriptsize
\setlength\tabcolsep{0pt}
\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}}
| c | c | c | c | c | c | c | c | }
\hline
\multicolumn{4}{c}{\textbf{Code Representation Approach}}&\textbf{Programming Languages} & \textbf{Code Tackling levels} & \multicolumn{2}{c}{\textbf{Deep Learning Approach}}\\ \hline
Tree Based Approach & Graph Based Approach & Token Based Approach & Others & & & DL Model & Others \\ \hline
AST & CFG & Word Embedding & ByteCode& C& Method Level & ANN & DBN \\ \hline
& DFG& n-grams & ASCCI & C++& Statement level & RNN & NMT \\ \hline
\end{tabular*}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}
执行此代码后,相应的表格不匹配,最后一列被隐藏,因为表格向右移动太多
答案1
您可以通过以下方法将表格压缩到可用的文本宽度内:缩短列标题并允许在较长的表格条目中换行。但请注意,我必须保持\scriptsize
字体大小。
在下面的 MWE 中,我还包括了以下两种替代方法,其中我将表格分成两半,每半 4 列:
最后,我添加了一个示例,说明如何使用嵌套的逐项列表呈现相同的信息:
\documentclass[runningheads]{llncs}
\usepackage{booktabs}
\usepackage{makecell}
\renewcommand{\theadfont}{\bfseries}
\begin{document}
\begin{table}[t]
\caption{Caption}
\label{tab:my_label}
\renewcommand{\theadfont}{\scriptsize\normalfont}
\setlength{\tabcolsep}{4pt}
\centering
\scriptsize
\begin{tabular}{ | c | c | c | c | c | c | c | c | }
\hline
\multicolumn{4}{|c|}{\bfseries\thead[t]{Code Representation\\ Approach}}&\smash{\bfseries\thead[t]{Programming\\ Languages}} & \smash{\bfseries\thead[t]{Code\\ Tackling\\ levels}} & \multicolumn{2}{c|}{\bfseries\thead[t]{Deep Learning\\ Approach}}\\ \cline{1-4} \cline{7-8}
\thead{Tree\\ Based} & \thead{Graph\\ Based} & \thead{Token\\ Based} & Others & & & DL Model & Others \\ \hline
AST & CFG & \makecell{Word\\ Embedding} & ByteCode & C & \makecell{Method\\ Level} & ANN & DBN \\ \hline
& DFG & n-grams & ASCCI & C++ & \makecell{Statement\\ level} & RNN & NMT \\ \hline
& ... & & ... & ... & & ... & ... \\ \hline
& ... & & ... & ... & & ... & \\ \hline
& & & ... & ... & & ... & \\ \hline
& & & & ... & & ... & \\ \hline
& & & & & & ... & \\ \hline
\end{tabular}
\end{table}
\begin{table}[t]
\caption{Caption}
\label{tab:my_label}
\centering
\begin{tabular}{*{4}{c}}
\toprule
\multicolumn{4}{c}{\thead{Code Representation Approach}} \\ \midrule
Tree Based & Graph Based & Token Based & Others \\ \midrule
AST & CFG & Word Embedding & ByteCode \\
& DFG & n-grams & ASCCI \\
& ... & & ... \\
& ... & & ... \\
& & & ... \\ \addlinespace \midrule
\smash{\thead[t]{Programming\\ Languages}} & \smash{\thead[t]{Code Tackling\\ levels}} & \multicolumn{2}{c}{\thead{Deep Learning Approach}} \\ \cmidrule(lr){3-4}
& & DL Model & Others \\ \midrule
C & Method Level & ANN & DBN \\
C++ & Statement level & RNN & NMT \\
... & & ... & ... \\
... & & ... & \\
... & & ... & \\
... & & ... & \\
& & ... & \\ \bottomrule
\end{tabular}
\end{table}
\begin{table}[t]
\caption{Caption}
\label{tab:my_label}
\centering
\begin{tabular}{|*{4}{c|}}
\hline
\multicolumn{4}{|c|}{\thead{Code Representation Approach}} \\ \hline
Tree Based & Graph Based & Token Based & Others \\ \hline
AST & CFG & Word Embedding & ByteCode \\
& DFG & n-grams & ASCCI \\
& ... & & ... \\
& ... & & ... \\
& & & ... \\ \hline
\smash{\thead[t]{Programming\\ Languages}} & \smash{\thead[t]{Code Tackling\\ levels}} & \multicolumn{2}{c|}{\thead{Deep Learning Approach}} \\ \cline{3-4}
& & DL Model & Others \\ \hline
C & Method Level & ANN & DBN \\
C++ & Statement level & RNN & NMT \\
... & & ... & ... \\
... & & ... & \\
... & & ... & \\
... & & ... & \\
& & ... & \\ \hline
\end{tabular}
\end{table}
\noindent
\begin{minipage}[t]{0.5\textwidth}
\begin{itemize}
\item Code Representation Approach
\begin{itemize}
\item Tree Based Approach
\begin{itemize}
\item AST
\end{itemize}
\item Graph Based Approach
\begin{itemize}
\item CFG
\item DFG
\item ...
\item ...
\end{itemize}
\item Token Based Approach
\begin{itemize}
\item Word Embedding
\item n-grams
\end{itemize}
\item Other
\begin{itemize}
\item ByteCode
\item ASCCI
\item ...
\item ...
\item ...
\end{itemize}
\end{itemize}
\item Code Tackling levels
\begin{itemize}
\item Method Level
\item Statement level
\end{itemize}
\end{itemize}
\end{minipage}%
\begin{minipage}[t]{0.5\textwidth}
\begin{itemize}
\item Deep Learning Approach
\begin{itemize}
\item DL Model
\begin{itemize}
\item ANN
\item RNN
\item ...
\item ...
\item ...
\item ...
\end{itemize}
\item Others
\begin{itemize}
\item DBN
\item NMT
\item ...
\end{itemize}
\end{itemize}
\item Programming Languages
\begin{itemize}
\item C
\item C++
\item ...
\item ...
\item ...
\item ...
\end{itemize}
\end{itemize}
\end{minipage}
\end{document}