4

I am using this code to generate a table in the document. It keeps giving me the error, Missing $ inserted. I am unable to figure out this error.

\begin{table}[htbp]
  \centering
    \begin{tabular}{lrrrrr}
          & \multicolumn{5}{c}{DeCLUTR Base} \\
    Pairs & \multicolumn{1}{l}{\omega_c^1} & \multicolumn{1}{l}{\omega_c^2} & \multicolumn{1}{l}{\Omega_c} & \multicolumn{1}{l}{z_{s,t}} & \multicolumn{1}{l}{$Q$} \\
    A1 - A2 & 0.24  & 0.55  & 0.40  & 0.83  & 2.09 \\
    A1 - A3 & 0.26  & 0.51  & 0.39  & 0.83  & 2.15 \\
    A2 - A3 & 0.39  & 0.33  & 0.36  & 0.84  & 2.31 \\
          &       &       &       &       &  \\
    I1 - I2 & 0.33  & 0.41  & 0.37  & 0.83  & 2.24 \\
    I1 - I3 & 0.25  & 0.49  & 0.37  & 0.82  & 2.22 \\
    I1 - I4 & 0.58  & 0.24  & 0.41  & 0.83  & 2.04 \\
    I2 - I3 & 0.29  & 0.47  & 0.38  & 0.83  & 2.20 \\
    I2 - I4 & 0.65  & 0.23  & 0.44  & 0.83  & 1.90 \\
    I3 - I4 & 0.76  & 0.16  & 0.46  & 0.82  & 1.80 \\
          &       &       &       &       &  \\
    O1 - O2 & 0.25  & 0.48  & 0.37  & 0.83  & 2.25 \\
    O1 - O3 & 0.61  & 0.21  & 0.41  & 0.83  & 2.00 \\
    O1 - O4 & 0.42  & 0.34  & 0.38  & 0.83  & 2.21 \\
    O2 - O3 & 0.81  & 0.15  & 0.48  & 0.82  & 1.72 \\
    O2 - O4 & 0.55  & 0.23  & 0.39  & 0.83  & 2.13 \\
    O3 - O4 & 0.24  & 0.55  & 0.40  & 0.84  & 2.12 \\
          &       &       &       &       &  \\
    M1 - M2 & 0.34  & 0.35  & 0.34  & 0.84  & 2.43 \\
    \end{tabular}
  \label{Tab:warp_coeff_declutr_b}
  \caption{Warp coefficients for DeCLUTR Base}
\end{table}%

Here is the errror. error message

5
  • 4
    \omega_c^1 needs to be in math so $\omega_c^1$ similarly the other math entries Commented Nov 23, 2021 at 23:15
  • Welcome to TeX.SE! Please make your code snippet be compilable, then we do not have to guess what you are doing ... Show the complete first error message in your question please!
    – Mensch
    Commented Nov 23, 2021 at 23:16
  • Apologies. I have added the error msg as well. Commented Nov 23, 2021 at 23:22
  • I had put \omega in $ but that does not work either. Commented Nov 23, 2021 at 23:27
  • 5
    Off-topic: If you want to be able to cross-reference this table correctly via a \ref directive, the \label directive has to be place after, not before, the\caption statement.
    – Mico
    Commented Nov 23, 2021 at 23:31

2 Answers 2

6

As David Carlisle has already pointed out in a comment, math-y expressions such as \omega_c^1, \omega_c^2, \Omega_c, and z_{s,t} must be rendered in math mode -- inline math mode, to be precise.

I would further like to suggest that you align the numbers explicitly on their decimal markers, say by loading the siunitx package and employing its S column type. (For the table at hand, it actually makes no difference whether you use the l, c, r, or S column type.)

Oh, and do take care to place the \caption directive before, not after, the \label directive. This matters greatly if you ever intend to cross-reference this table via LaTeX's \label-\ref mechanism.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{booktabs} % for \toprule, \cmidrule, \midrule, \addlinespace, and \bottomrule macros 
\usepackage{siunitx}  % for the 'S' column type

\begin{document}
\begin{table}[htbp]
  \centering
  \begin{tabular}{@{} l *{5}{S[table-format=1.2]} @{}}
    \toprule
    Pairs & \multicolumn{5}{c@{}}{DeCLUTR Base} \\
    \cmidrule(l){2-6}
    & {$\omega_c^1$} & {$\omega_c^2$} & {$\Omega_c$} & {$z_{s,t}$} & {$Q$} \\
    \midrule
    A1--A2 & 0.24  & 0.55  & 0.40  & 0.83  & 2.09 \\
    A1--A3 & 0.26  & 0.51  & 0.39  & 0.83  & 2.15 \\
    A2--A3 & 0.39  & 0.33  & 0.36  & 0.84  & 2.31 \\ \addlinespace
    I1--I2 & 0.33  & 0.41  & 0.37  & 0.83  & 2.24 \\
    I1--I3 & 0.25  & 0.49  & 0.37  & 0.82  & 2.22 \\
    I1--I4 & 0.58  & 0.24  & 0.41  & 0.83  & 2.04 \\
    I2--I3 & 0.29  & 0.47  & 0.38  & 0.83  & 2.20 \\
    I2--I4 & 0.65  & 0.23  & 0.44  & 0.83  & 1.90 \\
    I3--I4 & 0.76  & 0.16  & 0.46  & 0.82  & 1.80 \\ \addlinespace
    O1--O2 & 0.25  & 0.48  & 0.37  & 0.83  & 2.25 \\
    O1--O3 & 0.61  & 0.21  & 0.41  & 0.83  & 2.00 \\
    O1--O4 & 0.42  & 0.34  & 0.38  & 0.83  & 2.21 \\
    O2--O3 & 0.81  & 0.15  & 0.48  & 0.82  & 1.72 \\
    O2--O4 & 0.55  & 0.23  & 0.39  & 0.83  & 2.13 \\
    O3--O4 & 0.24  & 0.55  & 0.40  & 0.84  & 2.12 \\ \addlinespace
    M1--M2 & 0.34  & 0.35  & 0.34  & 0.84  & 2.43 \\
    \bottomrule
  \end{tabular}
  \caption{Warp coefficients for DeCLUTR Base}
  \label{Tab:warp_coeff_declutr_b}
\end{table}

\end{document}
1
  • I am very new to latex. I just started using it like 2-3 months ago. Dealing with tables was extremely daunting for me, upon doing some digging I found an extension in Excel called excel2latex and I have been using that. The tables have turned out pretty good so far. Here is it's reference link Commented Nov 24, 2021 at 0:48
2

A small variation of nice @mico answer: with use of the tabularray package:

\documentclass{article} 
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}  

\begin{document}
\begin{table}[htbp]
\centering
    \begin{tblr}{colspec={c *{5}{Q[c,si={table-format=1.2},$]}} }
    \toprule
\SetCell[r=2]{c}    Pairs 
        & \SetCell[c=5]{c, mode=text} {{{DeCLUTR Base}}}
                &       &       &       &       \\
    \cmidrule[l]{2-6}
        & {{{\omega_c^1}}}
                & {{{\omega_c^2}}}
                        & {{{\Omega_c}}}
                                & {{{z_{s,t}}}}
                                        & {{{Q}}} \\
    \midrule
A1--A2  & 0.24  & 0.55  & 0.40  & 0.83  & 2.09 \\
A1--A3  & 0.26  & 0.51  & 0.39  & 0.83  & 2.15 \\
A2--A3  & 0.39  & 0.33  & 0.36  & 0.84  & 2.31 \\ 
    \addlinespace
I1--I2  & 0.33  & 0.41  & 0.37  & 0.83  & 2.24 \\
I1--I3  & 0.25  & 0.49  & 0.37  & 0.82  & 2.22 \\
I1--I4  & 0.58  & 0.24  & 0.41  & 0.83  & 2.04 \\
I2--I3  & 0.29  & 0.47  & 0.38  & 0.83  & 2.20 \\
I2--I4  & 0.65  & 0.23  & 0.44  & 0.83  & 1.90 \\
I3--I4  & 0.76  & 0.16  & 0.46  & 0.82  & 1.80 \\ 
    \addlinespace
O1--O2  & 0.25  & 0.48  & 0.37  & 0.83  & 2.25 \\
O1--O3  & 0.61  & 0.21  & 0.41  & 0.83  & 2.00 \\
O1--O4  & 0.42  & 0.34  & 0.38  & 0.83  & 2.21 \\
O2--O3  & 0.81  & 0.15  & 0.48  & 0.82  & 1.72 \\
O2--O4  & 0.55  & 0.23  & 0.39  & 0.83  & 2.13 \\
O3--O4  & 0.24  & 0.55  & 0.40  & 0.84  & 2.12 \\ 
    \addlinespace
M1--M2  & 0.34  & 0.35  & 0.34  & 0.84  & 2.43 \\
    \bottomrule
\end{tblr}
    \caption{Warp coefficients for DeCLUTR Base}
    \label{Tab:warp_coeff_declutr_b}
\end{table}

\end{document}

In comparison to "clasic" table's packages the tabularray has a bit different syntax multcolumn and multirow determine \SetCell, for cells and columns define modes math, dmath and text etc. For details see package documentations.

Result of above MWE is the same as is in @Mico answer:

enter image description here

2
  • Do you like nicematrix more instead of tabulararray or vice versa?☺️☺️☺️☺️☺️☺️
    – Sebastiano
    Commented Nov 24, 2021 at 10:02
  • 1
    @Sebastiano, now I'm phase learn of tabularray. I must confess, that I'm not familiar with recent version of nicematrix`. It has some advantages over all other packages, for example in coloring rows and columns it is the best (to my opinion).
    – Zarko
    Commented Nov 24, 2021 at 11:08

You must log in to answer this question.

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