# How to place a “floating text box” at a specified location in page coordinates

I am looking for a way to have a command in LaTeX with an interface as follows:

\placetextbox{x_in_page_percentage, y_in_page_percentage}{This is my text}


The command would place the text This is my text centered within a box that may overlap with anything else on the page, and that would be placed at the coordinates specified by the variables x_in_page_percentage and y_in_page_percentage. These variables control the location of the x in the diagram below. E.g.

-------------x---------------
This is my text
-----------------------------


This way, something like \placetextbox{0.5, 0.5}{This is my text} would place the text roughly on the center of the page, regardless of anything else that may be on that location.

Any thoughts how to do this?

• The title of your question is confusing. Normally, when discussing LaTeX, a "floating" object does not overlap any other visible objects in the document. What makes it a "floating" is that its location in the output document is not exactly the location in the source code. e.g. you embed an image file. In your source code, you have some text before the image embed and some text after the image embed If latex put the picture exactly where your embed code was, then half of the picture might be on one page, and half on another page. As such, LaTeXwill "float" the picture somewhere else. – IdleCustard Jan 11 at 3:11

The eso-pic package allows you to add pictures (and text) to pages as an overlay/in the foreground [as an underlay/in the background]. The specific command used to add content to the current page is \AddToShipoutPictureFG* [\AddToShipoutPictureBG*]. The starred * versions of these commands limit the output to the current page, while the unstarred versions ship its contents out to every page.

The following minimal example illustrates the technique used to answer your question in the form of a macro \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{lipsum}% For 'Lorem Ipsum' dummy text
\usepackage[pscoord]{eso-pic}% The zero point of the coordinate systemis the lower left corner of the page (the default).

\newcommand{\placetextbox}[3]{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}
\setbox0=\hbox{#3}% Put <stuff> in a box
\put(\LenToUnit{#1\paperwidth},\LenToUnit{#2\paperheight}){\vtop{{\null}\makebox[0pt][c]{#3}}}%
}%
}%

\begin{document}
\lipsum[1-5]%
\placetextbox{0.5}{0.5}{\fbox{\Huge\textsf{This is my text.}}}%
\placetextbox{0.5}{1}{\Huge\texttt{Here is another piece of text.}}%
\placetextbox{0.1}{0.1}{\Large $\mathcal{A}_1$}%
\end{document}


Other packages are also capable of doing this, including background and tikz.

• Thanks @Werner. I get the following error with eso_pic: "Option clash for package eso-pic". Before that, I get a warning that says "You have requested the package ;eso-pic', but the package provides 'everyshi'" Any thoughts why I get this? – Amelio Vazquez-Reina Aug 2 '11 at 19:42
• Are you compiling the minimal example provided above? – Werner Aug 2 '11 at 19:51
• @KarelBílek: Perhaps you could ask fresh one using the "Ask Question" link above. Follow-up questions like this are more than welcome! Please also include a link to this question to provide the background. Merely stating "it doesn't work for me" doesn't provide any detail on the reasons, or perhaps other packages that you're loading. – Werner Jun 5 '12 at 23:36
• @Cookie: You can use \AddToShipoutPictureFG*{\put(\LenToUnit{#1\paperwidth},\LenToUnit{#2\paperheight}){\makebox[0pt][c]{\begin{tabular}{l}#3\end{tabular}}}}. I just placed a tabular around the #3 argument. This allows you to use \\ to break a line wherever you want. The alignment will be left, but you can change that to whatever you want. – Werner Dec 7 '17 at 16:13
• @FabianYing: Instead of \makebox[0pt][c]{#3}, you can use \parbox{<width>}{#3} where <width> is something you specify... like \textwidth. If you want it centred, use \parbox{\textwidth}{\centering #3}. – Werner Sep 23 '18 at 2:38