3

I am using datatool and want to display \posterbox A, hide box B if \TextA = value, if \TextA = blank display \posterbox B and hide box A.

Box A & Box B are different: Image, item, color, position of image, number of items...

My Minimal Coding:

      \RequirePackage{filecontents}
\begin{filecontents*}{file.tex}
 No,TextA,TextB
 1,a1,b1
 2,a2,b2
 3,,b3
 4,,
 5,a5,b5
 6,,b6

\end{filecontents*}

\documentclass{article}
\usepackage[a4paper]{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,\TextA=TextA,\TextB=TextB}
 {%
 \begin{tcbposter}[
  poster = {
    columns=1,
    rows=1,
    spacing=3mm,
    height=14cm,
    width=12cm,
  },
]
%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 \TextA
\end{enumerate}

}
%\newpage
\hspace{7cm}
%Box B
\posterbox[colframe=blue,width=5cm,height=5cm]{name=B,column=1}{
 \begin{enumerate}

\item \TextB
\item \TextB
\item \TextB
\end{enumerate}
\includegraphics[height=2cm]{example-image-b}
}
\end{tcbposter}
\newpage
}

\end{document}

enter image description here

Thank in advance

2

EDIT: This code will exclude box A if \TextA is empty, and it will exclude Box B is \TextA is not empty. Still waiting for guidance on what to do if both \TextA and \TextB are empty.

\RequirePackage{filecontents}
\begin{filecontents*}{file.tex}
 No,TextA,TextB
 1,a1,b1
 2,a2,b2
 3,,b3
 4,,
 5,a5,b5
 6,,b6

\end{filecontents*}

\documentclass{article}
\usepackage[a4paper]{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,\TextA=TextA,\TextB=TextB}
 {%
 \begin{tcbposter}[
  poster = {
    columns=1,
    rows=1,
    spacing=3mm,
    height=14cm,
    width=12cm,
  },
]
%Box A
\expandafter\ifx\expandafter\relax\TextA\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 \TextA
\end{enumerate}
}\fi
%\newpage
\hspace{7cm}
%Box B
\expandafter\ifx\expandafter\relax\TextA\relax
\posterbox[colframe=blue,width=5cm,height=5cm]{name=B,column=1}{
 \begin{enumerate}

\item \TextB
\item \TextB
\item \TextB
\end{enumerate}
\includegraphics[height=2cm]{example-image-b}
}\fi
\end{tcbposter}
\newpage
}

\end{document}
  • Your code is really good and can you edit: now a1, a5 can see both box A & Box B. I need if a1, a5 !=blank then see only box A, and don't display box B. 2/ And "%% EXCLUDE BOX B IF \TextA = a2": can you correcht \TextA !=blank => Excude box B. Please compare with blank, not "a2". I don;t understand it. Thanks – latexforti May 8 at 14:41
  • 1
    @latexforti Do I understand that if ever \TextA is non-empty, that you would like only Box A and not Box B? – Steven B. Segletes May 8 at 15:08
  • @latexforti ...and what if neither \TextA nor \TextB are defined? What then? – Steven B. Segletes May 8 at 15:10
  • B.Segletes. Your code is awesome, it works. If both (\TextA &\Text B = blank) then i will edit input in table. Manythanks – latexforti May 8 at 23:14

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.