现在我使用一个变量的 newcommand
最少编码:
\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}
在这段代码中,overleaf出现错误通知:未定义的控制序列
预先感谢
答案1
这是一个简单的拼写错误,你定义了\selectONEA
和\selectONEB
,但使用了\selectA
和\selectB
。如果你修复了这个问题,
\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}
你得到