我遇到了一个奇怪的问题,\cup 后面的文本会变成斜体(可能是数学模式显示?)。每当我使用\textsuperscript{\ell}
上标\ell
符号时 - 它会将后面的任何内容(即使在花括号之外)也作为上标。
\ell
为了解决这个问题,我在数学模式中将所有特殊符号(如和)都包裹起来\cup
。它解决了问题,但是...
现在我的表格对我进行了报复,在下面的代码块中,表格块中的前 8 行中有 7 行产生了错误"Missing $ inserted."
为什么?……还有什么办法吗?
\begin{center}
\begin{table}[h!]
\begin{tabular}{ c c c }
\textcolor{forestgreen}{flow}([int x;]\textsuperscript{$\ell$}) & = & \emptyset \\
\textcolor{forestgreen}{flow}([int[n] A;]\textsuperscript{$\ell$}) & = & \emptyset \\
\textcolor{forestgreen}{flow}([\{int fst; int snd\} R; ]\textsuperscript{$\ell$}) & = & \emptyset \\
\textcolor{forestgreen}{flow}(D\textsubscript{1} D\textsubscript{2}) & = & \textcolor{forestgreen}{flow}(D\textsubscript{1}) $\cup$ \textcolor{forestgreen}{flow}(D\textsubscript{2}) $\cup$ \{($\ell$, \textcolor{forestgreen}{init}(D\textsubscript{2})) | $\ell \in$ \textcolor{forestgreen}{final}(D\textsubscript{1})\} \\
\textcolor{forestgreen}{flow}([$\ell$ := a;]\textsuperscript{$\ell$}) & = & \emptyset \\
\textcolor{forestgreen}{flow}([R := (a\textsubscript{1}, a\textsubscript{2}); ]\textsuperscript{$\ell$}) & = & \emptyset \\
\textcolor{forestgreen}{flow}([read k;]\textsuperscript{$\ell$}) & = & \emptyset \\
\textcolor{forestgreen}{flow}([write $\ell$;]\textsuperscript{$\ell$}) & = & \emptyset \\
\textcolor{forestgreen}{flow}(S\textsubscript{1} S\textsubscript{2}) & = & \textcolor{forestgreen}{flow}(S\textsubscript{1}) $\cup$ \textcolor{forestgreen}{flow}(S\textsubscript{2}) $\cup$ \{($\ell$, \textcolor{forestgreen}{init}(S\textsubscript{2})) | $\ell \in$ \textcolor{forestgreen}{final}(S\textsubscript{1})\} \\
\textcolor{forestgreen}{flow}(if [b]\textsuperscript{$\ell$} \{S\textsubscript{0}\}) & = & \{($\ell$l, \textcolor{forestgreen}{init}(S\textsubscript{0}))\} $\cup$ \textcolor{forestgreen}{flow}(S\textsubscript{0}) \\
\textcolor{forestgreen}{flow}(if [b]\textsuperscript{$\ell$}\{S\textsubscript{1}\}else\{S\textsubscript{2}\}) & = & \textcolor{forestgreen}{flow}(S\textsubscript{1}) $\cup$ \textcolor{forestgreen}{flow}(S\textsubscript{2}) $\cup$ \{($\ell$, \textcolor{forestgreen}{init}(S\textsubscript{1})),$\ell$, \textcolor{forestgreen}{init}(S\textsubscript{2}))\} \\
\textcolor{forestgreen}{flow}(while [b]\textsuperscript{$\ell$} \{S\textsubscript{0}\}) & = & \{($\ell$, \textcolor{forestgreen}{init}(S\textsubscript{0}))\} $\cup$ \textcolor{forestgreen}{flow}(S\textsubscript{0}) $\cup$ \{($\ell$', $\ell$) | $\ell$' $\in$ \textcolor{forestgreen}{final}(S\textsubscript{0})\} \\
\end{tabular}
\caption{Function flow in MicroC.}
\label{table:MicroCFunctionFlow}
\end{table}
\end{center}
答案1
错误的原因是该标记\emptyset
是数学模式符号。
$\emptyset$
才是应该的。
尝试一下。对我有用:
我还调整了您的颜色名称。对您的 MWE 进行了一些小修复。
\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{amsmath}
\definecolor{ForestGreen}{RGB}{34,139,34}
\begin{document}
\begin{center}
\begin{table}[h!]
\begin{tabular}{ c c c }
\textcolor{ForestGreen}{flow}([int x;]\textsuperscript{$\ell$}) & = & $\emptyset$ \\
\textcolor{ForestGreen}{flow}([int[n] A;]\textsuperscript{$\ell$}) & = & $\emptyset$ \\
\textcolor{ForestGreen}{flow}([\{int fst; int snd\} R; ]\textsuperscript{$\ell$}) & = & $\emptyset$ \\
\textcolor{ForestGreen}{flow}(D\textsubscript{1} D\textsubscript{2}) & = & \textcolor{ForestGreen}{flow}(D\textsubscript{1}) $\cup$ \textcolor{ForestGreen}{flow}(D\textsubscript{2}) $\cup$ \{($\ell$, \textcolor{ForestGreen}{init}(D\textsubscript{2})) | $\ell \in$ \textcolor{ForestGreen}{final}(D\textsubscript{1})\} \\
\textcolor{ForestGreen}{flow}([$\ell$ := a;]\textsuperscript{$\ell$}) & = & $\emptyset$ \\
\textcolor{ForestGreen}{flow}([R := (a\textsubscript{1}, a\textsubscript{2}); ]\textsuperscript{$\ell$}) & = & $\emptyset$ \\
\textcolor{ForestGreen}{flow}([read k;]\textsuperscript{$\ell$}) & = & $\emptyset$ \\
\textcolor{ForestGreen}{flow}([write $\ell$;]\textsuperscript{$\ell$}) & = & $\emptyset$ \\
\textcolor{ForestGreen}{flow}(S\textsubscript{1} S\textsubscript{2}) & = & \textcolor{ForestGreen}{flow}(S\textsubscript{1}) $\cup$ \textcolor{ForestGreen}{flow}(S\textsubscript{2}) $\cup$ \{($\ell$, \textcolor{ForestGreen}{init}(S\textsubscript{2})) | $\ell \in$ \textcolor{ForestGreen}{final}(S\textsubscript{1})\} \\
\textcolor{ForestGreen}{flow}(if [b]\textsuperscript{$\ell$} \{S\textsubscript{0}\}) & = & \{($\ell$l, \textcolor{ForestGreen}{init}(S\textsubscript{0}))\} $\cup$ \textcolor{ForestGreen}{flow}(S\textsubscript{0}) \\
\textcolor{ForestGreen}{flow}(if [b]\textsuperscript{$\ell$}\{S\textsubscript{1}\}else\{S\textsubscript{2}\}) & = & \textcolor{ForestGreen}{flow}(S\textsubscript{1}) $\cup$ \textcolor{ForestGreen}{flow}(S\textsubscript{2}) $\cup$ \{($\ell$, \textcolor{ForestGreen}{init}(S\textsubscript{1})),$\ell$, \textcolor{ForestGreen}{init}(S\textsubscript{2}))\} \\
\textcolor{ForestGreen}{flow}(while [b]\textsuperscript{$\ell$} \{S\textsubscript{0}\}) & = & \{($\ell$, \textcolor{ForestGreen}{init}(S\textsubscript{0}))\} $\cup$ \textcolor{ForestGreen}{flow}(S\textsubscript{0}) $\cup$ \{($\ell$', $\ell$) | $\ell$' $\in$ \textcolor{ForestGreen}{final}(S\textsubscript{0})\} \\
\end{tabular}
\caption{Function flow in MicroC.}
\label{table:MicroCFunctionFlow}
\end{table}
\end{center}
\end{document}
答案2
您\emptyset
处于文本模式。
然而,在我看来,您的输入应该被视为全部是数学。
以下是该表的三种实现。
\documentclass{article}
\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}
\DeclareMathOperator{\cflow}{\textcolor{ForestGreen}{flow}}
\DeclareMathOperator{\cfinal}{\textcolor{ForestGreen}{final}}
\DeclareMathOperator{\cinit}{\textcolor{ForestGreen}{init}}
\newcommand{\fn}[1]{\operatorname{#1}}
\newcommand{\vr}[1]{\mathrm{#1}}
\begin{document}
\begin{table}[htp!]
\[
\renewcommand{\arraystretch}{1.2}
\begin{array}{ @{} c @{{}={}} c @{} }
\cflow([\fn{int} x;]^{\ell}) & \emptyset \\
\cflow([\fn{int}[n] A;]^{\ell}) & \emptyset \\
\cflow([\{\fn{int} \vr{fst}; \fn{int} \vr{snd}\} R; ]^{\ell}) & \emptyset \\
\cflow(D_{1} D_{2}) &
\cflow(D_{1}) \cup \cflow(D_{2}) \cup \{(\ell, \cinit(D_{2}))\mid\ell \in \cfinal(D_{1})\} \\
\cflow([\ell := a;]^{\ell}) & \emptyset \\
\cflow([R := (a_{1}, a_{2}); ]^{\ell}) & \emptyset \\
\cflow([\fn{read} k;]^{\ell}) & \emptyset \\
\cflow([\fn{write} \ell;]^{\ell}) & \emptyset \\
\cflow(S_{1} S_{2}) &
\cflow(S_{1}) \cup \cflow(S_{2}) \cup \{(\ell, \cinit(S_{2})) \mid \ell \in \cfinal(S_{1})\} \\
\cflow(\fn{if} [b]^{\ell} \{S_{0}\}) & \{(\ell, \cinit(S_{0}))\} \cup \cflow(S_{0}) \\
\cflow(\fn{if} [b]^{\ell}\{S_{1}\} \fn{else} \{S_{2}\}) &
\cflow(S_{1}) \cup \cflow(S_{2}) \cup \{(\ell, \cinit(S_{1})),\ell, \cinit(S_{2}))\} \\
\cflow(\fn{while} [b]^{\ell} \{S_{0}\}) &
\{(\ell, \cinit(S_{0}))\} \cup \cflow(S_{0}) \cup \{(\ell', \ell) \mid \ell' \in \cfinal(S_{0})\} \\
\end{array}
\]
\caption{Function flow in MicroC.}
\label{table:MicroCFunctionFlow}
\end{table}
\begin{table}[htp!]
\[
\begin{aligned}
& \cflow([\fn{int} x;]^{\ell}) = \emptyset \\
& \cflow([\fn{int}[n] A;]^{\ell}) = \emptyset \\
& \cflow([\{\fn{int} \vr{fst}; \fn{int} \vr{snd}\} R; ]^{\ell}) = \emptyset \\
& \cflow(D_{1} D_{2}) = \cflow(D_{1}) \cup \cflow(D_{2}) \cup \{(\ell, \cinit(D_{2}))\mid\ell \in \cfinal(D_{1})\} \\
& \cflow([\ell := a;]^{\ell}) = \emptyset \\
& \cflow([R := (a_{1}, a_{2}); ]^{\ell}) = \emptyset \\
& \cflow([\fn{read} k;]^{\ell}) = \emptyset \\
& \cflow([\fn{write} \ell;]^{\ell}) = \emptyset \\
& \cflow(S_{1} S_{2}) = \cflow(S_{1}) \cup \cflow(S_{2}) \cup \{(\ell, \cinit(S_{2})) \mid \ell \in \cfinal(S_{1})\} \\
& \cflow(\fn{if} [b]^{\ell} \{S_{0}\}) = \{(\ell, \cinit(S_{0}))\} \cup \cflow(S_{0}) \\
& \cflow(\fn{if} [b]^{\ell}\{S_{1}\} \fn{else} \{S_{2}\}) = \cflow(S_{1}) \cup \cflow(S_{2}) \cup \{(\ell, \cinit(S_{1})),\ell, \cinit(S_{2}))\} \\
& \cflow(\fn{while} [b]^{\ell} \{S_{0}\}) = \{(\ell, \cinit(S_{0}))\} \cup \cflow(S_{0}) \cup \{(\ell', \ell) \mid \ell' \in \cfinal(S_{0})\} \\
\end{aligned}
\]
\caption{Function flow in MicroC.}
\label{table:MicroCFunctionFlow-2}
\end{table}
\begin{table}[htp!]
\[
\begin{aligned}
\cflow([\fn{int} x;]^{\ell}) &= \emptyset \\
\cflow([\fn{int}[n] A;]^{\ell}) &= \emptyset \\
\cflow([\{\fn{int} \vr{fst}; \fn{int} \vr{snd}\} R; ]^{\ell}) &= \emptyset \\
\cflow(D_{1} D_{2}) &= \cflow(D_{1}) \cup \cflow(D_{2}) \cup \{(\ell, \cinit(D_{2}))\mid\ell \in \cfinal(D_{1})\} \\
\cflow([\ell := a;]^{\ell}) &= \emptyset \\
\cflow([R := (a_{1}, a_{2}); ]^{\ell}) &= \emptyset \\
\cflow([\fn{read} k;]^{\ell}) &= \emptyset \\
\cflow([\fn{write} \ell;]^{\ell}) &= \emptyset \\
\cflow(S_{1} S_{2}) &= \cflow(S_{1}) \cup \cflow(S_{2}) \cup \{(\ell, \cinit(S_{2})) \mid \ell \in \cfinal(S_{1})\} \\
\cflow(\fn{if} [b]^{\ell} \{S_{0}\}) &= \{(\ell, \cinit(S_{0}))\} \cup \cflow(S_{0}) \\
\cflow(\fn{if} [b]^{\ell}\{S_{1}\} \fn{else} \{S_{2}\}) &= \cflow(S_{1}) \cup \cflow(S_{2}) \cup \{(\ell, \cinit(S_{1})),\ell, \cinit(S_{2}))\} \\
\cflow(\fn{while} [b]^{\ell} \{S_{0}\}) &= \{(\ell, \cinit(S_{0}))\} \cup \cflow(S_{0}) \cup \{(\ell', \ell) \mid \ell' \in \cfinal(S_{0})\} \\
\end{aligned}
\]
\caption{Function flow in MicroC.}
\label{table:MicroCFunctionFlow-3}
\end{table}
\end{document}