Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to slice an image into 8 parts, i.e., 2 rows by 4 columns. Each part is on a single page as follows. The gray frame is the Acrobat Reader background, so don't think it is a part of the output I want to have.

enter image description here

\documentclass{minimal}
\usepackage[margin=2cm,a6paper]{geometry}
\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics{bald}}
\newdimen\width
\newdimen\height
\width=\wd\IBox
\height=\ht\IBox
\parindent=0bp
\usepackage{multido}
\begin{document}
\centering%
%first row
\fbox{\includegraphics[height=\textheight,viewport={0\width} {0.5\height} {0.25\width} {\height},clip]{bald}}
\fbox{\includegraphics[height=\textheight,viewport={0.25\width} {0.5\height} {0.5\width} {\height},clip]{bald}}
\fbox{\includegraphics[height=\textheight,viewport={0.5\width} {0.5\height} {0.75\width} {\height},clip]{bald}}
\fbox{\includegraphics[height=\textheight,viewport={0.75\width} {0.5\height} {\width} {\height},clip]{bald}}
%second row
\fbox{\includegraphics[height=\textheight,viewport={0\width} {0\height} {0.25\width} {0.5\height},clip]{bald}}
\fbox{\includegraphics[height=\textheight,viewport={0.25\width} {0\height} {0.5\width} {0.5\height},clip]{bald}}
\fbox{\includegraphics[height=\textheight,viewport={0.5\width} {0\height} {0.75\width} {0.5\height},clip]{bald}}
\fbox{\includegraphics[height=\textheight,viewport={0.75\width} {0\height} {\width} {0.5\height},clip]{bald}}
\end{document}

If you need the image to be sliced, here it is.

enter image description here

I have attempted to translate it using nested \multido macros as follows but it did work. I think it is because I have no enough knowledge in doing length manipulation in (La)TeX.

\documentclass{minimal}
\usepackage[margin=2cm,a6paper]{geometry}
\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics{bald}}
\newdimen\width
\newdimen\height
\width=\wd\IBox
\height=\ht\IBox
\parindent=0bp
\usepackage{multido}
\begin{document}
\centering
\multido{\nx=0+0.25}{4}
{%
    \multido{\ny=1+-0.5}{2}
    {%
        \fbox{\includegraphics[height=\textheight,viewport={\nx\width} {\ny\height-0.5\height} {\nx\width+0.25\width} {\ny\height},clip]{bald}}%
    }%
}
\end{document}
share|improve this question
    
See my answer to Breaking pictures across multiple pages where I do something very similar, just the cutting is done vertically not horizontally. –  Martin Scharrer Jul 12 '11 at 12:10
add comment

1 Answer 1

up vote 3 down vote accepted
\documentclass{minimal}
\usepackage[margin=2cm,a6paper]{geometry}
\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics{bald}}
\newdimen\width
\newdimen\height
\width=\wd\IBox
\height=\ht\IBox
\parindent=0bp
\usepackage{multido}
\begin{document}
\centering
\multido{\ry=0.5+-0.5, \rY=1.0+-0.5}{2}{%
  \multido{\rx=0.00+0.25, \rX=0.25+0.25}{4}{%
    \fbox{\includegraphics[%height=\textheight, makes no sense without width=...
       viewport={\rx\width} {\ry\height} {\rX\width} {\rY\height},clip]{bald}}%
    }\\%
}
\end{document}

enter image description here

share|improve this answer
    
height without width is used to keep the aspect ratio. –  xport Jul 12 '11 at 13:18
    
However, it makes no sense. Your paper dimensions are not proportional to the image dimensions –  Herbert Jul 12 '11 at 13:29
    
@xport: I know keepaspectratio do you? –  Martin Scharrer Jul 12 '11 at 13:54
    
@Herbert: This code can be compiled with neither xelatex nor xetex. –  xport Aug 3 '11 at 15:49
    
@xport: clipping is broken in the xtex driver of graphicx. –  Herbert Aug 3 '11 at 15:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.