2

I ask for your help. I need to make a complex table (for my noobie level at LaTeX) for my master's thesis.

  • That's the table I would like to do:

enter image description here

I tried some codes, but I always get a fatal error, like that one below:

\begin{table}[H]
\centering
\begin{tabular}{|l|l|}
& \multicolumn{3}{c}{Entreprises}\\
\hline
& \multicolumn{2}{c}{Baidu}   &   \multicolumn{2}{c}{Huawei}   &   \multicolumn{2}{c}{Tencent} \\ \hline
Années   &   \multicolumn{2}{c}{Croissance des revenus bruts (USD | RMB)} & \multicolumn{2}{c}{Croissance des profits nets (USD | RMB)}   &   Croissance des revenus bruts (RMB) & Croissance des profits nets (RMB)   &   Croissance des revenus bruts (RMB) & Croissance des profits nets (RMB) \\ \hline \hline
\renewcommand{\arraystretch}{2}
2007-2008   &   96,03\% & 83,34\%   &   78,17 \% & 66,64\%   &   33,50\% & 132,72\%   &   83,25\% & 79,57\%\\
\end{tabular}
\renewcommand{\arraystretch}{1}
\caption{Croissance des revenus et profits des BATX chinoises.}
\captionsetup{font={footnotesize, bf}}
  \caption*{Source : CNNIC, Rapports statistiques. Réalisé par l'auteur.}
\label{table:2}
\end{table}

Could you please guys tried to help me? I would very appreciate it! :)

Guillaume.

EDIT 1bis.

Thank your for your help! However, I have a problem with your tables because of the complete datas, the table goes out of page.

enter image description here

There is the code I have for the first table:

\documentclass[a4paper,12pt]{book}
\usepackage[left=30mm,top=30mm,right=30mm,bottom=30mm]{geometry}
\usepackage{bookmark, tabularx, varwidth, nicematrix, array, tabularray, ragged2e}

\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{D}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax}C}
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}
\newcolumntype{Z}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{\hspace*{-\tabcolsep}}}
\newcommand{\mcA}[2]{\multicolumn{#1}{c|}{#2}} % just to save some keystrokes
\newcommand{\mcB}[2]{\multicolumn{#1}{c}{#2}} % just to save some keystrokes
\newcolumntype{L}{>{\RaggedRight}X}
    \begin{table}[htbp]
        \centering
        \begin{tabular}{|l|*{8}{c|}}
            \hline
                            & \mcA{8}{\textbf{Croissances des entreprises}}                                                  \\ \cline{2-9}
                            & \mcA{4}{\textbf{Baidu}} & \mcA{2}{\textbf{Huawei}} & \mcA{2}{\textbf{Tencent}} \\ \hline
            \textbf{Années} & \mcA{2}{Revenus bruts (RMB | USD)} & \mcA{2}{Profits (RMB | USD)} & Revenus bruts (RMB) & Profits (RMB)                    & Revenus bruts (RMB) & Profits (RMB)                     \\ \hline
            \textbf{2007-2008}   & 83,34\% & 96,03\%    & 66,64\% & 78,17\%    & 33,50\% & 132,74\%                    & 83,25\% & 79,57\%                     \\ \hline
        \end{tabular}
        \caption{Croissance des revenus et profits des BATX chinoises.
        \centering
        \newline\footnotesize\textbf{Source: Rapports annuels des entreprises concernées. Réalisé par l'auteur.}}
        \label{tab:2}
    \end{table}

\end{document}

Edit 2.

Thank you Zarko! Your table is perfect. I'm sorry about my bad MWE. I'm new at LaTeX and my file is very complex to understand with all packages, also. So I wouldn't to share with you all the mess.

I would have just one question about your table: is it possible to retire italic to the remark{Source}?

enter image description here

3
  • I don't know why but my "Hello everyone!" at the beginning was deleted, so I'm saying that here!
    – Guillaume
    Mar 20 at 23:53
  • Welcome to TeX.SE!!! You should provide a MWE. For example, how can we fix your last issue if we don't know the page and margin dimensions? Mar 21 at 10:24
  • Thanks! I'm sorry to know that. I'm new and I didn't think that would be important. I tried to provide you a "readable and understable" MWE in the Edit 1bis.
    – Guillaume
    Mar 21 at 11:34

3 Answers 3

2

Here is a way to construct that tabular with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{caption}
\usepackage{nicematrix}

\begin{document}

\begin{table}[htbp]
\centering
\caption{Croissance des revenus et profits des BATX chinoises}
\begin{NiceTabular}
  [ 
    cell-space-limits = 3pt , 
    tabularnote = { \footnotesize Source: CNNIC, Rapports statistiques. Réalisé par l'auteur. } ,
    hvlines,
    corners,
  ]
  {>{\bfseries}l*{8}{w{c}{5mm}}}
\RowStyle[nb-rows=2]{\bfseries}
       & \Block{1-8}{Entreprises} \\ 
       & \Block{1-4}{Baidu} &&&& \Block{1-2}{Huawei} && \Block{1-2}{Tencent} \\ 
Années & \Block{1-2}{A} && \Block{1-2}{B} && A & B & A & B \\ 
2007   & 1a & 1b    & 2a & 2b    & 3 & 4 & 5 & 6 \\ 
\end{NiceTabular}
\label{tab:1}
\end{table}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

However, I strongly recommend a design with booktabs in the spirit of booktabs (see Οὖτις's answer).

2
  • Thanks F. Pantigny! It's very helpful. I just have a question, what's the difference between: {table}[htbp] and {tabular} because it seems to have the same result visually.
    – Guillaume
    Mar 22 at 13:19
  • As {tabular}, {NiceTabular} creates a tabular. When you insert such tabular within an environment {table}, it becomes a ``floating'', that is to say an element that LaTeX is allowed to insert several paragraphs (sometimes several pages) after the position it appears in the TeX source (in order to allow empty pages). Of course, in a MWE with only a tabular, the environment {table} has no special effect... Mar 22 at 19:30
3

Welcome to TeX.SE! Let me show you two possible solutions. One of them is closer to your handmade sketch, the other one I consider more professional as it adds some space at horizontal rules and avoids vertical lines, where the latter is one of the two main rules mentioned in the booktabs documentation:

  1. Never, ever use vertical rules.
  2. Never use double rules

Results

\documentclass{article}
\usepackage{booktabs}
\newcommand{\mcA}[2]{\multicolumn{#1}{c|}{#2}} % just to save some keystrokes
\newcommand{\mcB}[2]{\multicolumn{#1}{c}{#2}} % just to save some keystrokes

\begin{document}

\begin{table}[htbp]
    \centering
    \begin{tabular}{|l|*{8}{c|}}
        \hline
                        & \mcA{8}{\textbf{Entreprises}}                                                  \\ \cline{2-9}
                        & \mcA{4}{\textbf{Baidu}} & \mcA{2}{\textbf{Huawei}} & \mcA{2}{\textbf{Tencent}} \\ \hline
        \textbf{Années} & \mcA{2}{A} & \mcA{2}{B} & A & B                    & A & B                     \\ \hline
        \textbf{2007}   & 1a & 1b    & 2a & 2b    & 3 & 4                    & 5 & 6                     \\ \hline
    \end{tabular}
    \caption{Croissance des revenus et profits des BATX chinoises. \footnotesize\textbf{Source: CNNIC, Rapports statistiques. Réalisé par l'auteur.}}
    \label{tab:1}
\end{table}

\begin{table}[htbp]
    \centering
    \begin{tabular}{l*{8}{c}}
        \toprule
                        & \mcB{8}{\textbf{Entreprises}}                                                   \\ \cmidrule(lr){2-9}
                        & \mcB{4}{\textbf{Baidu}}  & \mcB{2}{\textbf{Huawei}} & \mcB{2}{\textbf{Tencent}} \\ \cmidrule(lr){2-5} \cmidrule(lr){6-7} \cmidrule(lr){8-9}
        \textbf{Années} & \mcB{2}{A} & \mcB{2}{B}  & A & B                    & A & B                     \\
        \textbf{2007}   & 1a & 1b    & 2a & 2b     & 3 & 4                    & 5 & 6                     \\ \bottomrule
    \end{tabular}
    \caption{Croissance des revenus et profits des BATX chinoises. \footnotesize\textbf{Source: CNNIC, Rapports statistiques. Réalisé par l'auteur.}}
    \label{tab:2}
\end{table}

\end{document}
4
  • Hello! Wow, thank you for your answer! That's very helpful. I really like all the tables. However, I have a question about the first one: is it possible to delete the first cell at the bottom at the left (above "années")? I think it's more readable and clear. :)
    – Guillaume
    Mar 21 at 9:40
  • Thanks! It is possible: Add \mcA{1}{} to the empty cells, i.e. in the two lines above "Années". Mar 21 at 10:41
  • Thanks! However, I have a problem with my table because of the complete data: it's out of page (see my Edit above).
    – Guillaume
    Mar 21 at 11:28
  • Then you will have to allow linebreaks, I think of parboxes inside cells, p columns or, the shortest way, to go with Zarko's answer Mar 21 at 13:12
2
  • You not provide MWE (Minimal Working Example), so haven't any information about used document class nor about page layout in your document.
  • Table is quite wide, so some text should be broken in several lines (ap to three)
  • It is not clear, how many rows with data has your table nor what are data. So far are assumed, that possible othe rows has similar data
  • By guessing about missed information, your table can be:

enter image description here

\documentclass{article}
\usepackage{geometry}

\usepackage[T1]{fontenc}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\NewTableCommand\mc[1]{\SetCell[c=#1]{c}}

\begin{document}
    \begin{table}[htbp]
    \centering
    \small
\begin{talltblr}[
caption = {Croissance des revenus et profits des BATX chinoises.},
  label = {tab:2},
remark{Source} = {Rapports annuels des entreprises concernées. Réalisé par l'auteur.}
                ]{hline{1,2} = {2-Z}{solid},    hline{3-Z} = {1-Z}{solid},
                  vline{1}   = {3-Z}{solid},    vline{2-Z} = {1-Z}{solid},
                  colspec = { Q[font=\bfseries] 
                             *{8}{X[c,m, font=\linespread{0.84}\selectfont,
                                    si = {table-format=3.2{\,\%}}]} },
                  colsep=2pt,
                  row{1,2} = {font=\bfseries},      % <---
                  row{1-3} = {guard},               % <---
                  cell{4-Z}{2-Z} = {appto={\,\%}}
                 }
    & \mc{8}    Croissances des entreprises 
        &   &   &   &   &   &   &                   \\      
    & \mc{4}  Baidu
        &   &   &   & \mc{2}    Huawei
                        &   & \mc{2}    Tencent         
                                &                   \\                    
 Années
    & \mc{2} {Revenus bruts\\ (RMB | USD)} 
        &   & \mc{2}   {Profits\\ (RMB | USD)} 
                &   & Revenus bruts (RMB) 
                        & Profits (RMB)
                            & Revenus bruts (RMB)
                                & Profits (RMB)     \\
2007-2008
    & 83,34
        & 96,03
            & 66,64
                & 78,17
                    & 33,50
                        & 132,74
                            & 83,25
                                & 79,57           \\
\end{talltblr}
    \end{table}
\end{document}
  • Showed table width is equal to text block width.
  • For table is used talltblr of tabularray packages. It enable to add notes and remarks below table
  • In the case when table has several rows with numeric data you may consider, that number formatting in cels consider align at decimal points. This can be achieved by use si options, which mimic S column type of siunitx package.- Added last two rows are dummed. They just show numbers formatting in those rows.

Edit:
in the case, that you prefer to have table note (remark) in up shape and boldface (at all table), than insert to document preamble the following code lines:

\SetTblrStyle{remark-tag}{font=\bfseries\upshape}
\SetTblrStyle{remark-text}{font=\small\bfseries}

From edited question follows, that you also changed table design. That my suggestion to complain to this change, you need to change table preamble to:

                ]{hline{1,2} = {2-Z}{solid},    hline{3-Z} = {1-Z}{solid},
                  vline{1}   = {3-Z}{solid},    vline{2-Z} = {1-Z}{solid},
                  colspec = { Q[font=\bfseries]
                             *{8}{X[c,m, font=\linespread{0.84}\selectfont,
                                    si = {table-format=3.2}]} },  % <---
                  colsep=4pt,
                  row{1,2}= {font=\bfseries},
                  row{1-3} = {guard},               
                 }

and accordingly change test in the first row in table body. Result is:

enter image description here

4
  • Thank you Zarko for your help because your table is perfect! But I have just 1 question about it (see my Edit 2 above).
    – Guillaume
    Mar 21 at 12:19
  • @Guillaume: a quick and dirty fix would be remark{\upshape Source}. "upshape" means that the text within braces is upright, that is, not italic (it is the opposite of "itshape")
    – marquinho
    Mar 21 at 12:29
  • @Guillaume, so far I use default setting for table remarks (which is to my opinion more appealing as you like to have). This can be changed, but with tabularray syntax. See edited answer.
    – Zarko
    Mar 21 at 12:52
  • Thank you everyone! The marquinho's tip is good. Same for Zarko's advice. I'm again sorry for the bad MWE because my Master's thesis latex document is very complex with a lot of packages, which make me quickly lost.
    – Guillaume
    Mar 22 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .