TeX - LaTeX Asked on May 29, 2021
I want something working like a fancyhdr, but on the page margin: A colored box overlayed with the document title (or any other text) on every page, placed vertically inside the page margin. The box should be placed on the outer margin (right on odd, left on even pages) and should be easily enabled/disabled (e.g. using fancy styles).
An example is the blue box to the left in the below image for an even page:
On an odd page, I would like to have the same box/text, but rotated 180 °:
My concrete example is a blue box, but a general solution that would allow graphics as well is also higly appreciated!
The comments to my question lead me to a lot of different answers. I compiled an MWE from them using eso-picture
:
documentclass{article}[a4paper]
usepackage{lipsum}
usepackage{tikz}
usepackage{ifthen}
usepackage{changepage}
strictpagecheck
usepackage{xcolor}
usepackage{eso-pic}
definecolor{MyBlue}{HTML}{0053A6}
newcommandColorMargin{%
checkoddpage
ifoddpage
put (1 cm,480){
begin{tikzpicture}
node[rotate=90, minimum height=1 cm, minimum width=10 cm, fill=MyBlue, text=white] at (0, 0) {bfserieslarge MY TEXT};
end{tikzpicture}}
else
put (paperwidth - 2 cm,480){
begin{tikzpicture}
node[rotate=270, minimum height=1 cm, minimum width=10 cm, fill=MyBlue, text=white] at (0, 0) {bfserieslarge MY TEXT};
end{tikzpicture}}
fi
}
AddToShipoutPicture{ColorMargin}
begin{document}
sloppylipsum[1-50]lipsum[1-50]
ClearShipoutPicture
lipsum[1-50]
end{document}
Answered by Dschoni on May 29, 2021
This uses AddToHook{shipout/background}
, which is relatively new and built into LaTeX.
Note that at shipout value{page}
is reliable. You only need things like changepage or ifoddpage when using floats or the last paragraph on a page (well, any paragraph that might wind up last).
documentclass[a4paper]{article}
usepackage{lipsum}
usepackage{tikz}
usepackage{xcolor}
definecolor{MyBlue}{HTML}{0053A6}
newcommandColorMargin{%
ifoddvalue{page}%
put (1 cm,-1cm){% relative to upper left corner
begin{tikzpicture}[baseline=(current bounding box.north)]
node[rotate=90, minimum height=1 cm, minimum width=10 cm, fill=MyBlue, text=white] at (0, 0) {bfserieslarge MY TEXT};
end{tikzpicture}}%
else
put (paperwidth - 2 cm,-1cm){%
begin{tikzpicture}[baseline=(current bounding box.north)]
node[rotate=270, minimum height=1 cm, minimum width=10 cm, fill=MyBlue, text=white] at (0, 0) {bfserieslarge MY TEXT};
end{tikzpicture}}%
fi
}
AddToHook{shipout/background}[myhook]{ColorMargin}
begin{document}
sloppylipsum[1-50]lipsum[1-50]
RemoveFromHook{shipout/background}[myhook]
lipsum[1-50]
end{document}
Answered by John Kormylo on May 29, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP