我有一张用 \begin{figure} 在 \psmatrix 内创建的图像。
我怎样才能将 6 张相似的图片放在一个 2 x 3 的矩阵中?类似于
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{pstricks}%[pdf]
\usepackage{pst-node}
\usepackage{pst-blur}
\newpsobject{cnodeblue}{cnode}{fillstyle=solid,fillcolor=blue}
\newpsobject{cnodepink}{cnode}{fillstyle=solid,fillcolor=pink}
\newpsobject{cnodegreen}{cnode}{fillstyle=solid,fillcolor=green}
\newpsobject{psframegray}{psframe}{fillcolor=lightgray,linestyle=none,shadow,blur}
\pagestyle{empty}
\begin{document}
\begin{figure}[h!]
\centering
\resizebox{3cm}{!}{ % if you want to resize
\psset{framearc=0.2, shadowcolor=black!70, shadowangle=-90, unit=1.0cm}
\def\pscolhookii{\hskip 2cm}
\begin{psmatrix}[rowsep=1.9, colsep=2.9]% defines the distance between two frames
%
&
[name =Vecino1]
\psframegray(.00,.00)(3.5,1.7)
\pspolygon(0.5,0.2)(0.5,1.2)(2.3,1.2)(2.3,0.2)
\rput[t](2.3,-.15){Vecino 1}
\\ %[0.88cm]
&
[name =Vecino2]
\psframegray(.00,.00)(3.5,1.7)
\pspolygon(0.5,0.2)(0.5,1.2)(2.3,1.2)(2.3,0.2)
\rput[t](2.3,-.15){Vecino 2}
\\
%
[name =SA]
\psframegray(.00,.00)(3.5,1.7)
\pspolygon(0.5,0.2)(0.5,1.2)(2.3,1.2)(2.3,0.2)
\rput[t](2.3,-.15){Solución Actual}
&
[name =Vecino3]
\psframegray(.00,.00)(3.5,1.7)
\pspolygon(0.5,0.2)(0.5,1.2)(2.3,1.2)(2.3,0.2)
\rput[t](2.3,-.15){Vecino 3}
%
\end{psmatrix}
%%% Links
\psset{linewidth=3pt, linecolor=red, arrows=->, nodesep=4pt, linearc=0.25, angleB=180, shortput=nab, npos = 0.4}
\ncline[nodesepA = 2.0cm,nodesepB=0.5]{SA}{Vecino1}%
\ncline[nodesepA = 3.0cm,nodesepB=0.5]{SA}{Vecino2}%
\ncline[nodesepA = 3.7cm,nodesepB=0.5]{SA}{Vecino3}%
}\\[0.5cm]
%\vspace{2.85cm}
\caption{Forma 1 de Generar Vecinos}\label{Forma1GenerarVecinos}
\end{figure}
\end{document}
答案1
我更喜欢将你的 pstricks 代码编译为独立代码,includegraphics
在主文件中使用,这样代码会更简洁。它必须使用 pdflatex 进行编译。
我为您的 fancyframes 引入了一个只有一个参数(文本)的一体化宏,以避免多次重复相同的代码,并在 函数中给出了尽可能多的长度参数unit
。这使得只需设置 即可轻松缩放。因此,缩放时需要手动调整的唯一参数是和unit=…
的值,并且代码更具可读性。nodepA
nodesepB
\documentclass[10pt,pdf]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{pstricks}%
\usepackage{pst-node, pst-eps}
\usepackage{pst-blur}
\newpsobject{cnodeblue}{cnode}{fillstyle=solid,fillcolor=blue}
\newpsobject{cnodepink}{cnode}{fillstyle=solid,fillcolor=pink}
\newpsobject{cnodegreen}{cnode}{fillstyle=solid,fillcolor=green}
\newpsobject{psframegray}{psframe}{fillcolor=lightgray,linestyle=none,shadow,blur}
\newcommand*\myfancyframe[1]{\psframegray(0.0,0.25)(3.5,1.95)
\pspolygon(0.5,0.575)(0.5,1.575)(2.3,1.575)(2.3,0.575)\rput[b](2.3,-0.5){#1}} %2.3,-0.05
\begin{document}
\footnotesize
\psset{framearc=0.2, shadowcolor=black!70, shadowangle=-90, unit=5mm}
\def\pscolhookii{\hskip 2\psunit}
\begin{psmatrix}[rowsep=2.1, colsep=2.9]% defines the distance between two frames
%
&
[name =Vecino1]
\myfancyframe{Vecino 1}
\\ %
&
[name =Vecino2]
\myfancyframe{{Vecino 2}}
\\
%
[name =SA]
\myfancyframe{Solución Actual}
&
[name =Vecino3]
\myfancyframe{Vecino 3}
%
%%% Links
\psset{linewidth=3pt, linecolor=red, arrows=->, nodesep=4pt, linearc=0.25, angleB=180, shortput=nab, npos = 0.4,nodesepB = 0.15}
\ncline[nodesepA = 2.2]{SA}{Vecino1}%
\ncline[nodesepA = 3.5]{SA}{Vecino2}%
\ncline[nodesepA = 3.7]{SA}{Vecino3}%
\end{psmatrix}%
\end{document}
对于主文件本身,我使用了floatrow
专门设计用于制作此类内容的包。您可以有一个图形矩阵(floatrow
环境,仅单个标题)或一个子图形矩阵(subfloatrow
环境,带有子标题和全局标题)。
\documentclass[a4paper, 11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin = 2.5cm, nomarginpar]{geometry}%
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{floatrow}
\captionsetup{font =footnotesize}
\captionsetup[sub]{font =scriptsize}
\setlength\intextsep{20pt}
\begin{document}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\begin{figure}[!ht]
\floatsetup{captionskip = 8pt}
\ffigbox{
\begin{subfloatrow}[3]
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S1$}\label{fig: wfs1}}%
%
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S2$}\label{fig: wfs2}}%
%
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S3$}\label{fig: wfs3}}%
\end{subfloatrow}%
\vspace{1\baselineskip}
\begin{subfloatrow}[3]
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S4$}\label{fig: wfs4}}%
%
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S5$}\label{fig: wfs5}}%
%
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S6$}\label{fig: wfs6}}%
\end{subfloatrow}}
{\caption{A $ 2 ×3 $ matrix of subfigures}\label{matrix}}
\end{figure}
Some more text some more text some more text some more text some more text some more text some more text some more text some more text some more text some more text.
\newpage
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\begin{figure}[!ht]
\begin{floatrow}[3]
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S1$}\label{fig: wfs1}}%
%
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S2$}\label{fig: wfs2}}%
%
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S3$}\label{fig: wfs3}}%
\end{floatrow}%
\vspace{1\baselineskip}
\begin{floatrow}[3]
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S4$}\label{fig: wfs4}}%
%
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S5$}\label{fig: wfs5}}%
%
\ffigbox{%
\includegraphics{genvecinosA}}%
{\caption{workflow $S6$}\label{fig: wfs6}}%
\end{floatrow}
\end{figure}
Some more text some more text some more text some more text some more text some more text some more text some more text some more text some more text some more text.
\end{document}
子图矩阵:
数字矩阵: