3

Good morning, i've copied a code for a table that works in https://latexbase.com/ but i can't manage to get it work on texmaker.

The code is this one

\begin{table}[]
\centering
\caption{Experimental results}
\label{my-label}
\begin{tabular}{|llll|}
\cline{1-4}
\multicolumn{1}{|l|}{Scenario} & \multicolumn{1}{l|}{Drowsiness F_1-Score} & \multicolumn{1}{l|}{Non-drowsiness F_1-Score} & \multicolumn{1}{l|}{Accuracy}  \\ \cline{1-4}
BareFace       & 75.95\%             & 76.12\%                 & 76.04\%  \\ \cline{1-4}
Glasses        & 76.78\%             & 70.91\%                 & 74.17\%  \\ \cline{1-4}
Sunglasses     & 68.90\%             & 75.18\%                 & 72.39\%  \\ \cline{1-4}
Night-BareFace & 80.66\%             & 72.11\%                 & 77.16\%  \\ \cline{1-4}
Night-Glasses  & 74.20\%             & 81.66\%                 & 78.56\%  \\ \cline{1-4}
Overall & 75.81\% & 75.65\% & 75.73\% \\ \cline{1-4}
\end{tabular}
\end{table}

And i've got this error

...\multicolumn{1}{l|}{Drowsiness F_1-Score}
& \multicolumn{1}{l|}{Non...
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
! Missing $ inserted.
<inserted text>
$

I've seen different threads about this problem but i'm still not able the get this work.

  • 8
    You can't have _ in text mode, you probably want Drowsiness $F_1$-Score – moewe May 30 '18 at 8:25
  • 2
    Off-topic: As the tabular environment comprises 4 columns, one could replace all instances of \cline{1-4} with \hline. – Mico May 30 '18 at 9:27
6

As @moewe has already pointed out in a comment, you must change all instances of F_1 to either $F_1$ or, possibly, F\_1. (The _ (underscore) character shouldn't occur in ordinary text mode unless it's been "escaped" with a backslash character.)

You may also want to think about making the table more easily readable. For instances, by providing more visual structure in the header, omitting all vertical lines and most horizontal lines, you could make the tabular material both more compact and easier to absorb.

enter image description here

\documentclass{article}
\usepackage{booktabs} % for \toprule, \midrule, \cmidrule, & \bottomrule macros
\begin{document}
\begin{table}
\centering
\caption{Experimental results}
\label{my-label}
\begin{tabular}{@{}lccc@{}}
\toprule
Scenario & \multicolumn{2}{c}{$F_1$-Scores} & Accuracy  \\
\cmidrule(lr){2-3}
& Drowsiness & Non-Drowsiness \\
\midrule
BareFace       & 75.95\% & 76.12\% & 76.04\%  \\ %\cline{1-4}
Glasses        & 76.78\% & 70.91\% & 74.17\%  \\ %\cline{1-4}
Sunglasses     & 68.90\% & 75.18\% & 72.39\%  \\ %\cline{1-4}
Night-BareFace & 80.66\% & 72.11\% & 77.16\%  \\ %\cline{1-4}
Night-Glasses  & 74.20\% & 81.66\% & 78.56\%  \\ \addlinespace %\cline{1-4}
Overall        & 75.81\% & 75.65\% & 75.73\% \\ 
\bottomrule
\end{tabular}
\end{table}
\end{document}
| improve this answer | |
  • Thanks for the interesting comment about the readability of the table. I'm just keeping the same table structure of the other papers related to my current work, but i guess i could use your suggestion for future works. – Lorenzo Mammana May 30 '18 at 16:26
5

The problem is the _ which can only be used in math mode. The table only seems to work on LaTeXbase because there the compilation presses on despite the error message. You can see that something is not quite right by the fact that the text after the F_1 is looking unusual, that is because TeX was forced into math mode by the _ and goes on to treat the rest as if you had written F$_1-Score$, leading to an italic look for Score (it's not text italic it is the math font) and huge spaces around the hyphen that turned into a minus sign. It is a bit unfortunate that LaTeXbase does not show the error more prominently, you have to sift through the .log yourself to see it.

You might want to look into using booktabs to format your tables differently. Together with siunitx to format the numeric input you could end up with (note that text in S columns needs to be escaped with braces or multicolumns to avoid confusing siunitx's number parser)

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}
\centering
\caption{Experimental results}
\label{my-label}
\begin{tabular}{l*{3}{S[table-format=2.2]}}
\toprule
& \multicolumn{2}{c}{$F_1$-Score (\%)} &   \\\cmidrule(lr){2-3}
{Scenario} & {Drowsiness} & {Non-drowsiness} & {Accuracy (\%)} \\
\midrule
BareFace       & 75.95            & 76.12                 & 76.04  \\
Glasses        & 76.78            & 70.91                 & 74.17  \\
Sunglasses     & 68.90            & 75.18                 & 72.39  \\
Night-BareFace & 80.66            & 72.11                 & 77.16  \\
Night-Glasses  & 74.20            & 81.66                 & 78.56  \\
Overall & 75.81 & 75.65 & 75.73 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.