提前感谢您的帮助。如何向 \ifthenelse 添加多个条件?
我希望能够写:
\ifthenelse{varType equals 'HS' and metric equals 'KPI1'}
{do this}
\ifthenelse{varType does not equal 'HS' and metric equals 'KPI1'}
{do something else}
具体来说,我想将 MSL_POP$report == 'HS' 添加到:
\ifthenelse{\Sexpr{MSL_POP$exception[MSL_POP$metric == 'KPI1']} == 99999 and \Sexpr{MSL_POP$report == 'HS'}}
{do something}
\ifthenelse{\Sexpr{MSL_POP$exception[MSL_POP$metric == 'KPI1']} == 99999 and \Sexpr{MSL_POP$report != 'HS'}}
{do something else}
答案1
至少在使用包时,xifthen
您可以使用\OR
和\AND
构造等。例如:
\ifthenelse{\equal{a}{b} \AND \equal{c}{d}}
{do something when both a=b and c=d}
{do something when either unequal}
答案2
嵌套两个\ifthenelse
条件以实现正确的逻辑。
\documentclass{article}
\usepackage{ifthen}
\begin{document}
\def\a{T}% or {F}
\def\b{F}% or {T}
AND conditional:
\ifthenelse{\equal{\a}{T}}
{\ifthenelse{\equal{\b}{T}}{something}{something else}}
{something else}
OR conditional:
\ifthenelse{\equal{\a}{T}}
{something}
{\ifthenelse{\equal{\b}{T}}{something}{something else}}
\end{document}