在 longtable 中使用 \isodd

在 longtable 中使用 \isodd

我想使用类似

\ifthenelse{\isodd{rowno}}{\rowcolor{green!30}}{\rowcolor{blue!30}}&$\mathbb{N}$ & The set of all natural numbers\\ \hline

但它不起作用。它给出了错误!放错了 \noalign。

同样,如果我想将每隔三行涂成绿色,我该怎么做?


\documentclass{article}
\usepackage[table,dvipsnames,svgnames]{xcolor}
\usepackage{colortbl} %For coloring row, column or cell
\usepackage{longtable} %to break tables across pages
\usepackage{array} %Used for autonumbering row of a table.
\newcounter{rowno}
\setcounter{rowno}{0}
\usepackage{amsfonts}
\usepackage{ifthen}

\begin{document}

\begin{center}
\begin{longtable}{|r<{\stepcounter{rowno}(\therowno)} | l | l |}
\hline
\rowcolor{orange}\multicolumn{1}{|c}{\small \textbf{No.}} & \multicolumn{1}{|c|}{\small Symbol} & \multicolumn{1}{c|}{\small Description of the set}\\
\hline
\ifthenelse{\isodd{rowno}}{\rowcolor{green!30}}{\rowcolor{blue!30}}& The set of all natural numbers\\ \hline
\rowcolor{blue!30} &$\mathbb{Z}$ & The set of all integers \\ \hline
\rowcolor{green!30} &$J_n$ & $\{1,2,3,\dots , n\}$, $n \in \mathbb{N}$\\ \hline
\rowcolor{blue!30} &$\mathbb{Q}$ & The set of all rational numbers\\ \hline
\rowcolor{green!30} &$\mathbb{R}$ & The set of all real numbers\\ \hline
\rowcolor{blue!30} &$\mathbb{C}$ & The set of all complex numbers\\ \hline
\caption{Standard Sets}\label{Tab:001}
\end{longtable}
\end{center}

\end{document} 

答案1

\ifthenelse是不可扩展的,所以它会阻止 TeX 寻找诸如\noalign(隐式使用\rowcolor)或 之类的东西\multicolumn

您可以使用原始测试。

\documentclass{article}
\usepackage[table,dvipsnames,svgnames]{xcolor}
\usepackage{longtable} %to break tables across pages
\usepackage{array} %Used for autonumbering row of a table.
\usepackage{amsfonts}

\newcounter{rowno}

\begin{document}

\begin{longtable}{|r<{\stepcounter{rowno}(\therowno)} | l | l |}
\hline
\rowcolor{orange}
\multicolumn{1}{|c}{\small \textbf{No.}} &
\multicolumn{1}{|c|}{\small Symbol} &
\multicolumn{1}{c|}{\small Description of the set}\\
\hline
\ifodd\value{rowno}\rowcolor{green!30}\else\rowcolor{blue!30}\fi &
$\mathbb{N}$ & The set of all natural numbers\\ \hline
\rowcolor{blue!30} &$\mathbb{Z}$ & The set of all integers \\ \hline
\rowcolor{green!30} &$J_n$ & $\{1,2,3,\dots , n\}$, $n \in \mathbb{N}$\\ \hline
\rowcolor{blue!30} &$\mathbb{Q}$ & The set of all rational numbers\\ \hline
\rowcolor{green!30} &$\mathbb{R}$ & The set of all real numbers\\ \hline
\rowcolor{blue!30} &$\mathbb{C}$ & The set of all complex numbers\\ \hline
\caption{Standard Sets}\label{Tab:001}
\end{longtable}

\end{document}

请注意,您不需要加载colortbl,因为xcolor它使用table选项来执行。

在此处输入图片描述

不过,我不确定这个测试是否真的是你想要的。请使用\rowcolors

\documentclass{article}
\usepackage[table,dvipsnames,svgnames]{xcolor}
\usepackage{longtable} %to break tables across pages
\usepackage{array} %Used for autonumbering row of a table.
\usepackage{amsfonts}

\newcounter{rowno}

\begin{document}

\rowcolors{2}{green!30}{blue!30}
\begin{longtable}{|r<{\stepcounter{rowno}(\therowno)} | l | l |}
\hline
\rowcolor{orange}
\multicolumn{1}{|c}{\small \textbf{No.}} &
\multicolumn{1}{|c|}{\small Symbol} &
\multicolumn{1}{c|}{\small Description of the set}\\
\hline
&$\mathbb{N}$ & The set of all natural numbers\\ \hline
&$\mathbb{Z}$ & The set of all integers \\ \hline
&$J_n$ & $\{1,2,3,\dots , n\}$, $n \in \mathbb{N}$\\ \hline
&$\mathbb{Q}$ & The set of all rational numbers\\ \hline
&$\mathbb{R}$ & The set of all real numbers\\ \hline
&$\mathbb{C}$ & The set of all complex numbers\\ \hline
\rowcolor{white}\caption{Standard Sets}\label{Tab:001} \\
\end{longtable}

\end{document}

在此处输入图片描述

我不明白为什么longtable在这里使用。无论如何,它不应该被括在里面center

相关内容