On a conditional command: more powerful than \ifnum
In order to reproduce the picture, the test should be 1 ≤ x < y.
You can parametrize the rotation angle and test for the two special cases.
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x in {1,...,4} {
\foreach \y in {1,...,4} {
\def\rotation{-45}
\ifnum\y=1
\ifnum\x=1 \def\rotation{0} \fi
\ifnum\x=2 \def\rotation{0} \fi
\fi
\fill[red!50] (\x,\y) ellipse [x radius=3pt, y radius=6pt, rotate=\rotation];
\ifnum \x<\y \unless\ifnum \x<1 \breakforeach \fi\fi
}
}
\draw [|-|] (.895,1) -- ++(0.211,0);
\end{tikzpicture}
\end{document}
You can also use \ifthenelse
, of course.
\documentclass{standalone}
\usepackage{tikz}
\usepackage{xifthen}
\begin{document}
\begin{tikzpicture}
\foreach \x in {1,...,4} {
\foreach \y in {1,...,4} {
\ifthenelse{\y=1 \AND \(\x=1 \OR \x=2\)}{\def\rotation{0}}{\def\rotation{-45}}
\fill[red!50] (\x,\y) ellipse [x radius=3pt, y radius=6pt, rotate=\rotation];
\ifthenelse{ \x<\y \AND \NOT\(\x<1\) }{\breakforeach}{}
}
}
\draw [|-|] (.895,1) -- ++(0.211,0);
\end{tikzpicture}
\end{document}
With a somewhat easier syntax, see https://tex.stackexchange.com/a/467527/4427
\documentclass[border=4]{standalone}
\usepackage{tikz}
\usepackage{xparse}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\xifthenelse}{mmm}
{
\bool_if:nTF { #1 } { #2 } { #3 }
}
\cs_new_eq:NN \numtest \int_compare_p:n
\cs_new_eq:NN \oddtest \int_if_odd_p:n
\cs_new_eq:NN \fptest \fp_compare_p:n
\cs_new_eq:NN \dimtest \dim_compare_p:n
\cs_new_eq:NN \deftest \cs_if_exist_p:N
\cs_new_eq:NN \namedeftest \cs_if_exist_p:c
\cs_new_eq:NN \eqdeftest \token_if_eq_meaning_p:NN
\cs_new_eq:NN \streqtest \str_if_eq_p:ee
\cs_new_eq:NN \emptytest \tl_if_blank_p:n
\prg_new_conditional:Nnn \xxifthen_legacy_conditional:n { p,T,F,TF }
{
\use:c { if#1 } \prg_return_true: \else: \prg_return_false: \fi:
}
\cs_new_eq:NN \boolean \xxifthen_legacy_conditional_p:n
\ExplSyntaxOff
\begin{document}
\begin{tikzpicture}
\foreach \x in {1,...,4} {
\foreach \y in {1,...,4} {
\xifthenelse{\numtest{\y=1} && (\numtest{\x=1} || \numtest{\x=2})}
{\def\rotation{0}}
{\def\rotation{-45}}
\fill[red!50] (\x,\y) ellipse [x radius=3pt, y radius=6pt, rotate=\rotation];
\xifthenelse{ \numtest{1<=\x<\y} }{\breakforeach}{}
}
}
\draw [|-|] (.895,1) -- ++(0.211,0);
\end{tikzpicture}
\end{document}
LaTeX's ifthen package has some facility for combining conditionals with \and
and \or
, \not
and parentheses. But your case is easy to do with \ifnum
:
\ifnum \x<\y \ifnum \x>1
\breakforeach
\fi\fi