1

I'm trying to obtain the following table where the first two rows are the headers

enter image description here

I'm using the following code but it doesn't work

\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}

After implementing this code the corresponding table was not matching, and the last column is hidden because the table is shifted too much to the right

enter image description here

Peter
  • 105
  • Please extend your code snippet to complete small document with your table, which begin with \documentclass{...} and end with \end{document} and ln preamble load only necessary packages. Showed images of table doesn't contain numbers, why then you use S columns? – Zarko May 04 '21 at 16:26
  • @Zarko Done dear, The code is already updated, and yes there are no numbers in the table – Peter May 04 '21 at 16:46
  • tabular does not accept a width argument. You probably wanted to use tabular* instead. You currently only declare 5 columns, but seem to use 8 of them. In order to make the code compilable, add the missing column specifiers. – leandriis May 04 '21 at 17:11
  • @leandriis The code is updated but still doesn't work, the problem is "extra alignment tab has been changed to \cr" – Peter May 04 '21 at 17:21
  • Additionaly, the code is not compilable since the siunitx package, which defines the S column type is missing. Since your table does not contain any numbers, there is no need for S type columns (and the siunitx package) at all, so you might want to replace S[table-format=2.3] and S[table-format=2.2] with l or c depending on the expected horizontal alignment. – leandriis May 04 '21 at 17:22
  • The error message you now get is caused by missing column specifiers. You use a total of 8 columns, but l l l] *{2}{c} only declares a total of 5 columns (and contains a ] that does not belong there). If you want 8 horizontally centered colums, you could try *{8}{c} instead of the previously quoted code. – leandriis May 04 '21 at 17:23
  • @leandriis The question is updated now, because your appreciated modification work fine, but the shape of the table is not matching, and the last column is hidden now – Peter May 04 '21 at 17:39
  • 2
    Your table is simple to wide that can be fit to text width. (see https://tex.stackexchange.com/questions/332902/my-table-doesnt-fit-what-are-my-options, your question is now actully duplicate to it). You have two options: (i) enable multi-line cells' contents, (ii) rotate table to landscape orientation. – Zarko May 04 '21 at 17:44
  • 1
    Probably, you could split the table in half and present two halfs that contain 4 columns each or use an ertirely different, probably itemize-based approach? – leandriis May 04 '21 at 18:14

1 Answers1

2

Here is how you could squeeze your table into the available textwidth by shortening column headers and by allowing linebreak in the longer table entries. Note, however, that I had to keep the \scriptsize font size.

enter image description here

In the following MWE, I also included the following two alternative approaches, in which I split up the table into two halves of 4 columns, each:

enter image description hereenter image description here

Lasty, I added an example on how one could present the same information using nested itemize lists:

enter image description here

\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}

leandriis
  • 62,593