To add a border around each page in your Overleaf document, you can use either the fancybox package for a simple solution or the tikz package for more customization. Here are two methods:
Method 1: Using fancybox (Simple)
Add this to your preamble:
\usepackage{fancybox}
\AtBeginDocument{\pagestyle{plain}\setlength{\fboxrule}{2pt}\setlength{\fboxsep}{0pt}}
\AddToHook{shipout/background}{\put(0,0){\fbox{\phantom{\rule{\paperwidth}{\paperheight}}}}}
Explanation:
\setlength{\fboxrule}{2pt} sets border thickness (adjust as needed).
\setlength{\fboxsep}{0pt} removes padding between border and page edge.
- The border will appear on every page automatically.
Method 2: Using tikz (Customizable)
Add this to your preamble:
\usepackage{tikz,eso-pic}
\AddToShipoutPictureBG{%
\begin{tikzpicture}[remember picture, overlay]
\draw[line width=2pt] % Adjust thickness and color
(current page.north west) ++(1cm,-1cm) -- % Top-left margin
(current page.north east) ++(-1cm,-1cm) -- % Top-right margin
(current page.south east) ++(-1cm,1cm) -- % Bottom-right margin
(current page.south west) ++(1cm,1cm) -- cycle; % Bottom-left
\end{tikzpicture}
}
Customization:
- Thickness: Change
line width=2pt (e.g., 1pt for thinner).
- Color: Add
red (e.g., \draw[line width=2pt, red]).
- Margins: Adjust
1cm values to control border distance from page edges.
Important Notes:
- Place Code Correctly: Both snippets go in the preamble (before
\begin{document}).
- Geometry Conflicts: If using
geometry, ensure border margins (e.g., 1cm) are smaller than your page margins.
- Header/Footer: Borders appear behind text/headers. Use
\AddToShipoutPictureFG instead of BG for foreground placement (may cover content).
- Dashed Borders (Optional):
Replace \draw[line width=2pt] with:
\draw[line width=1pt, dash pattern=on 4pt off 4pt] % Dashed style
Choose the method that best fits your needs. The tikz method offers more flexibility for styling.