Graphics, Figures & Tablesmissing $ in table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Kaiser258
Posts: 2
Joined: Fri Apr 16, 2021 1:49 pm

missing $ in table

Post by Kaiser258 »

Hi guys,

I am having a problem when creating a table.
It keeps telling me that there is a missing $ but i don't see where it is missing

here is the line of code:

Code: Select all

\begin{table} 
        \centering
        \begin{tabular}{|c|c|c|c|}
            \hline
            Sex & n & X & $\hat{p}$= X/n\\
            \hline
            \hline
            Women & 537 & 328 & 0.6108 \\
            Men & 532 & 234 & 0.4398 \\
            \hline
            Total & 1069 & 562 & 0.5257 \\
            \hline
        \end{tabular}
        \caption{Instagram data}
        \label{tab:firstTable}
    \end{table}
    

and here's what it's telling me:
Screenshot 2021-04-16 155540.png
Screenshot 2021-04-16 155540.png (11.15 KiB) Viewed 2029 times
Please help and thank you in advance

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

missing $ in table

Post by Ijon Tichy »

No error here. You can check yourself with the Run LaTeX here button.

So I would recommend to make a real Infominimal working example to make the error reproducible.

However, I would recommend to always set the whole formula in math mode, e.g., $\hat{p} = X/n$ instead of $\hat{p}$= X/n. This makes a big difference, because in math mode letter characters are set italic as usual for variables. So all variables always should be in math mode. It makes a second difference, because spacing in math mode is automatically adapted to the kind of symbols, e.g., operators, letters, commas etc.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Kaiser258
Posts: 2
Joined: Fri Apr 16, 2021 1:49 pm

missing $ in table

Post by Kaiser258 »

I tried to run it on the site itself and its working perfectly but i don't know why it is telling me that there is a $ sign missing when I am using WinEdt. Anyway thanks for the advice on the math mode formulae
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

missing $ in table

Post by Ijon Tichy »

It works perfectly here, because in the shown code, there is no error, if the code snippet is surrounded by a standard document. Nevertheless, there could be an error in your concrete code. That's why I've told you, that we need a Infominimal working example instead of the code snippet.

One more note: For numeric columns, package siunitx and its s-columns could be useful.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply