我的目標是自動化一個過程,其中我有許多來自電影序列的圖片,並且我希望它們按降序排版。為此,我的所有圖像都保存在一個資料夾中,當然,它們的名稱末尾帶有文件索引。我選擇了matrix
但是,只要它靈活(基於 3 個參數:總寬度;微型寬度;列數),任何製作的東西tikz
都會很棒。
% !TeX encoding = UTF-8
% !TeX spellcheck = fr_FR
\documentclass[11pt, frenchb, twoside]{report}
% IMPORTS
\usepackage{polyglossia}
\usepackage{xparse}
\usepackage{xifthen}
\usepackage{tikz}
\usetikzlibrary{backgrounds, patterns, shapes,
calc, positioning,
matrix, scopes,
decorations.fractals, decorations.text}
\newlength{\foolen}
\newlength{\barlen}
% GRIDFIGURES % % % % % % % % % % % % % % % %
% #1 total width [default: \textwidth]
% #2 total figures
% #3 total columns
% #4 gutter space
% #5 folder
% #6 label
\ProvideDocumentCommand \gridFigures{ O{\textwidth} m m m m m }
{%
\let\gridcontent\empty
\let\ea\expandafter%
\pgfmathsetlength{\foolen}{(#1/#3)-#4}
\pgfdeclareimage[width=\foolen]{ghost}{../assets/#5/#6-1}
\settoheight{\barlen}{\pgfuseimage{ghost}}
%
\foreach \i in {1,2,...,#2}
{%
\pgfmathparse{mod(\i,#3)}
\pgfmathtruncatemacro{\mod}{\pgfmathresult}
\ifthenelse{\mod>0}
{\ea\gappto\ea\gridcontent\ea{\ea{\i} \&}}
{\ea\gappto\ea\gridcontent\ea{something \ea{\i} \\}}}
\begin{tikzpicture}
\matrix[matrix of nodes, ampersand replacement=\&]{\gridcontent};
\end{tikzpicture}}
\begin{document}
\begin{figure}[ht]
\gridFigures{40}{5}{5mm}{mohr}{cubic-limit}
\end{figure}
\end{document}
因為目前,由於擴展問題,我無法用圖像編號填滿矩陣。若要\i
使用 中的檔案索引 ( )重新建置映像\foreach
,i
必須立即展開,\ea\gappto\ea\gridcontent\ea
否則將無法運作。我可能錯過了一些東西,因為這是我第一次真正開始理解什麼是擴展。
答案1
\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc, positioning, matrix, scopes}
\tikzset{nosep/.style={inner sep=0pt,outer sep=0pt}}
% GRIDFIGURES % % % % % % % % % % % % % % % %
% #1 total width [default: \textwidth]
% #2 macro for matrix content
% #3 total figures
% #4 total columns
% #5 gutter space
% #6 folder
% #7 label
\ExplSyntaxOn
\ProvideDocumentCommand \gridFigures{ O{\textwidth} m m m m m m }
{%
\tl_clear_new:N #2
\dim_new:N \l_width_dim
\pgfmathparse{#3-1}
\pgfmathtruncatemacro{\row}{\pgfmathresult}
\pgfmathsetlength{\l_width_dim}{(#1/#4)-#5}
\int_step_inline:nnnn {1}{#4}{\row}
{
\pgfmathparse{##1+#4-1}
\pgfmathtruncatemacro{\col}{\pgfmathresult}
\int_step_inline:nnnn {##1}{1}{\col}
{
\tl_put_right:Nn #2 {\includegraphics[width=\l_width_dim]{#6/#7-####1}}
\int_compare:nT {####1<\col}
{\tl_put_right:Nn #2 {\&}}
}
\tl_put_right:Nn #2 {\\}
}
}
\ExplSyntaxOff
\begin{document}
\gridFigures{\matrixContent}{40}{5}{2mm}{../assets/mohr}{cubic-limit}
\begin{tikzpicture}[nosep]
\matrix[matrix of nodes,ampersand replacement=\&,
column sep=2mm,row sep=2mm]{\matrixContent};
\end{tikzpicture}
\end{document}