[Tex/LaTex] Put some text at a precise x, y position

boxestext;

I have a page which already has a very precise layout with many boxes: text, graphics (PNG), etc.

Without changing the current layout, and without changing anything that could impact the next pages, I'd like to add a textbox with a precise position, with something like:

\positiontextbox{3cm}{10cm}{Hello}    %  3 cm from left border of paper
                                      % 10 cm from top border of paper

This would be the LaTeX equivalent of HTML/CSS's #mytextbox { position: fixed; left: 20px; top: 100px; }.

How to do this in LaTeX ?

Best Answer

With the TikZ node current page.north west, it is possible to place some content precisely on a specified position relative to the upper left corner of the page.

\documentclass{article}
\usepackage[a4paper,lmargin=3cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{showframe}

\newcommand{\positiontextbox}[4][]{%
  \begin{tikzpicture}[remember picture,overlay]
%    \draw[step=0.5,gray!80!white] (current page.north west) grid (current page.south east); % For controlling
    \node[inner sep=10pt,right, fill=yellow,draw,line width=1pt,#1] at ($(current page.north west) + (#2,-#3)$) {#4};
  \end{tikzpicture}%
}

\usepackage{blindtext}

\begin{document}
\blindtext[2]

\positiontextbox{3cm}{10cm}{Hello}

\positiontextbox[fill=green]{14cm}{5cm}{Hello World}


\end{document}

enter image description here

The version with the requested circle (The line wrapping is from a very useful hint from Torbjørn T.)

\documentclass{article}
\usepackage[a4paper,lmargin=3cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{showframe}

\newcommand{\positiontextbox}[4][]{%
  \begin{tikzpicture}[remember picture,overlay]
%    \draw[step=0.5,gray!80!white] (current page.north west) grid (current page.south east); % For controlling
    \node[align=left,circle,inner sep=5pt,right, fill=white,draw,#1] at ($(current page.north west) + (#2,-#3)$) {#4};
  \end{tikzpicture}%
}

\usepackage{blindtext}

\begin{document}
\blindtext[2]

\positiontextbox{3cm}{10cm}{Hello}

\positiontextbox[fill=green]{14cm}{5cm}{Hello\\ World}
\end{document}

enter image description here