1

I have an article in TeX, The following image describes what I want to achieve!

I know how TeX works "Normally" on graphics, but really this is what I want.

Thanks. enter image description here

Qaher
  • 1,242
  • 2
    This is something I really wouldn't try to achieve. – AlexG Jan 30 '15 at 09:14
  • Question related. It says "Unfortunately this doesn't work. Picture environments (picture, tikzpicture, ...) are (horizontal) boxes on there own and LaTeX doesn't break these. I would need to do this by yourself." In that case, you have to split your image by yourself… – Clément Jan 30 '15 at 09:24
  • Just cut the image into two using any image editor then include it as two separate images. – David Carlisle Jan 30 '15 at 09:31
  • @DavidCarlisle I need it to be automatically. – Qaher Jan 30 '15 at 09:47
  • 1
    @Gahir you can't really do that automatically in general, TeX has not decided the page breaks at the point the \includegraphics happens, and by the time it does decide the page breaks it can not split the image. It's like asking to break the page in the middle of an X – David Carlisle Jan 30 '15 at 09:54
  • @DavidCarlisle but I really need this to be done! I don't know, maybe some scripts, or something other than manually doing it. – Qaher Jan 30 '15 at 10:04
  • 1
    Actually, I want something maybe similar to ‎\allowdisplaybreaks‎, but for graphics instead of equations! – Qaher Jan 30 '15 at 10:15
  • \allowdisplaybreaks does not allow you to break in the middle of a \sum sign or other unbreakable thing, a display is a series of rows with a natural break point between them, normally amsmath explicitly prevents breaking at that point and \allowdisplaybreaks just tells it not to do that. An image is completely different, it is like a letter: tex has absolutely no knowledge about its internal structure. – David Carlisle Jan 30 '15 at 10:56
  • but what is "this" that you want to do? always split it in half? or would you split of a strip 1mm high if that is what it takes to fill the first page then have a 1mm high image at the top of the second page or... – David Carlisle Jan 30 '15 at 10:58
  • @DavidCarlisle I want the image to flow through pages, as it would in text; like the picture above. (It first occupies the remaining space in the page and flows the remaining part of the image to the next page - As simple as this!) – Qaher Jan 30 '15 at 11:27
  • @Gahir that is not simple at all it is totally against the way TeX works. You can make an approximation by looking at \pagetotal as in the posted answer but it does not really have the right information (it has little information about floats for example as they are added to the page later – David Carlisle Jan 30 '15 at 12:50

1 Answers1

4
\documentclass{article}
\usepackage{graphicx,lipsum}
%--------------------------------------------------
\newsavebox\mtbox
\newcommand{\mtgraphics}[1]{%
\sbox\mtbox{\includegraphics{#1}}%
\null%
\dimen255=\dimexpr\pagegoal-\pagetotal-\baselineskip\relax%
\ifdim\dimen255>\ht\mtbox
  \usebox\mtbox
\else
\dimen254=\dimen255%
\dimen255=\dimexpr\ht\mtbox-\dimen254\relax%
  \includegraphics[trim=0mm 1.\dimen255 0mm 0mm, clip=true]{#1}
  \par
  \includegraphics[trim=0mm 0mm 0mm \dimen254, clip=true]{#1}
\fi}
%--------------------------------------------------
\begin{document}

\lipsum[1-5]

\mtgraphics{myfoto}

\end{document}
touhami
  • 19,520
  • I can confirm it works (screenshot). Nice ! – Clément Jan 30 '15 at 12:27
  • @touhami Thanks, it does work! but if you replace \lipsum command with normal text, the image flies to next page. (I mean how should I change my text to make it behave like \lipsum[1-5]?) – Qaher Jan 30 '15 at 12:44
  • 1
    it isn't really safe to use dimen254 as a scratch register, better to use 0 and 2, or do it inside a group but yes, although this can never be reliable (\pagetotal is not accurate at the time you need to look) it is probably the best that can be done for the OPs requirement – David Carlisle Jan 30 '15 at 12:53
  • @DavidCarlisle Thank you very much for your useful contribution. – Qaher Jan 30 '15 at 14:58
  • @DavidCarlisle The trick does not work for minipage environment at all! What should I do in this case? – Qaher Jan 31 '15 at 08:32
  • @Gahir the whole point about a minipage environment is that it is a box that is guaranteed not to split. So the issue should not arise in a minipage. – David Carlisle Jan 31 '15 at 08:52