2

I'm desperately trying to format my table: I've tried several different codes but it never gives what I want. I know it's not easy to make beautiful tables but here, I'm stuck.

The rendering I want: on the 1st line: 2x2 merged columns (the 1st with the text "gauche" and the second with the text "droite"), the last 2 without anything on the 2nd line: couple & concentrations ($\unit{\moLar}$)&couple& concentrations $\unit{\moLar}$& pH & Voltage ($\unit{\V}$)

With my code, only the word "gauche" is visible, I don't see the word "droite" text

\documentclass{article}
\usepackage[left=1.5cm, right=1.5cm, top=1.5cm, bottom=1.5cm]{geometry}

\usepackage{tabularray}
\UseTblrLibrary{amsmath,booktabs,counter,diagbox,siunitx,varwidth}
\usepackage{chemgreek}
\usepackage[modules={all}]{chemmacros}%le module orbital a été commenté (lignes 3816 à 3824
\usepackage{textgreek}
\chemsetup{greek=textgreek}

\newcommand{\longeq}[1]{\begin{gathered}#1\end{gathered}}

\begin{document}

\begin{table}[!h]
    \centering
    \begin{tblr}{vspan=even, hspan=minimal,
            colspec={Q[c] Q[c] Q[c] Q[c] Q[c] Q[c]}, rowspec={Q[m] Q[m] Q[m] Q[m] Q[m] Q[m] Q[m]},
            cell{1}{1}={r},
            colsep=5pt,
            row{1-2}={cmd=\textbf}}
            \SetCell[c=2]{c} Gauche & \SetCell[c=2]{c} droite & &\\
            \cmidrule[blue]{1-4}
         couple  & concentrations ($\unit{\moLar}$)&couple& concentrations ($\unit{\moLar}$)& pH & Tension ($\unit{\V}$) \\
         \toprule[blue]
        Cu\pch[2] / Cu & $[\ch{Cu^2+}]$=1e-2 & Zn\pch[2] / Zn & 1e-2 & 0 & 1.1 \\
        
        \bottomrule[blue]
    \end{tblr}
    \caption{Exemples}
    \label{tab:exemple}
\end{table}

\end{document}
1
  • 1
    Off-topic: left=1.5cm, right=1.5cm, top=1.5cm, bottom=1.5cm may be expressed more simply as margin=1.5cm.
    – Mico
    Commented Aug 2 at 22:28

2 Answers 2

4

In addition to having to double the & symbol between \SetCell[c=2]{c} Gauche and \SetCell[c=2]{c} droite, you may want to impose some additional visual structure on the header material, say by (a) creating two visually separate \cmidrule lines and (b) placing the unit information below rather than to the right of the instances of "concentrations".

enter image description here

\documentclass{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage[T1]{fontenc}   % new
\usepackage[french]{babel} % new

\usepackage{tabularray}
\UseTblrLibrary{amsmath,booktabs,counter,
                diagbox,siunitx,varwidth}
\usepackage{chemgreek,textgreek}
\usepackage[modules={all}]{chemmacros}
\chemsetup{greek=textgreek}

%\newcommand{\longeq}[1]{\begin{gathered}#1\end{gathered}}

\begin{document}

\begin{table}[!ht]
\centering
\begin{tblr}{vspan=even, hspan=minimal,
      colspec={Q[c] Q[c] Q[c] Q[c] Q[c] Q[c]}, 
      rowspec={Q[m] Q[m] Q[m] Q[m] Q[m] Q[m] Q[m]},
      %cell{1}{1}={r}, % is this needed?
      colsep=5pt, row{1-2}={cmd=\textbf}}
      
      \SetCell[c=2]{c} gauche && \SetCell[c=2]{c} droite &&
      pH & Tension ($\unit{\V}$)\\
      \cmidrule[blue,r]{1-2} \cmidrule[blue,lr]{3-4}
      couple & concentrations & couple & concentrations \\
      & ($\unit{\moLar}$) && ($\unit{\moLar}$) \\
      \midrule[blue]
      
      Cu\pch[2] / Cu & [\ch{Cu^2+}]=\num{e-2} & 
      Zn\pch[2] / Zn & \num{e-2} & 
      0 & 1.1 \\
      \bottomrule[blue]
\end{tblr}
\caption{Exemples}
\label{tab_exemple}
\end{table}

\end{document}
3

The only thing that is missing is another & before "droite", if I understand correctly:

            \SetCell[c=2]{c} Gauche & & \SetCell[c=2]{c} droite & &\\

So, when a cell occupies multiple columns you must include all & occupied by the cell but leave them blank.

You must log in to answer this question.

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