5

I am co-writing a paper in linguistics on Overleaf. When I download the tex-file and try to compile it locally on the computer (Editor Winedt), I get an error mistake that is not present in Overleaf, where everything compiles correctly. It is clearly related to an equation environment inside a figure. I do not manage to find a solution.

Here's a relatively minimal working example. The error message is :

! Missing $ inserted.
<inserted text> 

\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[normalem]{ulem} 
\usepackage{booktabs}
\usepackage{amsmath}

\begin{document}

Some text

\begin{figure} \centering
\caption{A feature bundle on C$^0$}
\vspace{0,5cm}
\label{lex}

\begin{equation*}

\left  ( \begin{array}{lll} \textrm{C$^0$[Fin], [EPP]} & [Focus] & [Topic] \\ & [Contrastive] & [Contrastive] \\ & [Mirative] & [Shifting] \\ & [\ldots] & [\ldots]
\end{array}
 \right )

\end{equation*}
 \vspace{0,5cm}
\end{figure}

\end{document} 
3
  • 4
    You must not have empty lines in the equation Mar 31 at 9:03
  • 3
    Keep in mind that Overleaf has a very, very bad handling of errors, as it tries to force its way through errors even though LaTeX isn't designed for it. It means that files tested only on Overlead aren't reliable.
    – Miyase
    Mar 31 at 9:16
  • 1
    Just out of idle curiosity: Why do you write C$^0$ instead of $C^0$?
    – Mico
    Mar 31 at 11:29

2 Answers 2

7

As @samcarter_is_at_topanswers.xyz has already noted in a comment, blank lines aren't allowed in a display math environment. The fact that your test document supposedly compiles successfully on Overleaf is almost certainly due to Overleaf doing an excellent [!] job hiding LaTeX warning and other messages from users.

I'd go further than just eliminate the blank lines, though. Specifically, I'd (a) use inline math mode instead of display math mode and (b) employ a tabular environment instead of an array environment because the words in the 4x3 array should be typeset in text mode, not math mode.

A separate issue: Is it essential that the tabular/array material be surrounded by round parentheses? Would simple vertical lines on either side of the tabular/array material do just a well? If so, you could get rid of the math-y setup entirely and replace \begin{tabular}{lll} with \begin{tabular}{|lll|}, as is demonstrated in the lower half of the following screenshot. (For that matter, does the table really need to be surrounded by either parentheses or vertical lines?)

enter image description here

\documentclass{article}
\usepackage[english]{babel}
%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc}
\usepackage[normalem]{ulem} 
\usepackage{booktabs}
\usepackage{amsmath}

\begin{document}
Some text\dots

\begin{figure}[h]
\centering

\caption{A feature bundle on $C^0$}\label{lex}
\vspace*{5mm}

%% a 'tabular' env. flanked by tall math-mode parentheses
$\left( 
\begin{tabular}{lll} 
$C^0$[Fin], [EPP] & [Focus] & [Topic] \\ 
   & [Contrastive] & [Contrastive] \\ 
   & [Mirative]    & [Shifting] \\ 
   & [\ldots]      & [\ldots] \\
\end{tabular}
\right)$

\vspace*{0.5cm}

%% just a 'tabular' env. flanked by vertical bars
\begin{tabular}{|lll|} 
$C^0$[Fin], [EPP] & [Focus] & [Topic] \\ 
   & [Contrastive] & [Contrastive] \\ 
   & [Mirative]    & [Shifting] \\ 
   & [\ldots]      & [\ldots] \\
\end{tabular}

\end{figure}

Some more text\dots
\end{document} 
2
  • thanks, this solved the problem. The round parentheses are not strictly speaking essential, but they are conventional in the context I use them, so I went with your first suggestion with the math-mode parentheses. As for why I write C$^0$ instead of $C^0$... I don't know, does it matter? The letter C is not part of the math mode itself, so why include it?
    – Espen
    Apr 3 at 7:36
  • @Espen -- As to why I asked why you write C$^0$ instead of $C^0$ -- I guess it all depends on whether C is a (mathematical) variable of some kind or not. According to your comment, it's not.
    – Mico
    Apr 3 at 8:06
4

Define your own environment.

Also, if you want the caption above the material, tell LaTeX so, rather than adding random spaces.

\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[normalem]{ulem} 
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{caption}

\captionsetup[figure]{position=top}

\newenvironment{ptabular}
 {$\left(\hspace{-\tabcolsep}\tabular}{\endtabular\hspace{-\tabcolsep}\right)$}

\begin{document}

Some text

\begin{figure}[htp]
\centering

\caption{A feature bundle on C$^0$}
\label{lex}

\begin{ptabular}{lll}
C$^0$[Fin], [EPP] & [Focus]       & [Topic] \\
\addlinespace
                  & [Contrastive] & [Contrastive] \\
\addlinespace
                  & [Mirative]    & [Shifting] \\
\addlinespace
                  & [\ldots]      & [\ldots]
\end{ptabular}
\end{figure}

Some other text

\end{document} 

enter image description here

You must log in to answer this question.

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