我有下表和以下代码:
\documentclass{cta-author}
\usepackage{mystyle}
\usepackage{caption}
\usepackage{myrq}
\usepackage[toc,page]{appendix}
\usepackage{longtable}
\usepackage{hyperref}
\usepackage{rotating}
\usepackage{lscape}
\usepackage{xurl}
\usepackage{csquotes}
\usepackage{xcolor}
% Acronyms
\input{acronyms}
% frames
\usepackage{framed}
\definecolor{shadecolor}{rgb}{0.95,0.95,1}
\newenvironment{summary}[1]%
{%
\begin{shaded}%
\iffalse\end{shaded}\fi
\textbf{#1 Summary:}%
}%
{\end{shaded}}
\begin{document}
\begin{table*}[t]
\caption{Overview of \ac{slr} Coding Attributes}
\label{tab:Coding_attr}
\renewcommand{\theadfont}{\scriptsize\normalfont}
\setlength{\tabcolsep}{4pt}
\centering
\scriptsize
\begin{tabular}{ c c c c c c c c }
\multicolumn{4}{c}{\bfseries\thead[t]{\textbf{Code Representation}\\ \textbf{Approach}}}&\smash{\bfseries\thead[t]{\textbf{Programming}\\ \textbf{Language}}} & \smash{\bfseries\thead[t]{\textbf{Code-Level}\\ \textbf{Granularity}}} & \multicolumn{2}{c}{\bfseries\thead[t]{\textbf{Deep Learning}\\ \textbf{Architecture}}}\\
\thead{\emph{Tree}\\ \emph{Based}} & \thead{\emph{Graph}\\ \emph{Based}} & \thead{\emph{Token}\\\emph{ Based}} & \emph{Others} & & & \emph{DL Model} & \emph{Others} \\ \hline
\rule{0pt}{6ex} AST & CFG & \makecell{Word\\ Embedding} & ByteCode & C & \makecell{Method Level} & ANN & DBN \\
& DFG & n-grams & ASCII & C++ & \makecell{Statement level} & RNN & NMT \\
& PDG & & Code Gadget & C\# & & LSTM & RL \\
& CallFG & & Latent Semantic Indexing & Java & & CNN & \\
& & & Binary Visualization & Java Script & & GNN & \\
& & & & Python & & Auto-Encoder & \\
& & & & & & Attention Mechanism & \\
\end{tabular}
\end{table*}
\end{document}
输出图如下
前两行分别是标题和副标题。
现在我想通过在“软件任务”末尾添加一个新列来更改表格,其中包含两个子标题,软件任务和其他任务(例如“深度学习架构”。我尝试修改代码如下:
\begin{table*}[t]
\caption{Overview of \ac{slr} Coding Attributes.}
\label{tab:Coding_attr}
\renewcommand{\theadfont}{\scriptsize\normalfont}
\setlength{\tabcolsep}{4pt}
\centering
\scriptsize
\begin{tabular}{ c c c c c c c c c c}
\multicolumn{5}{c}{\bfseries\thead[t]{\textbf{Code Representation}\\ \textbf{Approach}}}&\smash{\bfseries\thead[t]{\textbf{Programming}\\ \textbf{Language}}} & \smash{\bfseries\thead[t]{\textbf{Code-Level}\\ \textbf{Granularity}}} & \multicolumn{2}{c}{\bfseries\thead[t]{\textbf{Deep Learning}\\ \textbf{Architecture}}}& \multicolumn{2}{c}{\bfseries\thead[t]{\textbf{Software}\\ \textbf{Task}}}\\
\thead{\emph{Tree}\\ \emph{Based}} & \thead{\emph{Graph}\\ \emph{Based}} & \thead{\emph{Token}\\\emph{ Based}} & \emph{Others} & & & \emph{DL Model} & \emph{Others} & \emph{Task} & \emph{Others} \\ \hline
\rule{0pt}{6ex} AST & CFG & \makecell{Word\\ Embedding} & ByteCode & C & \makecell{Method Level} & ANN & DBN & Code Clone Detection & Code Suggestion \\
& DFG & n-grams & ASCII & C++ & \makecell{Statement level} & RNN & NMT \\
& PDG & & Code Gadget & C\# & & LSTM & RL \\
& CallFG & & Latent Semantic Indexing & Java & & CNN & \\
& & & Binary Visualization & Java Script & & GNN & \\
& & & & Python & & Auto-Encoder & \\
& & & & & & Attention Mechanism & \\
\end{tabular}
\end{table*}
输出如下:
如您所见,软件任务主标题出现在子标题树形列上方的新行中,而不是位于最后一列主列中。
答案1
你写了,
现在我想通过在“软件任务”末尾添加一个新列来更改表格,其中包含两个子标题“软件任务”和“其他”
由于您希望添加二子标题(以及一个横跨两个新子标题的新标题单元格),则必须将列数增加二, 不是一个。
顺便问一下,您为什么改成\multicolumn{4}{c}{...}
了\multicolumn{5}{c}{...}
?
我建议你彻底清理表格的外观,不要使用粗体显示和斜体在标题和副标题单元格中。接下来,我还将使用该booktabs
包(尤其是其\cmidrule
宏)在标题和副标题上强加一些可识别的视觉结构。最后,请考虑在可能的情况下使用缩写来减少一些列宽。
\documentclass{cta-author}
\usepackage{makecell,booktabs}
\providecommand\ac[1]{#1} % ??
\begin{document}
\begin{table*} % [t] % <-- [t] has no effect
\caption{Overview of \ac{slr} Coding Attributes}
\label{tab:Coding_attr}
\renewcommand{\theadfont}{\scriptsize}
\setlength{\tabcolsep}{4pt}
\centering
\scriptsize
\smallskip
\begin{tabular}{@{} *{10}{c} @{}} % before: \begin{tabular}{ *{8}{c} }
\toprule
\multicolumn{4}{@{}c}{Code representation approach}
& \thead[t]{Programming\\ language} & \thead[t]{Code-level\\ granularity}
& \multicolumn{2}{c}{\thead[t]{Deep learning\\ architecture}}
& \multicolumn{2}{c@{}}{\thead[t]{Software\\ task}}
\\
\cmidrule(r){1-4} \cmidrule(lr){7-8} \cmidrule(l){9-10}
\thead[t]{Tree\\based} & \thead[t]{Graph\\based} & \thead[t]{Token\\based} & Others
& &
& DL model & Others
& Task & Others \\
\midrule
AST & CFG & \makecell[t]{Word\\embedding} & ByteCode & C & \makecell[t]{Method\\level}
& ANN & DBN & \dots & \dots \\
& DFG & n-grams & ASCII & C++ & \makecell[t]{Statement\\level}
& RNN & NMT & \dots & \dots \\
& PDG & & Code Gadget & C\# & & LSTM & RL \\
& CallFG & & Lat.\ Sem.\ Indexing & Java & & CNN & \\
& & & Binary Vis. & Java Script & & GNN & \\
& & & & Python & & Auto-Encoder & \\
& & & & & & Attention Mech. & \\
\end{tabular}
\end{table*}
\end{document}
答案2
使用tabularray
包可以大大简化您的表代码。除此之外,在下面的 MWE 中还进行了以下更改:
- 列是
X
类型,因此表格宽度是\textwidth
,并且不再需要手动分隔文本(第一个表格行除外) - 使用的是来自
booktabs
包的规则 - 表格中使用的字体大小增加到
\small
\documentclass[twocolumn]{article}%{cta-author}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{table*}
\caption{Overview of \emph{slr} Coding Attributes}
\label{tab:Coding_attr}
\small
\begin{tblr}{colsep=3pt,
colspec = {@{} *{2}{X[0.8,c,m]}
*{2}{X[c,m]}
*{2}{X[1.2,c,m]}
*{2}{X[0.8,c,m]}
*{2}{X[1.2,c,m]}
@{}},
row{1,2} = {font=\bfseries}
}
\toprule
\SetCell[c=4]{c} {Code\\ representation approach}
& & & & \SetCell[r=2]{c,m} Program. language
& \SetCell[r=2]{c,m} Code-level granularity
& \SetCell[c=2]{c} {Deep learning\\ architecture}
& & \SetCell[c=2]{c} {Software\\ task}
& \\
\cmidrule[r]{1-4} \cmidrule{7-8} \cmidrule[l]{9-10}
Tree based
& Graph based
& Token based
& Others
& & & DL model
& Others
& Task
& Others \\
\midrule
AST
& CFG
& Word embedding
& ByteCode
& C & Method level
& ANN
& DBN
& Code Clone Detection
& Code Suggestion \\
& DFG
& n-grams
& ASCII
& C++
& Statement level
& RNN
& NMT
& \dots
& \dots \\
& PDG
& & Code Gadget
& C\#
& & LSTM
& RL
& \dots
& \dots \\
& CallFG
& & Lat. Sem. Indexing
& Java
& & CNN
& & \dots
& \dots \\
& & & & & & Attention Mech.
& & \dots
& \dots \\
\bottomrule
\end{tblr}
\end{table*}
\end{document}