How can I insert a vertical line through a whole page to separate the text and the margin notes?
[Tex/LaTex] Inserting a line to separate the text and the margin note
marginnotemarginparmarginsrules
marginnotemarginparmarginsrules
How can I insert a vertical line through a whole page to separate the text and the margin notes?
Best Answer
The following code adds the rule only on pages with marginpars. If they appear on both sides (using a mix of
\reversemarginpar
and\normalmarginpar
) the rules show up on both sides.Customization possibilities are the rule itself (color, widths, etc) via
\mparrule
and the placement within the space given by\marginparsep
via\mparrulefactor
.Explanation: We patch
\@addmarginpar
to record if a marginpar is added to the left or to the right. Once one of the switches is set to to true it will remain so until we actually typeset the page (this way marginpars can be placed on either or both sides and we get the proper rules). The in\@outputpage
we simply use the switches to add a rule to the left and/or right of the\@outputbox
. By putting everything into an\hbox
the rule automatically extends to the full height of the box. Finally we reset both stwiches back to false so that a page without marginpars will not generate rules.As a result we get on the first page:
while page 3 shows rules on both sides:
A variation
As an alternative one could produce lines matching just the size of the marginals. Most of the previous code ideas could be reused only this time we do everything inside of
\@addmarginpar
:In that case we would get output like this: