Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass{article}
- \usepackage{datatool}
- \usepackage[strict]{changepage}
- \usepackage{filecontents}
- \usepackage{tcolorbox}
- \usepackage[absolute,overlay]{textpos}
- \usepackage{xcolor}
- \usepackage{xparse}
- \begin{filecontents*}{test1.csv}
- Acol, Bcol,Ccol
- Ax,Bx,1
- Ay,By,3
- A1,B22,1
- A2,B44,2
- A3,B11,3
- \end{filecontents*}
- % If you include a line such as 'A4,B55,4' without saying how \xLength and
- % \yLength should be set in this case, you'll get the error message:
- %
- % Package lforti Error: Encountered value '4', but no case was written for it.
- \DTLloaddb{mydata1}{test1.csv}
- \newlength{\xlengthForOddPages}
- \newlength{\xlengthForEvenPages}
- \newlength{\ylengthForOddPages}
- \newlength{\ylengthForEvenPages}
- \setlength{\xlengthForOddPages}{2cm}
- \setlength{\xlengthForEvenPages}{10cm}
- \setlength{\ylengthForOddPages}{1.5cm}
- \setlength{\ylengthForEvenPages}{5cm}
- \newif\ifmyoddpage % always set globally, contrary to \ifoddpage
- \newcommand*{\xpageDependent}{%
- \ifmyoddpage
- \expandafter
- \xlengthForOddPages
- \else
- \expandafter
- \xlengthForEvenPages
- \fi
- }
- \newcommand*{\ypageDependent}{%
- \ifmyoddpage
- \expandafter
- \ylengthForOddPages
- \else
- \expandafter
- \ylengthForEvenPages
- \fi
- }
- \newcommand*{\mycheckoddpage}{%
- \checkoddpage
- \global\let\ifmyoddpage=\ifoddpage
- }
- \ExplSyntaxOn
- \msg_new:nnn { lforti } { unhandled-value }
- { Encountered~value~'\exp_not:n~{#1}',~but~no~case~was~written~for~it. }
- \tl_new:N \l__lforti_cond_length_setup_conds_tl
- \seq_new:N \l__lforti_cond_length_setup_tmpa_seq
- \seq_new:N \l__lforti_cond_length_setup_tmpb_seq
- % Flexible length setup that may depend on whether it is called on an odd page
- % or on an even page.
- %
- % #1: a LaTeX length command (or a TeX \skipdef token) to set according to
- % #2 and #3
- % #2: the value to test against
- % #3: a comma list describing the different cases:
- %
- % {value_1, length-for-odd-pages, length-for-even-pages},
- % {value_2, length-for-odd-pages, length-for-even-pages},
- % ...
- % {value_n, length-for-odd-pages, length-for-even-pages},
- \cs_new_protected:Npn \lforti_cond_length_setup:Nnn #1#2#3
- {
- \checkoddpage % make sure it is used on the relevant page
- \seq_set_from_clist:Nn \l__lforti_cond_length_setup_tmpa_seq {#3}
- \tl_clear:N \l__lforti_cond_length_setup_conds_tl
- \seq_map_inline:Nn \l__lforti_cond_length_setup_tmpa_seq
- {
- \seq_set_from_clist:Nn \l__lforti_cond_length_setup_tmpb_seq {##1}
- \tl_put_right:Nx \l__lforti_cond_length_setup_conds_tl
- {
- % Value to check against
- { \seq_item:Nn \l__lforti_cond_length_setup_tmpb_seq { 1 } }
- { % Corresponding setup code for #1
- \exp_not:N \skip_set:Nn \exp_not:N #1
- {
- \seq_item:Nn
- \l__lforti_cond_length_setup_tmpb_seq
- { \ifoddpage 2 \else 3 \fi }
- }
- }
- }
- }
- % Handle value #2 according to the cases described by #3
- \str_case:nVF {#2} \l__lforti_cond_length_setup_conds_tl
- { \msg_error:nnn { lforti } { unhandled-value } {#2} }
- }
- \cs_generate_variant:Nn \lforti_cond_length_setup:Nnn { Nx }
- % Same as \lforti_cond_length_setup:Nnn (see above), except that the second
- % argument will be fully expanded (\lforti_cond_length_setup:Nnn will only see
- % the *result* of this expansion in its #2).
- \NewDocumentCommand \lforticondlengthsetup { m m m }
- {
- \lforti_cond_length_setup:Nxn #1 {#2} {#3}
- }
- \ExplSyntaxOff
- \newlength{\xLength}
- \newlength{\yLength}
- \begin{document}
- \lforticondlengthsetup{\xLength}{\C}{%
- {1, 2cm, 4cm}, % When \C expands to 1, use 2cm on odd pages, 4cm on even pages
- {2, 3cm, 5cm}, % When \C expands to 2, use 3cm on odd pages, 5cm on even pages
- {3, 4cm, 4cm}, % When \C expands to 3, use 4cm on all pages
- }%
- \lforticondlengthsetup{\yLength}{\C}{% analogous setup for \yLength
- {1, 1.5cm, 12cm},
- {2, 2cm, 23cm},
- {3, 3cm, 1.5cm},
- }%
- \DTLforeach*{mydata1}{\A=Acol,\B=Bcol,\C=Ccol}%
- {%
- \begin{textblock*}{5cm}(\xLength,\yLength)
- \color{blue!50!black}%
- \noindent
- abc \\
- \texttt{\string\xLength} = \the\xLength\\
- \texttt{\string\yLength} = \the\yLength
- \end{textblock*}
- \begin{tcolorbox}[width=\xLength,height=\yLength,
- title={Title}]
- \C
- \end{tcolorbox}
- \newpage
- }
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement