7

I have large figures (PNG images) in my document that are very thin but block an entire page due to their length. Is there a package available that cuts those in half, and positions those halves next to each other as one figure?

  • Did you consider using imagemagick, you could batch the process and obtain the desired figures and insert them. – Dror Sep 6 '12 at 8:11
  • of course, using an external tool would also accomplish this. However, I'd like to use a more LaTeX-ish way of doing it. So that I only have to rebuild my document when changing the picture instead of 1) change picture 2) use tool to split 3) build pdf – Chris Sep 6 '12 at 9:02
7

This can be quite easily done using Martin Scharrer's excellent adjustbox package:

\documentclass{article}
\usepackage{adjustbox}

\newcommand{\splitimage}[1]{%
  \adjustimage{trim=0 0.5\height{} 0 0, clip=true}{#1}%
  \adjustimage{trim=0 0 0 0.5\height{}, clip=true}{#1}%
}

\begin{document}
\splitimage{bottle}
\end{document}

Or using just the graphicx functionality:

\documentclass{article}
\usepackage{graphicx}

\newcommand{\splitimage}[1]{%
  \newlength{\imageheight}%
  \settoheight{\imageheight}{\includegraphics{#1}}%
  \includegraphics[trim=0 0.5\imageheight{} 0 0, clip=true]{#1}%
  \includegraphics[trim=0 0 0 0.5\imageheight{}, clip=true]{#1}%
}

\begin{document}
\splitimage{bottle}

\end{document}

Image taken from Wikimedia Comons: https://commons.wikimedia.org/wiki/File:Normflasche-1.jpg

| improve this answer | |
3

you can clip anything of the image:

\documentclass{article}
\usepackage{graphicx,multido}
\newlength\Iwidth\newlength\Iheight\newsavebox\IBox
\savebox\IBox{\includegraphics{Normflasche}}
\setlength\Iwidth{\wd\IBox} \setlength\Iheight{\ht\IBox}

\begin{document}

\noindent
\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[%
       viewport={\rx\Iwidth} {\ry\Iheight} {\rX\Iwidth}  \rY\Iheight,clip,scale=0.5]{Normflasche}}} \\[2pt]%                                                                                                             
}                                                                                                                         

\end{document}

enter image description here

| improve this answer | |
2

In ConTeXt you can use the \clip command. With \setupclipping you can select what to clip. Here I selected to clip into five slices on the vertical axis. With the x=… and y=… setting you specify which slice you want to retrieve.

\setupclipping
  [nx=1, ny=5]

\starttext

\dorecurse{5}{
  \clip[y=\recurselevel]{\externalfigure[hacker]}\blank}

\stoptext

result:

result

| improve this answer | |
2

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\usepackage{graphicx}

\def\Columns{5}% columns
\def\Rows{5}% rows
\def\Filename{ParisHilton}
\def\Scale{1}

\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=\Scale]{\Filename}}


\psset
{
    xunit=\dimexpr\wd\IBox/\Columns\relax,
    yunit=\dimexpr\ht\IBox/\Rows\relax,
}

\SpecialCoor
\begin{document}

\multido{\ny=\Rows+-1}{\Rows}
{
    \multido{\nx=0+1}{\Columns}
    {
        \pspicture(\Columns,\Rows)
            \psclip{\psframe[linestyle=none,linewidth=0pt](!\nx\space \ny\space 1 sub)(!\nx\space 1 add \ny)}
                \rput[bl](0,0){\usebox\IBox}
            \endpsclip
        \endpspicture
    }
}

\end{document}

Here is the picture that I used in this answer as a demo picture.

| improve this answer | |
  • 1
    Please focus on the code rather than on the sample picture. – kiss my armpit Sep 6 '12 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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