4

The following will position an image at the specified page coordinates.

\documentclass{article}

\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage[absolute,overlay]{textpos}
\setlength{\TPHorizModule}{1mm}
\setlength{\TPVertModule}{1mm}

\begin{document}

\lipsum[1-3]
\begin{textblock}{20}(80,100)
\includegraphics{foo}
\end{textblock}

\end{document}

However, in this case, the image will be overlaid on top of the text. Not what I want. What I do want is something that looks more like what you get from this code.

\documentclass{article}

\usepackage{lipsum}
\usepackage[demo]{graphicx}

\begin{document}

\lipsum[1]

Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at,
tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy
pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa
ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Mae-
cenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum.
Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. Sed lacinia nulla
\begin{center}
\includegraphics{foo}
\end{center}
vitae enim. Pellentesque tincidunt purus vel magna. Integer non enim.
Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam cur-
sus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum
pellentesque felis eu massa.


\end{document}

In this case, the image does not overlay the text and instead the paragraph is split and a clearing is made to fit the image.

I would like to do something which produces this effect but do so using something more like what textpos does. In other words, I would to say to LaTeX to put an image at a particular position on the page but to produce a clearing around that image where no text is allowed.

  • 1
    Do you really mean at a particular position on the page (regardless of the surrounding text), or do you mean at a particular position in the text (as you've shown in your example)? You might find the wrapfig package useful. – Paul Gessler Jul 7 '14 at 21:37
  • 3
    what you ask is very hard in TeX (and not possible in general) consider for example if the page content is not just lipsum text but contains display math, or images or other unbreakable text so that it is not possible to split at the given position. page breaking happens asynchronously with macro expansion and line breaking. – David Carlisle Jul 7 '14 at 21:38
  • 2
    You might look at flowfram if you are sure you really want to do this. – cfr Jul 8 '14 at 3:03
1

This has so many restrictions and undocumented features I wouldn't know where to start listing them but it redefines b to position a float \middlefloatpos down the page, so long as the page has enough text that can be split at that point.

enter image description here

\documentclass{article}

\usepackage{lipsum}
\usepackage[demo]{graphicx}
\setcounter{bottomnumber}{1}% don't even think of setting this higher

\newlength\middlefloatpos
\setlength\middlefloatpos{4cm} % space above the inserted float

\makeatletter
\def \@cflb {%
    \let\@elt\@comflelt
    \setbox\@tempboxa \vbox{}%
    \@botlist
    \setbox\@outputbox \vbox{\vbadness\@M
\setbox\z@\vsplit\@outputbox to \middlefloatpos
                             \unvbox\z@
                             \vskip .5\textfloatsep plus \baselineskip
                             \unvbox\@tempboxa
                             \vskip .5\textfloatsep plus \baselineskip
                             \vskip -\floatsep
\unvbox\@outputbox
                             }%
    \let\@elt\relax
    \xdef\@freelist{\@freelist\@botlist}%
    \global \let \@botlist\@empty
}
\makeatother

\begin{document}

\lipsum[1]

\begin{figure}[!b]\centering
\includegraphics{foo}
\end{figure}
Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at,
tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy
pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa
ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Mae-
cenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum.
Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. Sed lacinia nulla
vitae enim. Pellentesque tincidunt purus vel magna. Integer non enim.
Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam cur-
sus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum
pellentesque felis eu massa.


\end{document}

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.