我希望只显示空白,如果找不到图像,请不要显示图像路径。
我的最低限度的编码:
\RequirePackage{filecontents}
\begin{filecontents*}{file.tex}
No,TextA
1,Smile
2,No
3,
\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}
{%
\begin{tcbposter}[
poster = {
columns=1,
rows=1,
spacing=3mm,
height=14cm,
width=12cm,
},
]
%Box A
\posterbox[colframe=red,width=4.7cm,height=5.0cm]{name=A,column=1}{
\begin{enumerate}[leftmargin =-1em,rightmargin =-1em]
\item \includegraphics[width=3cm,height=3cm]{ImageA/\TextA.png} \hfill abc
\end{enumerate}
}
\end{tcbposter}
\newline
}
\end{document}
答案1
\includegraphics
该解决方案利用了和\adjustbox
(大部分)使用相同关键字的事实。
\RequirePackage{filecontents}
\begin{filecontents*}{file.tex}
No,TextA
1,Smile
2,No
3,
\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}
\usepackage{adjustbox}
\newcommand{\mygraphics}[2][\empty]% #1 = \includegraphics options, #2=pathname
{\IfFileExists{#2}{\includegraphics[#1]{#2}}{\adjustbox{#1}{\rule{1cm}{0pt}\rule{0pt}{1cm}}}}
\begin{document}
\DTLforeach*
{file}% Database
{\No=No,\TextA=TextA}
{%
\begin{tcbposter}[
poster = {
columns=1,
rows=1,
spacing=3mm,
height=14cm,
width=12cm,
},
]
%Box A
\posterbox[colframe=red,width=4.7cm,height=5.0cm]{name=A,column=1}{
\begin{enumerate}[leftmargin =-1em,rightmargin =-1em]
\item \mygraphics[width=3cm,height=3cm]{ImageA/\TextA.png} \hfill abc
\end{enumerate}
}
\end{tcbposter}
\newline
}
\end{document}