Why is LaTeX missing $when I have no mathematical equation and how do I center the table? I am new to LaTeX. However, I don't know why this code is not working: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage[usenames, dvipsnames]{color} \usepackage{multirow} \title{r} \author{omar113057 } \date{September 2018} \begin{document} \maketitle \section{Introduction} \definecolor{black}{rgb}{0.0, 0.0, 0.0} \begin{table}[!hbtp] \begin{center} \begin{normalsize} \color{black} \begin{tabular}{llcrr} \hline &Female&Male&\\ &(N=287)&(N=570)&\multirow{-2}{*}{p}\\ \hline age & 68.7 \pm 10.7 & 60.6 \pm 11.2 & < 0.001\\ \hline cardiogenicShock &&& 0.136\\ \hspace{0.5cm} No &275 (95.8\%)&530 (93.0\%)&\\ \hspace{0.5cm} Yes &12 ( 4.2\%)&40 ( 7.0\%)&\\ \hline entry &&&0.035\\ \hspace{0.5cm} Femoral &119 (41.5\%)&193 (33.9\%)&\\ \hspace{0.5cm} Radial &168 (58.5\%)&377 (66.1\%)&\\ \hline Dx &&&0.012\\ \hspace{0.5cm} NSTEMI &50 (17.4\%)&103 (18.1\%)&\\ \hspace{0.5cm} STEMI &84 (29.3\%)&220 (38.6\%)&\\ \hspace{0.5cm} Unstable Angina&153 (53.3\%)&247 (43.3\%)&\\ \hline EF &56.3 \pm 10.1&55.6 \pm 9.4&0.387\\ \hline height &153.8 \pm 6.2&167.9 \pm 6.1&< 0.001\\ \hline weight &57.2 \pm 9.3&68.7 \pm 10.3&< 0.001\\ \hline BMI &24.2 \pm 3.6&24.3 \pm 3.2&0.611\\ \hline obesity &&&0.580\\ \hline \hspace{0.5cm} No &194 (67.6\%)&373 (65.4\%)&\\ \hline \hspace{0.5cm} Yes &93 (32.4\%)&197 (34.6\%)&\\ TC &188.9 \pm 51.1&183.3 \pm 45.9&0.124\\ \hline LDLC &117.8 \pm 41.2&116.0 \pm 41.1&0.561\\ \hline HDLC &39.0 \pm 11.5&37.8 \pm 10.9&0.145\\ \hline TG &119.9 \pm 76.2&127.9 \pm 97.3&0.195\\ \hline DM &&&0.077\\ \hspace{0.5cm} No &173 (60.3\%)&380 (66.7\%)&\\ \hspace{0.5cm} Yes &114 (39.7\%)&190 (33.3\%)&\\ HBP &&&< 0.001\\ \hspace{0.5cm} No &83 (28.9\%)&273 (47.9\%)&\\ \hspace{0.5cm} Yes &204 (71.1\%)&297 (52.1\%)&\\ \hline smoking &&&< 0.001\\ \hspace{0.5cm} Ex-smoker &49 (17.1\%)&155 (27.2\%)&\\ \hspace{0.5cm} Never &209 (72.8\%)&123 (21.6\%)&\\ \hspace{0.5cm} Smoker &29 (10.1\%)&292 (51.2\%)&\\ \hline \end{tabular} \end{normalsize} \end{center} \end{table} \color{black} \end{document}  This code is generated from an R package called ztable. I fixed a lot of errors in this code however, and this$ sign that the log keeps throwing is very strange to me as I don't see any pattern here.

Also I want to make a pretty centered and well spaced table. How can I achieve that?

• Hi, welcome. As a first step, note that \pm works only in math mode. – Torbjørn T. Sep 30 '18 at 9:46
• I actually have replaced +- symbol that was generated by ztable package as it was not rendered at any point. @TorbjørnT. – Omar113 Sep 30 '18 at 10:17


One solution is to use the command \ensuremath. This command will put the argument into maths mode if it was not already in maths mode. It will also correctly put it back to normal text mode. If you are in math mode already, TeX leaves the argument in math mode.

You could use a macro definition to put something into maths mode if you were not already.

For your use (\pm in either math or text mode) you could define a macro \ppmm say:

  \newcommand{\ppmm}{\ensuremath{\pm}}


You could then use \ppmm in text mode or $\ppmm$ math mode without syntax errors.

Macros with \ensuremath are useful in lots of situations like this. For instance to describe a 12-bit ADC in TeX, I use $\mathcal{ADC}_{12}$ but sometimes I might want to use this when already in maths mode. By making the macro employ an \ensuremath wrapper, it can be safely used in both modes:

  \newcommand{\adctw}{\ensuremath{\mathcal{ADC}_{12}}


Then in the document you can call the macro whether in math mode, ${\adctw}$, or text mode, \adctw, and it works without syntax errors.

• good point. edited my post – Robin Oct 1 '18 at 10:50
• I've taken the liberty of adding backticks around TeX and LaTeX expressions, to them stand out as computer code. Feel free to revert. – Mico Oct 1 '18 at 11:14
• did not know this site did that! makes it look better thanks. – Robin Oct 1 '18 at 11:16
• A related approach would be to \let\oldpm=\pm and then \renewcommand{\pm}{\ensuremath{\oldpm}}. Then the table would work as it stands. And if you did this within the tabular, scoping would prevent \pm from being redefined elsewhere. – Teepeemm Oct 1 '18 at 14:18