如果某個資料夾中存在圖片,則插入文字

如果某個資料夾中存在圖片,則插入文字

我的程式碼如下

\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包(核心乳膠tools包的一部分),然後使用

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

相關內容