![如果条件则显示框 A 或框 B](https://linux22.com/image/395350/%E5%A6%82%E6%9E%9C%E6%9D%A1%E4%BB%B6%E5%88%99%E6%98%BE%E7%A4%BA%E6%A1%86%20A%20%E6%88%96%E6%A1%86%20B.png)
我正在使用datatool
并希望显示A,如果= 值则\posterbox
隐藏框 B ,如果= 空白则显示B 并隐藏框 A。\TextA
\TextA
\posterbox
盒子 A 和盒子 B 不同:图像、物品、颜色、图像位置、物品数量......
我的最少编码:
\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}
预先感谢
答案1
编辑:如果框 A\TextA
为空,此代码将排除框 A;如果框 B 不为空,此代码将排除框 B。\TextA
仍在等待有关如果和都\TextA
为\TextB
空该怎么办的指导。
\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}