3

Following the topic to divide a page in two equal parts, I can't figure out how to draw a line at the quarter of the page. My goal is to create some multiple short tests on the same page that I'm able to easily cut (cf. image). They must have the same height.

Here is a starting point.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\tikz[overlay,remember picture]
    \draw (current page.west) -- (current page.east); %% <-- should draw a line at the end of the first quarter
    \draw (current page.west) -- (current page.east); %% <-- should draw a line at the end of the second quarter
    \draw (current page.west) -- (current page.east); %% <-- should draw a line at the end of the third quarter

\end{document}

In the most general case, how to let TikZ know I want the node at XX% of the page to draw several lines ? The anchors east/west are not enough.

Now, I'm drawing those lines with

\vfill
\hrule
\smallskip

and I try to manually keep the text with same height... which is not easy.

My personnal use is for exam class but article is more general and will be the same result in that case. enter image description here

6
  • 2
    Learn to use the calc library and the ($(A)!fraction!(B)$) syntax. So the left edge of a quarter from the top is ($(current page.south west)!0.75!(current page.north west)$).
    – daleif
    Sep 15, 2023 at 10:25
  • Please post complete examples people can compile.
    – cfr
    Sep 15, 2023 at 17:42
  • 1
    Do you want the space for the tests to be equal in height or the pieces of paper? If you divide the page equally, the central two will have more space for content because those areas don't include the header/footer space. Or are you using custom settings or a special class which minimises or eliminates those areas?
    – cfr
    Sep 15, 2023 at 17:46
  • @cfr The start of the code did not appear with the ´´´ starting code block at the same line. Corrected. I use exam class here but article give the same result in that case. I want, after cut on the lines, equal height for each parts. So directly at quarter of the, here, A4 paper. No bigger tests at center.
    – Piroooh
    Sep 18, 2023 at 7:55
  • But that's the point: if you divide the paper equally, you divide the space for the tests unequally unless you change the page layout.
    – cfr
    Sep 18, 2023 at 17:38

1 Answer 1

7

If you don't have to use TikZ, you could try shipout. They do not interfer with the text body and therefore can not be "pushed" up or down by adding some text or spacing commands:

\documentclass[a4paper]{article}

\AddToHook{shipout/background}[dashedlines]{%
  \put(0,-.25\paperheight){%
    \multiput(2,0)(5,0){120}{\line(1,0){2pt}}%
  }%
  \put(0,-.5\paperheight){%
    \multiput(2,0)(5,0){120}{\line(1,0){2pt}}%
  }%
  \put(0,-.75\paperheight){%
    \multiput(2,0)(5,0){120}{\line(1,0){2pt}}%
  }%
}%

\begin{document}
Test
\end{document}

... gives:

image divided by dashed lines

I used dashed lines which may be more appropriate as cutting marker. Straight lines are of course also possible.

The lines can be removed from a particular point on by inserting a RemoveFromHook{shipout/background}[dashedlines] command somewhere in the document.

Edit: Boxes for content

You could use some boxes to define the content of each quarter.

I set the margins of the whole document to 0pt using geometry package and then use the \fboxsep of each \colorbox as seperate box margin. The backgroundcolor of each box is only to illustrate the borders:

\documentclass[a4paper]{article}

\usepackage[margin=0pt]{geometry}
\usepackage{graphicx}
\usepackage{xcolor}

\usepackage{blindtext}
\setlength{\parindent}{0pt}
\setlength{\fboxsep}{1.5em}
\setlength{\parskip}{0pt}

\AddToHook{shipout/foreground}[dashedlines]{%
  \put(0,-.25\paperheight){%
    \multiput(2,0)(5,0){120}{\line(1,0){2pt}}%
  }%
  \put(0,-.5\paperheight){%
    \multiput(2,0)(5,0){120}{\line(1,0){2pt}}%
  }%
  \put(0,-.75\paperheight){%
    \multiput(2,0)(5,0){120}{\line(1,0){2pt}}%
  }%
}%

\begin{document}

\colorbox{gray!50}{
  \begin{minipage}[][\dimexpr.25\paperheight-2\fboxsep][t]{\dimexpr \paperwidth-2\fboxsep}
    \blindtext    
  \end{minipage}
}\par \nointerlineskip

\colorbox{gray!20}{
  \begin{minipage}[][\dimexpr.25\paperheight-2\fboxsep][t]{\dimexpr \paperwidth-2\fboxsep}
    \blindtext[2]   
  \end{minipage}
}\par \nointerlineskip

\colorbox{gray!50}{
  \begin{minipage}[][\dimexpr.25\paperheight-2\fboxsep][t]{\dimexpr \paperwidth-2\fboxsep}
    \blindtext    
  \end{minipage}
}\par \nointerlineskip

\colorbox{gray!20}{
  \begin{minipage}[][\dimexpr.25\paperheight-2\fboxsep][t]{\dimexpr \paperwidth-2\fboxsep}
    \blindtext    
  \end{minipage}
}\par \nointerlineskip

\end{document}

Only aspect to pay attention to: If the text inside the box is too long and runs over the defined height, it will ignore the \fboxsep at the bottom of the box.

Of course, other box setups are possible. And for repetition you could wrap the box setup inside a new command, e.g. like

\NewDocumentCommand{\mytextbox}{+m}{%
  \colorbox{gray!20}{%
    \begin{minipage}[][\dimexpr.25\paperheight-2\fboxsep][t]{\dimexpr \paperwidth-2\fboxsep}
      #1
    \end{minipage}
  }\par \nointerlineskip

Which offers you also the possibility to declare some default text, as name:............. etc.

Just an additional idea ;)

6
  • 1
    With an uptodate LaTex version, atbegshi's functionality is part of the kernel and will only be emulated: \AddToHook{shipout/background}{\put…} should work as well. Sep 15, 2023 at 14:18
  • 1
    @Qrrbrbirlbel, of course, you're right. Was too lazy to adapt the code. Now its up-to-date with lthooks and ltshipout from the kernel. Thus, no packages needed.
    – lukeflo
    Sep 15, 2023 at 15:08
  • I particularly like simple solutions with commands who don't need extra packages. And you've extended more on the usage of boxes. I learned too the optionnal parameter of the minipage environment for height which will be very useful for me in the future :-)... A perfect answer,and edit. Thanks !
    – Piroooh
    Sep 19, 2023 at 20:13
  • To be complete, could you explain what the commands \put and \multiput do ?
    – Piroooh
    Sep 19, 2023 at 20:16
  • Good that it solved your question. I prefer those simple solutions too ;). \put is a command of the built in LaTeX environment picture. It puts the content of the braced argument at the position defined in the parentheses. The position is defined as x and y coordinates, by default counted in pt, from the upper left corner of the page. Thus, \put(.5\paperwidth,-.5\paperheight){A} places an A in the middle of the page (the second coordinate is negative, cause it counts from the upper end of the page down). \multiput repeats a given code, which here results in a dotted line.
    – lukeflo
    Sep 19, 2023 at 21:27

You must log in to answer this question.

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