1

I want to print a lined page with a gap in the middle that should be in the centre of the page vertically. This is my code:

\documentclass[landscape]{article}
\usepackage[paperheight=320mm, paperwidth=450mm, top=0pt, bottom=0pt]{geometry} %Top=-10pt to start right at the top
\usepackage{tikz}

\begin{document}
\newcommand{\linegap}{5}
\newcommand{\linenumber}{19} %Off by one error, actual lines are one more then the one here
\newcommand{\spacing}{25}
\newcommand{\nextparagraphstart}{\the\numexpr\linegap*\linenumber+\spacing}

\begin{figure}
    \begin{tikzpicture}
[
        remember picture,
        overlay,
        every path/.style={
            line width=0.2mm,
        },
    ]
        \foreach \y in {0, \linegap, ..., \the\numexpr\linegap *\linenumber} {
            \coordinate (key) at (0, -\y mm);
            \draw (current page.west |- key) -- (current page.east |- key);
        }

        \foreach \y in {\nextparagraphstart, \the\numexpr\nextparagraphstart+\linegap, ..., \the\numexpr\nextparagraphstart+\linegap*\linenumber} {
            \coordinate (key) at (0, -\y mm);
            \draw (current page.west |- key) -- (current page.east |- key);
        }
    \end{tikzpicture}
\end{figure}
\end{document}

I have looked at similar questions and that suggest \vfill before and after figure which did not change anything. Have used \null and ~ before the \vfill and it also did nothing. I have also tried \vspace*{\fill} before and after the figure and it also didn't change anything. Is the coordinate command in TikZ not relative to the figure and instead specific for the page or is it some other reason?

0

3 Answers 3

2

By using options remember picture, overlay and page node current page, the tikz picture is drawn at absolute positions of the current page, irrelevant to the surrounding spacing commands like \vspace. Thus you should draw lines at the positions you want them on.

\documentclass[landscape]{article}
\usepackage[paperheight=320mm, paperwidth=450mm, top=0pt, bottom=0pt]{geometry} %Top=-10pt to start right at the top
\usepackage{tikz}

\begin{document}
\newlength{\linegap}  \setlength{\linegap}{5mm}
\newlength{\spacing}  \setlength{\spacing}{25mm}
\newlength{\currentyshift}

\newcommand{\linenumber}{19} %Off by one error, actual lines are one more then the one here


\begin{tikzpicture}
[
    remember picture,
    overlay,
    every path/.style={
        line width=0.2mm,
    },
]
    \setlength{\currentyshift}{\dimexpr.5\spacing -\linegap\relax}
    \foreach \y in {0, 1, ..., \linenumber} {
        \global\advance\currentyshift by \linegap
        % or the local assignment
        % \addtolength{\currentyshift}{\y\linegap}
        \draw
          ([yshift= \currentyshift]current page.west) -- 
          ([yshift= \currentyshift]current page.east)
          ([yshift=-\currentyshift]current page.west) -- 
          ([yshift=-\currentyshift]current page.east);
    }
    
    % helper,
    \draw[cyan!50, thick]
      % mark the center of page
      (current page.north west) -- (current page.south east)
      (current page.north east) -- (current page.south west)
      % visualize the spacing
      ([shift={( .5\spacing,  .5\spacing)}]current page) rectangle
      ([shift={(-.5\spacing, -.5\spacing)}]current page);
\end{tikzpicture}
\end{document}

enter image description here

0

The tikzpicture [overlay] takes up almost no space (equivalent to \hbox{}). You need to fill the text area with blank space. Otherwise any following text will simply write over the tikzpicture.

I didn't try to fix your foreach loops. This simply locates the center of the page (and the center of the text area). You can add your lines relative to that starting point.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{figure}[p]
\begin{minipage}[c][\textheight][c]{\textwidth}
\makebox[\textwidth]{center of text area}%
    \begin{tikzpicture}
[
        remember picture,
        overlay,
        every path/.style={
            line width=0.2mm,
        },
    ]
      \node[text=red] at (current page.center) {center of page};
    \end{tikzpicture}
\end{minipage}
\end{figure}
\end{document}
0

I'm just guessing .. something like this?

enter image description here

(red line is on vertical middle of page, blue box size is equal to \spacing in mm)

Edit: Your code is significantly simplified. Now it consider your comment (distance between line groups should equal to \spacing).

In comparison to original solution is now one loop less and for calculation of half of the \spacing is employed \pgfmathsetmacro.

I hope that now I correctly figured out what mean some defined commands (still unclear what in which units is \linegap) .

\documentclass[landscape]{article}
\usepackage[paperheight=320mm, paperwidth=450mm, 
            top=0pt, bottom=0pt]{geometry}
   \usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\newcommand{\linegap}{5}
\newcommand{\linenumber}{19} %Off by one error, actual lines are one more then the one here
\newcommand{\spacing}{25}

\begin{figure}
    \begin{tikzpicture}[remember picture,overlay]
    \pgfmathsetmacro{\halfspacing}{\spacing/2}
    \draw[red] (current page.west) -- node[draw=blue, inner sep=0pt, minimum size=\spacing mm] {} ++ (\paperwidth,0);

\foreach \y in {0,1, ...,\linenumber}
{
\draw   ([yshift= +\halfspacing mm] $(current page.west)+(0,\y*\linegap/10)$) -- ++ (\paperwidth,0);
\draw   ([yshift= -\halfspacing mm] $(current page.west)-(0,\y*\linegap/10)$) -- ++ (\paperwidth,0);
}
   \end{tikzpicture}
\end{figure}
\end{document}
2
  • Thanks, this fixes the centering, however the spacing is used for the total space between the bottom of the first group of lines and the top of the second group so it should be divided by 2, how would this be done? Just using \spacing/2 with or without parentheses does not work. Jul 4, 2022 at 18:35
  • @DragonStaty, sorry, but question is not very clear about this. Considering your comment, I correct code in answer.
    – Zarko
    Jul 4, 2022 at 21:01

You must log in to answer this question.

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