Fotografías de pasaporte usando cambio de tamaño

Fotografías de pasaporte usando cambio de tamaño
\documentclass{article}
\usepackage{graphicx}
\usepackage{calc}
\usepackage{ifthen}
\newlength{\oH}
\newlength{\oW}
\newlength{\rH}
\newlength{\cH}
\newcommand\PrintImage[3]{% width, height, image
  \settototalheight{\oH}{\includegraphics{#3}}%
  \settowidth{\oW}{\includegraphics{#3}}%
  \setlength{\rH}{\oH * \ratio{#1}{\oW}}
  \ifthenelse{\lengthtest{\rH < #2}}{
    \includegraphics[width=#1]{#3}%
  }{%
    \setlength{\cH}{(\rH-#2)*\ratio{\oW}{#1}}%
    \includegraphics[width=#1,clip,trim=0 \cH{} 0 0]{#3}%
  }%
}

\begin{document}
\PrintImage{6cm}{2cm}{yourimage}
\end{document}

Con este código puede crear una fotografía de pasaporte de 2x2 pulgadas. Si se utiliza papel A4, ¿cómo podemos organizar la fotografía en columnas para que se puedan generar varias fotografías de pasaporte en una página y no se desperdicie papel fotográfico? Sólo por curiosidad y diversión.

Respuesta1

¿Qué tal si utilizamos una tabla environment, el orden preciso depende del tamaño del papel fotográfico?

\documentclass{article}
\usepackage[a4paper,lmargin=0.5cm,rmargin=0.5cm,tmargin=0.2cm,bmargin=0.2cm]{geometry}
\usepackage[demo]{graphicx}
\usepackage{calc}
\usepackage{ifthen}
\newlength{\oH}
\newlength{\oW}
\newlength{\rH}
\newlength{\cH}
\newcommand\PrintImage[3]{% width, height, image
  \settototalheight{\oH}{\includegraphics{#3}}%
  \settowidth{\oW}{\includegraphics{#3}}%
  \setlength{\rH}{\oH * \ratio{#1}{\oW}}
  \ifthenelse{\lengthtest{\rH < #2}}{
    \includegraphics[width=#1]{#3}%
  }{%
    \setlength{\cH}{(\rH-#2)*\ratio{\oW}{#1}}%
    \includegraphics[width=#1,clip,trim=0 \cH{} 0 0]{#3}%
  }%
}

\newlength{\extraspaceforcutting}
\setlength{\extraspaceforcutting}{0.2ex}
\begin{document}
\begin{tabular}{*{3}{@{}c@{}}}
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting] 
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\end{tabular}
\end{document}

ingrese la descripción de la imagen aquí

Versión con bucle

\documentclass{article}
\usepackage[a4paper,lmargin=0.5cm,rmargin=0.5cm,tmargin=0.2cm,bmargin=0.2cm]{geometry}
\usepackage{forloop}%
\usepackage{etoolbox}%
\usepackage[demo]{graphicx}
\usepackage{calc}
\usepackage{ifthen}
\newlength{\oH}
\newlength{\oW}
\newlength{\rH}
\newlength{\cH}
\newcommand\PrintImage[3]{% width, height, image
  \settototalheight{\oH}{\includegraphics{#3}}%
  \settowidth{\oW}{\includegraphics{#3}}%
  \setlength{\rH}{\oH * \ratio{#1}{\oW}}
  \ifthenelse{\lengthtest{\rH < #2}}{
    \includegraphics[width=#1]{#3}%
  }{%
    \setlength{\cH}{(\rH-#2)*\ratio{\oW}{#1}}%
    \includegraphics[width=#1,clip,trim=0 \cH{} 0 0]{#3}%
  }%
}%

\newcounter{rowcounter}
\newcounter{columncounter}

\newcounter{maxcolumns}
\newcounter{maxrows}
\setcounter{maxcolumns}{3}
\setcounter{maxrows}{9}%
\newlength{\extraspaceforcutting}
\setlength{\extraspaceforcutting}{0.2ex}
\begin{document}
\begin{tabular}{*{\value{maxcolumns}}{@{}c@{}}}
  \forloop{rowcounter}{1}{\value{rowcounter} < \numexpr\value{maxrows}}{%
    \forloop{columncounter}{1}{\value{columncounter} < \numexpr\value{maxcolumns}+1}{%
      \PrintImage{6cm}{2cm}{yourimage} \ifnumless{\value{columncounter}}{3}{&}{}%
    }%
    \ifnumless{\value{rowcounter}}{\value{maxrows}-1}{\tabularnewline[\extraspaceforcutting]%
    }{} % no newline 
  }%
\end{tabular}
\end{document}

información relacionada