1

follow topic tcolorbox: specific width and height settings for odd and even pages

minimal code:

\documentclass{article}
\usepackage{datatool}
\usepackage{filecontents}
\usepackage[strict]{changepage}

\begin{filecontents*}{test2.csv}
Acol, Bcol, NoCol
Ax,Bx,1
Ay,By,3
A1,B22,2
A2,B44,4
A3,B11,5
\end{filecontents*}

\DTLloaddb{mydata}{test2.csv}

\newcommand*{\pageDependent}{\ifoddpage 5cm\else 10cm\fi\relax}

\begin{document}

\DTLforeach*{mydata}{\A=Acol,\B=Bcol}%
{%
 \A \checkoddpage\hspace{\pageDependent} \B
 \newpage
}%

\end{document}

How can i change

\newcommand*{\pageDependent}{\ifoddpage 5cm\else 10cm\fi\relax}

and \checkoddpage{\pageDependent} ...

with new below Rule of NoCol of Datatools:

  1. if Nocol = odd, \pageDependent = 5cm

  2. if Nocol = even, \pageDependent = 10cm

Thanks

Zarko
  • 296,517
latexforti
  • 2,091

1 Answers1

2

I propose the following:

\RequirePackage{filecontents}
\begin{filecontents*}{test2.csv}
Acol, Bcol, NoCol
Ax,Bx,1
Ay,By,3
A1,B22,2
A2,B44,4
A3,B11,5
\end{filecontents*}

\documentclass{article}
\usepackage{datatool}
\DTLloaddb{mydata}{test2.csv}

\makeatletter
\newcommand*{\valueDependent}[1]{%
  \ifodd #1
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\makeatother

\begin{document}

\DTLforeach*{mydata}{\A=Acol, \B=Bcol, \No=NoCol}%
{%
 \A
 \hspace{\valueDependent{\No}{5cm}{10cm}}%
 \B
 \par
}%

\end{document}

screenshot

This works because:

  • \hspace{something} does \hskip something\relax;

  • after digesting an \hskip command, TeX expands tokens until it has a 〈glue〉;

  • after enough expansions, my \valueDependent macro yields a 〈glue〉, because the TeX primitive \ifodd also expands tokens until it has a 〈number〉 (the column macros defined by datatool, such as \No here, are expandable).

In case you want the two lengths to be hardcoded inside \valueDependent, you can use:

\RequirePackage{filecontents}
\begin{filecontents*}{test2.csv}
Acol, Bcol, NoCol
Ax,Bx,1
Ay,By,3
A1,B22,2
A2,B44,4
A3,B11,5
\end{filecontents*}

\documentclass{article}
\usepackage{datatool}
\DTLloaddb{mydata}{test2.csv}

\newcommand*{\valueDependent}[1]{%
  \ifodd #1 5cm \else 10cm \fi
}

\begin{document}

\DTLforeach*{mydata}{\A=Acol, \B=Bcol, \No=NoCol}%
{%
 \A
 \hspace{\valueDependent{\No}}%
 \B
 \par
}%

\end{document}

The output is the same as in the previous screenshot.

frougon
  • 24,283
  • 1
  • 32
  • 55