9

Consider the MWE below:

\documentclass{article}
\usepackage[vmargin=3cm]{geometry}
\usepackage{l3draw}
\usepackage{lipsum}
\ExplSyntaxOn

% Define color for notepad rules
\color_set:nnn {notepadrulecolor} { RGB } { 217, 244, 244 }

% Command to draw the notepad background
\cs_new_protected:Nn \draw_notepad_background:
{
  \draw_begin:
    \draw_linewidth:n { 1pt }
    \color_select:n { notepadrulecolor }
    \draw_path_moveto:n { 2cm, 2cm }
    \draw_path_lineto:n { 2cm , 27cm } 
    \draw_path_use_clear:n { stroke }
    
  \draw_end:
}

% Hook to draw background on every page
\AddToHook{shipout/background}
{
  \draw_notepad_background:
}

\ExplSyntaxOff

\begin{document}

\lipsum[1-14]

\end{document}

What I am currently trying to achieve is to draw a vertical line that spans the height of the page and is on the left margin of the text area. I know this can be done via TikZ but am trying to recreate it with l3draw. Any assistance would be appreciated.

2
  • 2
    off-topic: you shouldn't use the draw prefix for a custom macro as it is reserved for the l3draw module.
    – cfr
    Commented yesterday
  • @cfr Duly noted.
    – azetina
    Commented yesterday

2 Answers 2

9

You need to set the bounding box of the drawing to zero and then either shift it to the right position on the page or change the y values to negative (because positive values depict upwards and the drawing box will sit in the upper left corner of the page).

I changed the color to enhance the visibility of the line, feel free to revert:

\documentclass{article}
\usepackage[vmargin=3cm]{geometry}
\usepackage{l3draw}
\usepackage{lipsum}

\ExplSyntaxOn

% Define color for notepad rules
\color_set:nnn { notepadrulecolor } { RGB } { 0, 244, 244 }

% Command to draw the notepad background
\cs_new_protected:Nn \azetina_notepad_draw_background:
{
  \draw_begin:
    \bool_set_false:N \l_draw_bb_update_bool
    \draw_linewidth:n { 1pt }
    \color_select:n { notepadrulecolor }
    \draw_path_moveto:n { 2cm, -2cm }
    \draw_path_lineto:n { 2cm , -27cm } 
    \draw_path_use_clear:n { stroke }
  \draw_end:
}

% Hook to draw background on every page
\AddToHook{shipout/background}
{
  \azetina_notepad_draw_background:
}

\ExplSyntaxOff

\begin{document}

\lipsum[1-14]

\end{document}

Alternatively, use \draw_transform_shift:n { 0pt , -\paperheight } and keep the positive y values.

first page of the output of above code

7

Since Jasper Habicht already provided an l3draw answer, here's a simpler approach which avoids the need for any additional package.

The shipout/background hook puts the specified code into a picture environment. Hence, for simple drawings, there is no need to use either tikz or l3draw. Instead, we can just use picture mode itself.

\put (2cm,\dimexpr 2cm-\paperheight) 
  {\color_select:n {notepadrulecolor} \line(0,1){27cm}}
  • \put(<x>,<y>){<stuff>} is a picture-mode macro which typesets <stuff> at <x>,<y> relative to the lower-left corner of the page. So \put (2cm, \dimexpr 2cm-\paperheight) {...} puts {...} 2cm to the right and 2cm above the lower-left corner of the page.
  • \line(<x>,<y>){<dim>} draws a line of <dim> length in the direction of the vector specified by <x>,<y>. So \line(0,1){27cm} draws a vertical line from the current point of 27cm.

I couldn't see the line clearly, so I changed the colour for purposes of testing and demonstration.

marginal line

\documentclass{article}
\usepackage[vmargin=3cm]{geometry}
\usepackage{lipsum}
\ExplSyntaxOn

% Define color for notepad rules
% \color_set:nnn {notepadrulecolor} { RGB } { 217, 244, 244 }
\color_set:nnn {notepadrulecolor} { RGB } { 150, 200, 200 }

% Hook to draw background on every page
\AddToHook{shipout/background}
{
  \put (2cm,\dimexpr 2cm-\paperheight) 
  {\color_select:n {notepadrulecolor} \line(0,1){27cm}}
}

\ExplSyntaxOff

\begin{document}
\lipsum[1-14]
\end{document}
2
  • 4
    David trained you well. Commented yesterday
  • 1
    @UlrikeFischer >^.^<
    – cfr
    Commented yesterday

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.