3

In topic: Display Box A or Box B if then condition

i have used only one paratemeter

Old Rule: condition with TextX

\TextX      |            Show             |         Hide

Value      |     \posterbox A            |          \posterbox B

Blank       |    \posterbox B              |         \posterbox A

Now I want to create New Rule: condition with 2 parameters: TextX, TextY

\TextX     |   \TextY     |  Show one box       |                 Hide 3 boxes

Value      |   Value      |  \posterbox A     |                    B,C,D

Value      |   Blank     |   \posterbox B            |             A,C,D

Blank     |    Value     |   \posterbox C         |                A,B,D

Blank     |    Blank     |   \posterbox D         |                A,B,C

Minimal working code:

\RequirePackage{filecontents}
\begin{filecontents*}{file.tex}
 No,TextX,TextY,TextZ,TextW
 1,x1,y1,z1,w1
 2,,y2,z2,w2
 3,,y3,w3,
 4,,,,w4
 5,x5,y5,,
 6,,y6,z6,w6
 7,x7,y7,z7,w7

\end{filecontents*}

\documentclass{article}
\usepackage[a4paper,landscape]{geometry}
\usepackage{filecontents}
\usepackage{datatool}
\usepackage{wrapfig}
\usepackage{xparse}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{poster}

\usepackage{bbding}
\usepackage{pifont}
\usepackage{enumitem, setspace}
 \tcbset{colframe=blue!75!black,colback=white}


 \DTLloaddb{file}{file.tex}

 \begin{document}

 \DTLforeach*
 {file}% Database
 {\No=No,\TextX=TextX,\TextY=TextY,\TextZ=TextZ,\TexW=TextW}
 {%
 \begin{tcbposter}[
  poster = {
    columns=1,
    rows=1,
    spacing=3mm,
    height=14cm,
    width=12cm,
  },
]
%Box A
\expandafter\ifx\expandafter\relax\TextX\relax\else
\posterbox[colframe=red,width=5cm,height=5cm]{name=A,column=1}{
\includegraphics[height=3cm]{example-image-a} 
 \begin{enumerate}[wide, leftmargin =-1em, rightmargin=-1em]
\item A \TextX
\end{enumerate}
}\fi
%\newpage

%Box B
\expandafter\ifx\expandafter\relax\TextX\relax
\posterbox[colframe=blue,width=5cm,height=5cm]{name=B,column=1,xshift=5.0cm,yshift=0.0cm}{
 \begin{enumerate}

\item B \TextY
\item B \TextY
\item B \TextY
\end{enumerate}
\includegraphics[height=2cm]{example-image-b}
}\fi
\vspace{2cm}
%BoxC
\posterbox[colframe=green,width=5cm,height=5cm]{name=C,column=1,xshift=1.0cm,yshift=-7.0cm}{
\begin{enumerate}

\item C \TextZ
\item C \TextZ
\end{enumerate}
\includegraphics[height=2cm]{example-image-c}
}
%BoxD
\posterbox[colframe=black,width=5cm,height=5cm]{name=C,column=1,xshift=8.0cm,yshift=-7.0cm}{
\includegraphics[height=2cm]{example-image-duck}
 \begin{enumerate}

\item D \TextW
\item D \TextW
\end{enumerate}

}
\end{tcbposter}
\newpage
}

\end{document}

Please update code with new rule: 2 paramters

Thanks

3

You could nest some \if conditionals:

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.dat}
 No,TextX,TextY,TextZ,TextW
 1,x1,y1,z1,w1
 2,,y2,z2,w2
 3,,y3,w3,
 4,,,,w4
 5,x5,y5,,
 6,,y6,z6,w6
 7,x7,y7,z7,w7
\end{filecontents*}

\documentclass{article}
\usepackage[a4paper,landscape]{geometry}
\usepackage{datatool}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{poster}

\usepackage{enumitem, setspace}
\tcbset{colframe=blue!75!black,colback=white}

\DTLloaddb{file}{\jobname.dat}

\newcommand{\select}[2]{%
  \if\relax#1\relax
    \if\relax#2\relax
      \selectD % 00
    \else
      \selectC % 01
    \fi
  \else
    \if\relax#2\relax
      \selectB % 10
    \else
      \selectA % 11
    \fi
  \fi
}
\newcommand{\selectA}{%
  \posterbox[colframe=red,width=5cm,height=5cm]{name=A,column=1}{%
    \includegraphics[height=3cm]{example-image-a} 
    \begin{enumerate}[wide, leftmargin =-1em, rightmargin=-1em]
    \item A \TextX
    \end{enumerate}
  }%
}
\newcommand{\selectB}{%
  %Box B
  \posterbox[colframe=blue,width=5cm,height=5cm]{name=B,column=1,xshift=5.0cm,yshift=0.0cm}{%
    \begin{enumerate}
    \item B \TextY
    \item B \TextY
    \item B \TextY
  \end{enumerate}
  \includegraphics[height=2cm]{example-image-b}
  }%
}
\newcommand{\selectC}{%
  %BoxC
  \posterbox[colframe=green,width=5cm,height=5cm]{name=C,column=1,xshift=1.0cm,yshift=-7.0cm}{%
    \begin{enumerate}
    \item C \TextZ
    \item C \TextZ
    \end{enumerate}
    \includegraphics[height=2cm]{example-image-c}
  }%
}
\newcommand{\selectD}{%
  %BoxD
  \posterbox[colframe=black,width=5cm,height=5cm]{name=C,column=1,xshift=8.0cm,yshift=-7.0cm}{%
    \includegraphics[height=2cm]{example-image-duck}
    \begin{enumerate}
    \item D \TextW
    \item D \TextW
    \end{enumerate}
  }%
}

\begin{document}

\DTLforeach*{file}% Database
 {\No=No,\TextX=TextX,\TextY=TextY,\TextZ=TextZ,\TextW=TextW}
 {%
  \begin{tcbposter}[
    poster = {
      columns=1,
      rows=1,
      spacing=3mm,
      height=14cm,
      width=12cm,
    },
  ]
  \select{\TextX}{\TextY}
  \end{tcbposter}
  \newpage
}

\end{document}
3

You could extend the idea from your previous post and do this by having multiple branches of \if-statements like

\expandafter\ifx\expandafter\relax\TextX\relax
  \expandafter\ifx\expandafter\relax\TextY\relax\else
  ...
\fi\fi...\fi

but this will end up looking pretty nasty. Instead, the code below defines a command \FourWayChoice that accepts 6 arguments and is used as

\FourWayChoice{\TextX}{\TextY}{Box A}{Box B}{Box C}{Box D}

where the different "boxes" are chosen as per the table in the OP. The definition of the \FourWayChoice macro is pretty easy, partly because I use LaTeX3. You can use the same idea to answer the previous post.

Using this code, page 2 of the MWE looks like this:

enter image description here

Here is the full code:

\RequirePackage{filecontents}
\begin{filecontents*}{file.tex}
 No,TextX,TextY,TextZ,TextW
 1,x1,y1,z1,w1
 2,,y2,z2,w2
 3,,y3,w3,
 4,,,,w4
 5,x5,y5,,
 6,,y6,z6,w6
 7,x7,y7,z7,w7

\end{filecontents*}

\documentclass{article}
\usepackage[a4paper,landscape]{geometry}
\usepackage{filecontents}
\usepackage{datatool}
\usepackage{wrapfig}
\usepackage{xparse}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{poster}

\usepackage{bbding}
\usepackage{pifont}
\usepackage{enumitem, setspace}
\tcbset{colframe=blue!75!black,colback=white}
\DTLloaddb{file}{file.tex}

\usepackage{expl3}
\ExplSyntaxOn
\cs_generate_variant:Nn \str_set:Nn {No}
\str_new:N \l_text_x_str
\str_new:N \l_text_y_str
\NewDocumentCommand\FourWayChoice{ mm mmmm }{
  \str_set:No \l_text_x_str {#1}
  \str_set:No \l_text_y_str {#2}
  \str_if_empty:NTF \l_text_x_str
    { \str_if_empty:NTF \l_text_y_str {#6} {#5} }
    { \str_if_empty:NTF \l_text_y_str {#4} {#3} }
}
\ExplSyntaxOff

\begin{document}

 \DTLforeach*
 {file}% Database
 {\No=No,\TextX=TextX,\TextY=TextY,\TextZ=TextZ,\TextW=TextW}
 {%
 \begin{tcbposter}[
    poster = {
      columns=1,
      rows=1,
      spacing=3mm,
      height=14cm,
      width=12cm,
    },
  ]
  \FourWayChoice{\TextX}{\TextY}
    { % Box A
      \posterbox[colframe=red,width=5cm,height=5cm]{name=A,column=1}{
        \includegraphics[height=3cm]{example-image-a}
          \begin{enumerate}[wide, leftmargin =-1em, rightmargin=-1em]
             \item A \TextX
          \end{enumerate}
        }
    }
    { % Box B
      \posterbox[colframe=blue,width=5cm,height=5cm]
        {name=B,column=1,xshift=5.0cm,yshift=0.0cm}{
        \begin{enumerate}
          \item B \TextY
          \item B \TextY
          \item B \TextY
        \end{enumerate}
        \includegraphics[height=2cm]{example-image-b}
      }
    }
    { % BoxC
      \posterbox[colframe=green,width=5cm,height=5cm]
         {name=C,column=1,xshift=1.0cm,yshift=-7.0cm}{
        \begin{enumerate}
          \item C \TextZ
          \item C \TextZ
        \end{enumerate}
        \includegraphics[height=2cm]{example-image-c}
      }
    }
    { % BoxD
      \posterbox[colframe=black,width=5cm,height=5cm]
        {name=C,column=1,xshift=8.0cm,yshift=-7.0cm}{
        \includegraphics[height=2cm]{example-image-duck}
        \begin{enumerate}
          \item D \TextW
          \item D \TextW
        \end{enumerate}
      }
    }
  \end{tcbposter}
  %\newpage
}

\end{document}
  • i use your above code but there are 4 pages. Other pages: 2,4,6 do not display? – latexforti May 11 at 7:31
  • 1
    @latexforti Note that I commented out the \newpage at the bottom. If I remove then comment then this generates 7 pages for me, as it should since file.tex has 7 entries. – Andrew May 11 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.