0

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

Now i use newcommand with one varialbe

Minimal coding:

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.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
8,x8,,z8,w8
9,x9,,z9,w9
10,x10,y10,z10,w10
11,,y11,z11,w11
12,,y12,,
13,,,z13,w13
14,x14,,z14,w14
15,x15,y15,,w15
16,x16,y16,z16,w16
\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.tex}



\newcommand{\selectONE}[1]{%
\if\relax#1\relax
\selectA % 00
\else
\selectB % 01
\fi
}
\newcommand{\selectONEA}{%
%\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{\selectONEB}{%
%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

\end{enumerate}
\includegraphics[height=2cm]{example-image-b}
%}%
}


\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,
},
]
\posterbox[colframe=green,width=5cm,height=5cm]{name=C,column=1,xshift=2.0cm,yshift=-1.0cm}{%

\selectONE{\TextX}

}

\posterbox[colframe=green,width=5cm,height=5cm]{name=C,column=1,xshift=8.0cm,yshift=-7.0cm}{%

\selectONE{\TextY}

}
\end{tcbposter}
\newpage
}

\end{document}

In this code, overleaf appear error notification: undefined control sequence

Thank in advance

  • It is a simple typo: you forgot ONE in \selectA and \selectB, it needs to be \newcommand{\selectONE}[1]{% \if\relax#1\relax \selectONEA % 00 \else \selectONEB % 01 \fi } instead of \newcommand{\selectONE}[1]{% \if\relax#1\relax \selectA % 00 \else \selectB % 01 \fi } – Schrödinger's cat Nov 2 '19 at 3:01
  • 3
    \begin{filecontents*}{\jobname.tex} is a bad idea. It may work on overleaf but in a local system it would either not work or it would be a disaster if it did. So don't get into the habitude to use this syntax. – Ulrike Fischer Nov 2 '19 at 11:48
  • As Ulrike Fischer already pointed out: Don't try to overwrite \jobname.tex. In local systems \jobname.tex usually denotes the name of the main .tex-file of the source-code of the document which LaTeX is processing. E.g., if on a local system the source of my document is saved as main.tex and is compiled via the command-line pdflatex main.tex, then \jobname will yield the sequence main. Trying to overwrite main.tex will not be a good idea. Your question reminds me of this question. – Ulrich Diez Nov 2 '19 at 14:21
2

It is a simple typo, you are defining \selectONEA and \selectONEB, but using \selectA and \selectB. If you fix this,

\RequirePackage{filecontents}
\begin{filecontents*}{myfile.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
8,x8,,z8,w8
9,x9,,z9,w9
10,x10,y10,z10,w10
11,,y11,z11,w11
12,,y12,,
13,,,z13,w13
14,x14,,z14,w14
15,x15,y15,,w15
16,x16,y16,z16,w16
\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}{myfile.tex}



\newcommand{\selectONE}[1]{%
\if\relax#1\relax
\selectONEA % 00
\else
\selectONEB % 01
\fi
}
\newcommand{\selectONEA}{%
%\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{\selectONEB}{%
%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

\end{enumerate}
\includegraphics[height=2cm]{example-image-b}
%}%
}


\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,
},
]
\posterbox[colframe=green,width=5cm,height=5cm]{name=C,column=1,xshift=2.0cm,yshift=-1.0cm}{%

\selectONE{\TextX}

}

\posterbox[colframe=green,width=5cm,height=5cm]{name=C,column=1,xshift=8.0cm,yshift=-7.0cm}{%

\selectONE{\TextY}

}
\end{tcbposter}
\newpage
}

\end{document}

you get

enter image description here

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.