以下是table.tex:
\documentclass{article}
\usepackage{color}
\begin{document}
\pagestyle{empty}
\begin{tabular}{ l | r }
Problem & Expansions \\
\hline
{\green Unit} Grid & \green 382,536 \\
{\red Life} Grid & \red 994,437 \\
\hline
{\green Unit} Pancake & \green 69 \\
{\red Sum} Pancake & \red 3,711 \\
\end{tabular}
\end{document}
当我做:
latex table
我收到此错误:
! Undefined control sequence.
l.14 {\green
Unit} Grid & \green 382,536 \
\red
对于和的其他用法,我也遇到了类似的错误\green
。使用\usepackage{color}
和\red
处理\green
其他文档时,我不明白为什么它在这种情况下不起作用。
答案1
\begin{document}
\pagestyle{empty}
\begin{tabular}{ l | r }
Problem & Expansions \\
\hline
{\color{green} Unit} Grid & {\color{green} 382,536} \\
{\color{red} Life} Grid & {\color{red} 994,437} \\
\hline
{\color{green} Unit} Pancake & {\color{green} 69} \\
{\color{red} Sum} Pancake & {\color{red} 3,711} \\
\end{tabular}
\end{document}
这就是你需要定义颜色变化的方式color
包的颜色变化的方式。以下是 wiki 参考的链接https://en.wikibooks.org/wiki/LaTeX/Colors
根据 egreg 的建议,
\begin{document}
\pagestyle{empty}
\begin{tabular}{ l | r }
Problem & Expansions \\
\hline
\textcolor{green}{Unit} Grid & \textcolor{green}{382,536} \\
\textcolor{red}{Life} Grid & \textcolor{red}{994,437} \\
\hline
\textcolor{green}{Unit} Pancake & \textcolor{green}{69} \\
\textcolor{red}{Sum} Pancake & \textcolor{red}{3,711} \\
\end{tabular}
\end{document}