2

I am looking to create a box outside page margin with some text in it. Is there any way to manually position the box. I want desire output as follows:

enter image description here

ZEESHAN
  • 247
  • 1
    Welcome to TeX.SE!!! – manooooh May 22 '19 at 05:29
  • 2
    Yes, there is, but we need more information. What is the number inside the box? The page? The chapter? Something fixed? Which documentclass are you using? Could you please add a minimal but compilable example of what you tried so far? – CarLaTeX May 22 '19 at 06:02
  • It is a page number, I'm using \documentclass{article} – ZEESHAN May 22 '19 at 13:07
  • I'm fond of everypage and tikzpagenodes. See https://tex.stackexchange.com/questions/384008/margins-around-tikz-frame/384023?r=SearchResults&s=1|64.5190#384023 for example. – John Kormylo May 22 '19 at 13:38
  • \marginpar is the simple method... – MadyYuvi May 23 '19 at 13:03

2 Answers2

3

The OP does not make it clear if the box is set relative to the paper dimensions, or relative to some nearby text. So, here, I show both approaches:

  1. With \atxy, it is specified (for this page only) relative to the upper left paper dimension. (based on my answer at What are the ways to position things absolutely on the page?)

  2. With \marginpar, it is specified relative to nearby text.

If it is desired to use option 1 on every page, just change \AddThisPageHook to \AddEveryPageHook in the definition of \atxy.

\documentclass{article}
\usepackage{everypage}
\usepackage{xcolor}
\usepackage{lipsum}
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\newcommand\atxy[3]{%
 \AddThispageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{\textcolor{red}{#3}}}}}
% VERIFIED THAT SETTING \hoffset AND \voffset DO NOT BREAK SOLUTION.
%\hoffset=0.4in
%\voffset=0.2in
\begin{document}
\atxy{6.77in}{2in}{\fbox{\textcolor{black}{\thepage}}}
\lipsum[1]
Now here it is relative to this paragraph.%
  \marginpar{\color{red}\fbox{\textcolor{black}{\thepage}}}
\lipsum[1]
\end{document}

enter image description here

2

There are packages for assorted fancy page layout effects but you can always place any box anywhere by hiding its width, for example in a zero-sized picture environemnt.

enter image description here

\documentclass{article}


\makeatletter
\renewcommand\@oddhead{\hfill\begin{picture}(0,0)\put(10,-50){\fbox{\thepage}}\end{picture}}
\makeatother
\def\zz{One two three four five. }
\def\zzz{\zz\zz\zz\zz\zz Red yellow blue green black white. \stepcounter{enumi}\roman{enumi}: \zz}

\begin{document}

\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz
\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz

\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz
\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz\zzz

\end{document}
David Carlisle
  • 757,742