2

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{-\marginparwidth}
\addtolength\xshift{-\marginparsep}
\addtolength\xshift{-1.0in} % half the minipage width
\addtolength\xshift{-1pt} % frame 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

wrong flushing

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

3
  • 1
    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, 2014 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. Jun 12, 2014 at 20:05
  • BTW, you can also use the tikzpagenodes package. Jun 12, 2014 at 20:33

2 Answers 2

1

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{-\marginparwidth}
%\addtolength\xshift{-\marginparsep}
%\addtolength\xshift{-1.0in} % half the minipage width
%\addtolength\xshift{-1pt} % frame 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}

enter image description here

1
1

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}

my awesome minipage

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .