I'm having lots of trouble when using \ifodd
. I want to make a pattern of alternating thick and thin lines, I have tried several ways but none of them works.
With this structure
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}[remember picture,overlay,shorten >= -10pt]
\coordinate (aux1) at ([xshift=-25mm, yshift=-30mm]current page.north east);
\coordinate (aux2) at ([xshift=-25mm, yshift=30mm]current page.south east);
\coordinate (aux3) at ([xshift=25mm, yshift=-30mm]current page.north west);
\coordinate (aux4) at ([xshift=25mm, yshift=30mm]current page.south west);
\begin{scope}[black]
\foreach \i [evaluate =\i as \x using int(\i)] in {0, ..., 4}{
\draw["\ifodd \x line width=1pt \else line width=2pt \fi" ]([
xshift=\x mm,
yshift=-65mm
]aux1)
--
([
xshift=\x mm,
yshift=10mm]
aux2);
}
\end{scope}
\end{tikzpicture}
\end{document}
I have tried
\foreach \x in {0, ..., 4}{
\draw["\ifodd \x line width=1pt \else line width=2pt \fi" ]([
}
\foreach \x in {0, ..., 4}{
\draw["\ifodd \num{\x} line width=1pt \else line width=2pt \fi" ]([
}
\foreach \x in {0, ..., 4}{
\draw["\ifodd \value{\x} line width=1pt \else line width=2pt \fi" ]([
}
\foreach \i [evaluate =\i as \x using int(\i)] in {0, ..., 4}{
\draw["\ifodd \x line width=1pt \else line width=2pt \fi" ]([
}
Note: I want to learn how to use \ifodd inside loops
\draw[line width=\ifodd\x\space1pt\else2pt\fi]
instead, but you'll get adimension too large
error from your picture anyway, not sure where exactly that comes from.\space
better than brace around the dimensions?\space
will end the\ifodd
without any other ill effects that{}
would have. The=
must be outside the\ifodd...\fi
block so thatpgfkeys
parses\ifodd\x\space1pt\else2pt\fi
as the value (which it'll then try to use as a dimension, and during that assignment, not during key-parsing, the conditional will get evaluated).