1

I wish to draw a horizontal line spanning the entire page. Previously I've been using the method in this answer, but I just found that it doesn't work properly on pages with asymmetric margins (say 2in on the left and 1in on the right, or vice versa).

I did come up with a method that works in all usual cases, but it is a little bit ugly:

\noindent\hspace*{-\paperwidth}\makebox[\linewidth]{\rule{4\paperwidth}{2pt}}

Do you have any suggestions?

Below is a MWE to play with.

\documentclass{article}
\usepackage[left=2in,right=1in]{geometry}
% \usepackage[left=1in,right=2in]{geometry}
% \usepackage[left=1in,right=1in]{geometry}

\begin{document}

\noindent\makebox[\linewidth]{\rule{\paperwidth}{2pt}} % \noindent\hspace*{-\paperwidth}\makebox[\linewidth]{\rule{4\paperwidth}{2pt}}

\end{document}

Jinwen
  • 8,518
  • have a look at the answer below --from --https://tex.stackexchange.com/questions/410689/i-need-to-draw-a-dotted-line-to-divide-a-page-ignoring-the-margin – js bibra Mar 11 '21 at 09:05

2 Answers2

2

This solution use TikZ. Remember to run it twice.

\documentclass[10pt,a4paper]{article}
\usepackage[left=2in, right=1in]{geometry}
\usepackage{lipsum}
\usepackage{tikz}
\begin{document}

\lipsum[1]

\begin{tikzpicture}[remember picture, overlay] \coordinate (baseline) at (0,{0.5\ht\strutbox-0.5\dp\strutbox}); \draw (current page.west |- baseline) -- (current page.east |- baseline); \end{tikzpicture}

\lipsum[1] \end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Thanks for this. May I ask what does {0.5\ht\strutbox-0.5\dp\strutbox} stand for? – Jinwen Mar 12 '21 at 05:03
  • That is the distance from the baseline to the center of a \strut. If you want the baseline, just use (0,0). – John Kormylo Mar 12 '21 at 14:22
  • I like this answer, since TikZ brings a lot features such as stylish dashed lines. It is a pity that it requires a second run to correctly locate the line. – Jinwen Mar 12 '21 at 14:29
  • [remember picture] stores the local origin in the aux file (which is the only way to get absolute locations). The second run is needed to read this value. – John Kormylo Mar 12 '21 at 14:49
0

enter image description here

\documentclass[10pt,a4paper]{article}

\usepackage[left=2in, right=1in]{geometry} \usepackage{lipsum} \begin{document}

\newcommand{\dividepage}{%
    \par\noindent
    \makebox[\linewidth]{\raisebox{.2\baselineskip}{\makebox[2\paperwidth]{\hrulefill}}}%
    \par
}

    \lipsum[1]

    \dividepage

    \lipsum[1]

\end{document}

js bibra
  • 21,280