# Moving minipage on page to flush right with text

I would like to place a box on every page of my LaTeX document that does not interfere with the typesetting of the rest of the document, and found that the watermark packages are suitable for the task; e.g., xwatermark.

Specifically, I would like to insert a framed minipage such that its right border coincides with the right border of the text body.

Considering the LaTeX page layout, I tried

\documentclass{article}

\usepackage{lipsum}

\newlength\xshift
\setlength\xshift{0.5\paperwidth}
\addtolength\xshift{-1.0in} % half the minipage width

\usepackage{xcolor}
\usepackage[printwatermark]{xwatermark}
\newwatermark[
pages=1,
color=black,
scale=1,
xpos=\xshift,
ypos=0.0in
]{%
\fbox{%
\begin{minipage}{2.0in}\normalsize%
my awesome minipage\\
my awesome minipage\\
my awesome minipage
\end{minipage}%
}%
}

\begin{document}

\lipsum[1-4]

\end{document}


which results in

What might be the cause of the problem? Is there another package that is better suited?

• I haven't worked with the package you reference, but have great success with the backgrounds, eso-pic and tikzpagenodes packages - they might help you resolve this – cmhughes Jun 12 '14 at 19:11
• There is an gap of unknown width between the right margin and the edge of the page. To compute the location of the right edge of the text area, use 1in+\oddsidemargin+\textwidth. Then subtract 0.5/paperwidth+1in+\fboxsep+\fboxrule to get \xshift. – John Kormylo Jun 12 '14 at 20:05
• BTW, you can also use the tikzpagenodes package. – John Kormylo Jun 12 '14 at 20:33

You have to set \xshift like this

\setlength\xshift{\dimexpr0.5\paperwidth-\marginparwidth-\marginparsep-\oddsidemargin-1in\relax}


Full code:

\documentclass{article}

\usepackage{lipsum,showframe}

\newlength\xshift
\setlength\xshift{\dimexpr0.5\paperwidth-\marginparwidth-\marginparsep-\oddsidemargin-1in\relax}
%\addtolength\xshift{-1.0in} % half the minipage width

\usepackage{xcolor}
\usepackage[printwatermark]{xwatermark}
\newwatermark[
pages=1,
color=black,
scale=1,
xpos=\xshift,
ypos=0.0in
]{%
\fbox{%
\begin{minipage}{2.0in}\normalsize%
my awesome minipage\\
my awesome minipage\\
my awesome minipage
\end{minipage}%
}%
}

\begin{document}

\lipsum[1-4]

\end{document}


• Thanks, also for the hint about the showframe package! From en.wikibooks.org/wiki/LaTeX/Page_Layout, it seems that \oddsidemargin and \marginpar* overlap, and thus cannot be simply add up. Is that wrong? – Nico Schlömer Jun 13 '14 at 9:16

Tikz solution:

\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{lipsum}

\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node[draw=red,text=red,left] at (current page text area.east)
{\begin{minipage}{2in}
my awesome minipage\\
my awesome minipage\\
my awesome minipage
\end{minipage}};
\end{tikzpicture}

\lipsum[1-4]

\end{document}