2

I want to create a table with the tabularray package but I don't understand why the compilation gives me several errors: I have the impression that it is due to word wrapping in the cells. Can anyone help me?

My code:

\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}
\begin{document}

\begin{table}[!h]%
\begin{tblr}{
vspan=even,
colspec = {X[2,c]X[1.5,c]X[1.5,c]X[c]X[c]||X[c]X[c]},
cell{X-Z}{2-6}={font=\small},
row{1}={font=\bfseries},
}
       \toprule[blue]
ions en présence & \ch{H3O\pch{}} & \ch{CH3COOH} & \ch{HO\mch{}\lqd{}} & \ch{A\mch{}\aq{}} & \ch{Na\pch{}\aq{}} & \ch{Cl\mch{}\aq{}}\\
       \midrule[blue]
        $V=0$   & $n_a=C_a V_a$&  $n_b=C_b V$& excès    & 0& $C_a V_a$&\\
      $V<V_{eq1}$& ${C_a V_a -C_b V\\=C_b (V_{eq}-V)}$  &  $\approx 0$& excès       & $C_b V$   &   $C_b V_{eq}$    &\\
            $V=V_{eq1}$& $\approx 0$& ${C_b V -C_a V_a\\=C_b(V-V_{eq})}$    & excès     &   $C_b V$ &   $C_b V_{eq}$    &\\
            $V_{eq1}<V<V_{eq2}$ & $\approx 0$& ${C_b V -C_a V_a\\=C_b(V-V_{eq})}$   & excès     &   $C_b V$ &   $C_b V_{eq}$    &\\
            $V=V_{eq2}$& $\approx 0$& ${C_b V -C_a V_a\\=C_b(V-V_{eq})}$    & excès     &   $C_b V$ &   $C_b V_{eq}$    &\\
            $V>V_{eq2}$& $\approx 0$& ${C_b V -C_a V_a\\=C_b(V-V_{eq})}$    & excès     &   $C_b V$ &   $C_b V_{eq}$    &\\
        \bottomrule[blue]
\end{tblr}
    \caption{Tableau d'avancement pour le dosage d'un acide fort (acide chlorhydrique) par une base forte (soude)}
    \label{tab:tableau_avancement_dosage_acidefort_baseforte}
\end{table}

\end{document}
2
  • Errors comes from \\ in math mode. You could use \begin{aligned}...\end{aligned} instead. By the way you should use mode=math for cell displayed in inline math mode.
    – jlab
    Commented May 23 at 21:00
  • Off-topic: The option list left=1.5cm, right=1.5cm, top=1.5cm, bottom=1.5cm may be expressed more succinctly as margin = 1.5cm.
    – Mico
    Commented May 23 at 21:10

1 Answer 1

4

You cannot have \\ in a cell, unless protected inside something else.

I'd use gathered (but hidden for simplicity of input in a command).

\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}[!htp]
\centering

\begin{tblr}{
  vspan=even,
  colspec = {ccccc||cc},
  cell{X-Z}{2-6}={font=\small},
  row{1}={font=\bfseries},
}
\toprule[blue]
ions en présence &
\ch{H3O\pch{}} &
\ch{CH3COOH} &
\ch{HO\mch{}\lqd{}} &
\ch{A\mch{}\aq{}} &
\ch{Na\pch{}\aq{}} &
\ch{Cl\mch{}\aq{}} \\
\midrule[blue]
$V=0$       & $n_a=C_a V_a$ & $n_b=C_b V$ & excès & 0& $C_a V_a$ \\
$V<V_{eq1}$ & $\longeq{C_a V_a -C_b V\\=C_b (V_{eq}-V)}$ & $\approx 0$ & excès       & $C_b V$   &   $C_b V_{eq}$    &\\
$V=V_{eq1}$ & $\approx 0$ & $\longeq{C_b V -C_a V_a\\=C_b(V-V_{eq})}$    & excès     &   $C_b V$ &   $C_b V_{eq}$    &\\
$V_{eq1}<V<V_{eq2}$ & $\approx 0$& $\longeq{C_b V -C_a V_a\\=C_b(V-V_{eq})}$   & excès     &   $C_b V$ &   $C_b V_{eq}$    &\\
$V=V_{eq2}$& $\approx 0$& $\longeq{C_b V -C_a V_a\\=C_b(V-V_{eq})}$    & excès     &   $C_b V$ &   $C_b V_{eq}$    &\\
$V>V_{eq2}$& $\approx 0$& $\longeq{C_b V -C_a V_a\\=C_b(V-V_{eq})}$    & excès     &   $C_b V$ &   $C_b V_{eq}$    &\\
\bottomrule[blue]
\end{tblr}
    \caption{Tableau d'avancement pour le dosage d'un acide fort (acide chlorhydrique) par une base forte (soude)}
    \label{tab:tableau_avancement_dosage_acidefort_baseforte}
\end{table}

\end{document}

I changed the colspec to avoid complications (your columns become wider than the text width).

enter image description here

You must log in to answer this question.

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