2

I am typesetting novels in Latex and I would like to include a 'if you like this, why not try' section at the back.

Such sections are normally formatted like this:

enter image description here

With a nice grey border around the page, that indicates this section is differnet. It's normally visible from the side as well:

enter image description here

How can I achive this effect in Latex? (personally I'd be fine with doing it post-hoc in a pdf editor, but I don't know how to do that either)

1

2 Answers 2

2

Same result, but done at the package level, using tikz pagenodes, and setting the border command as the page header with fancyhdr, so you can add in other header material if you need to.

page border

Perhaps easier to maintain and modify, semantically speaking, depending on your coding style. Only two variables, colour and line width (with the "frame's" given x- and y-shift of 0).

I find no additional overhead loading tikz, so this solution may depend on your system constraints (if any).

MWE

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

\newcommand{\gborder}{\tikz[remember picture,overlay] 
    \draw [black!10!blue!20,line width=18mm]
    (current page.south west)
    rectangle
    (current page.north east)
    ;}

\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyhead[C]{\gborder}
\renewcommand{\headrule}{}

\begin{document}

\section{A}
\lipsum[1-10]
\section{B}
\lipsum[1-10]
\end{document}
3
  • Very strangly this MWE gives me: twitter.com/JoeReddington/status/1480938959320633350/photo/1 - is that my setup or did something accidently hit the MWE?
    – Joe
    Jan 11, 2022 at 16:26
  • Okay, I switched the 'north' and 'south' - and remembered to run it twice (possibly those two cancel each other out) and it's working perfectly. Thank you.
    – Joe
    Jan 11, 2022 at 16:34
  • 1
    Compiling twice (or more) is needed because the contents need to "settle" (e.g. table of contents is populated on second run, shifting page numbers, so a third run is needed to get the refreshed page numbering into the TOC), and then the tikz picture clicks into position. "North" and "South" are shorthand-code for "top centre of the page rectangle" and "Bottom centre of the page rectangle", so swapping them around will still draw a rectangular-frame border around the page edges. North east = top right corner, and so on.
    – Cicada
    Jan 12, 2022 at 3:57
3

LaTeX has hooks for every page (e.g. shipout/background). This one expect picture commands, eg \put the picture (0,0) is in the topleft corner, see texdoc ltshipout-doc. With this it is fairly simple to build fixed backgrounds, e.g.

\documentclass{article}

\usepackage{xcolor,kantlipsum}

\AddToHook{shipout/background}{%
  \linethickness{20pt}%
  \color{black!25}%
  \put(0,-10pt){\line(1,0){\paperwidth}}%
  \put(10pt,0){\line(0,-1){\paperheight}}%
  \put(0,-10pt){\line(1,0){\paperwidth}}%
  \put(\paperwidth-10pt,-\paperheight){\line(0,1){\paperheight}}%
  \put(\paperwidth,-\paperheight+10pt){\line(-1,0){\paperwidth}}%
  }

\begin{document}

\kant

\end{document}

enter image description here

2
  • Investigating - I'm running into a problem with \AddToHook - might be a problem with my setup...
    – Joe
    Jan 11, 2022 at 16:22
  • @Joe Hook management was added in 2020-10 to LaTeX if I remember correctly. If your LaTex is still older than the solution will not work. Jan 11, 2022 at 17:33

You must log in to answer this question.

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