如果某个文件夹中存在图片,则插入文本

如果某个文件夹中存在图片,则插入文本

我的代码如下

\documentclass[ngerman,german,14pt,twoside,openany]{scrbook} %Bei Hochformat [oneside] zusätzlich eintragen und linker Rand 3cm, 2 Spalten und 6cm Bildhöhe
\usepackage[left=2.5cm,right=2.5cm,top=2cm,bottom=2.5cm]{geometry}
%\usepackage[cam,width=216truemm,height=303truemm,center]{crop} %Beschnittzugabe; https://komascript.de/node/786
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{rotating, graphicx}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{tikz-timing}
\usepackage{pgffor} % \foreach


\begin{document}


This is just text as part of a test... This is just text as part of a test...This is just text as part of a test... This is just text as part of a test...

\begin{center}
   \foreach \s in {1,...,1000}{%
   \IfFileExists{D:/folder1/folder2/pupil\s.jpg}%
 {\begin{tikzpicture}%
  \def\ig{%
   \includegraphics[width=.48\textwidth,keepaspectratio]{D:/folder1/folder2/pupil\s.jpg}}%
 \node [inner sep=0pt](mypicture) at (0,0) {\phantom{\ig}};%
 \clip[rounded corners=4mm] ($(mypicture.south west)+(1mm,1mm)$) rectangle ($(mypicture.north east)-(1mm,1mm)$);%
 \node[inner sep=0pt](mypicture) at (0,0) {\ig};%
\end{tikzpicture}
\vspace{2mm}
}}
\end{center}

\end{document} 

这是我的问题:我正在为学校写一份报告。在这份报告中,大约 50 名学生将收到一份带有一些照片的文本。是否可以修改我的代码,使文本仅在图片“文件夹 2”包含图片时出现,否则不应出现任何文本。如何做到这一点?非常感谢任何帮助!谢谢!

答案1

s=1您可以将前导文本移到由和保护的循环中,\IfFileExists这样它只会在循环迭代时出现一次,如果没有文件则不会出现。

\documentclass[ngerman,german,14pt,twoside,openany]{scrbook} %Bei Hochformat [oneside] zusätzlich eintragen und linker Rand 3cm, 2 Spalten und 6cm Bildhöhe
\usepackage[left=2.5cm,right=2.5cm,top=2cm,bottom=2.5cm]{geometry}
%\usepackage[cam,width=216truemm,height=303truemm,center]{crop} %Beschnittzugabe; https://komascript.de/node/786
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{rotating, graphicx}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{tikz-timing}
\usepackage{pgffor} % \foreach


\begin{document}


\begin{center}
  \foreach \s in {1,...,10}{%


   \IfFileExists{D:/folder1/folder2/pupil\s.jpg}%
   {%
    \ifnum\s=1   
\parbox{\textwidth}{This is just text as part of a test... This is just text as part of a test...This is just text as part of a test... This is just text as part of a test...}
\fi
\begin{tikzpicture}%
  \def\ig{%
   \includegraphics[width=.48\textwidth,keepaspectratio]{D:/folder1/folder2/pupil\s.jpg}}%
 \node [inner sep=0pt](mypicture) at (0,0) {\phantom{\ig}};%
 \clip[rounded corners=4mm] ($(mypicture.south west)+(1mm,1mm)$) rectangle ($(mypicture.north east)-(1mm,1mm)$);%
 \node[inner sep=0pt](mypicture) at (0,0) {\ig};%
\end{tikzpicture}
\vspace{2mm}
}}
\end{center}

\end{document} 

答案2

使用当前的 Texlive 或 miktex,您可以使用l3sys-query包(核心 latextools包的一部分),然后使用

\QueryFilesTF{*.jpg}{\node....\includegraphics{#1}}{}{No Files found}

相关内容