2

This is a follow up to the question Is there a package that draws a diagonal line over the page - not using TikZ, in trying to implement the following answer. However, the problem is in my view too extensive to be dealt with in the comments there.

I have following MWE, which works fine for drawing the main diagonals and the lower two half-diagonals on the page.

\documentclass[a4paper]{article}
\usepackage{pgf}
\usepackage{eso-pic}
\begin{document}
\AddToShipoutPictureFG{%
\AtPageLowerLeft{% diagonal left bottom to right top
  \begin{pgfpicture}
    \pgfpathmoveto{\pgfpoint{0mm}{0mm}}
    \pgfpathlineto{\pgfpoint{\paperwidth}{\paperheight}}
    \pgfusepath{stroke}
  \end{pgfpicture}}%
\AtPageLowerLeft{%  semi-diagonal left bottom to right middle
  \begin{pgfpicture}
    \pgfpathmoveto{\pgfpoint{0mm}{0mm}}
    \pgfpathlineto{\pgfpoint{\paperwidth}{.5\paperheight}}
    \pgfusepath{stroke}
  \end{pgfpicture}}%
\AtPageLowerLeft{% diagonal right bottom to left top
  \begin{pgfpicture}
    \pgfpathmoveto{\pgfpoint{\paperwidth}{0mm}}
    \pgfpathlineto{\pgfpoint{0mm}{\paperheight}}
    \pgfusepath{stroke}
  \end{pgfpicture}}%
\AtPageLowerLeft{% diagonal right bottom to left middle
  \begin{pgfpicture}
    \pgfpathmoveto{\pgfpoint{\paperwidth}{0mm}}
    \pgfpathlineto{\pgfpoint{0mm}{.5\paperheight}}
    \pgfusepath{stroke}
  \end{pgfpicture}}%
%%%% From here, it turns bad
\AtPageLowerLeft{% diagonal right middle to left top
  \begin{pgfpicture}
    \pgfpathmoveto{\pgfpoint{\paperwidth}{.5\paperheight}}
    \pgfpathlineto{\pgfpoint{-.5\paperwidth}{.5\paperheight}}
    \pgfusepath{stroke}
  \end{pgfpicture}}%
}                         
blub\newpage blub         
\end{document}

However, I am not able to draw the two upper half-diagonals. I tried by guessing all possibilities yet arrive just at horizontal lines or a line over the already drawn ones.

According to the pgf-manual, the path operation should be relative. So what goes wrong here? I've tried to indicate what I'm trying to do in the comments in the code, so maybe I'm already doing stuff wrong there, but accidentally arrive at the right result.

  • you need to specify the bounding box of your pgfpicture otherwise it will calculate one and re-shift the origin – David Carlisle May 12 '17 at 18:14
4

Use current page node from TikZ to ease the pain or convert the draw commands to pgf which though is not relevant for TikZ/PGF or I don't understand why you don't want TikZ but ok with PGF.

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{eso-pic}
\begin{document}
\AddToShipoutPictureFG{%
\AtPageLowerLeft{% diagonal left bottom to right top
  \begin{tikzpicture}[overlay,remember picture]
    \draw (current page.south west)--(current page.north east);
    \draw (current page.south west)--(current page.east)--(current page.north west);
    \draw (current page.south east)--(current page.north west);
    \draw (current page.south east)--(current page.west)--(current page.north east);
    \draw (current page.south west)--(current page.north east);
\end{tikzpicture}}%
}                         
blub\newpage blub
\end{document}

resulting page image

  • Thanks for your answer. I don't want to use TikZ because of externalization issues, there is a workaround, though. But the question is more specific what I did wrong with the commands I've used in order to achieve the result. – jjdb May 13 '17 at 11:49
  • @jjdb You are using PGF so same issues should happen with PGF too. But anyways, the problem is that you need to place an empty something at (0,0) such that the bounding box includes the lowerleft corner otherwise your picture will be sized to the smallest bounding box – percusse May 13 '17 at 12:18
4

pgf and tikz pictures are using the smallest possible bounding box by default. The height of the bounding box of your last pgf picture is only .5\paperheight and this is inserted at the lower left corner of the paper. So the "upper half-diagonal" is shifted to the page bottom.

But you can use the special node "current page" and add \pgfusepath{use as bounding box} as first line in the pgfpicture environment:

\documentclass{article}
\usepackage{pgf}
\usepackage{eso-pic}
\begin{document}
\AddToShipoutPictureFG{%
  \AtPageLowerLeft{%
    \begin{pgfpicture}
      \pgfusepath{use as bounding box}
      \pgfpathmoveto{\pgfpointanchor{current page}{east}}
      \pgfpathlineto{\pgfpointanchor{current page}{north west}}
      \pgfusepath{stroke}
    \end{pgfpicture}%
  }%
}
blub\newpage blub
\end{document}

results in

enter image description here

In your example you can use a single path in a single pgfpicture:

\documentclass[a4paper]{article}
\usepackage{pgf}
\usepackage{eso-pic}
\begin{document}
\AddToShipoutPictureFG{%
  \AtPageLowerLeft{%
    \begin{pgfpicture}
      % diagonal left bottom to right top
      \pgfpathmoveto{\pgfpointanchor{current page}{south west}}
      \pgfpathlineto{\pgfpointanchor{current page}{north east}}
      % semi-diagonal left bottom to right middle
      \pgfpathmoveto{\pgfpointanchor{current page}{south west}}
      \pgfpathlineto{\pgfpointanchor{current page}{east}}
      % diagonal right bottom to left top
      \pgfpathmoveto{\pgfpointanchor{current page}{south east}}
      \pgfpathlineto{\pgfpointanchor{current page}{north west}}
      % diagonal right bottom to left middle
      \pgfpathmoveto{\pgfpointanchor{current page}{south east}}
      \pgfpathlineto{\pgfpointanchor{current page}{west}}
      % diagonal right middle to left top
      \pgfpathmoveto{\pgfpointanchor{current page}{east}}
      \pgfpathlineto{\pgfpointanchor{current page}{north west}}
      \pgfusepath{draw}
    \end{pgfpicture}%
  }%
}
blub\newpage bl
\end{document}

Or with package pgffor:

\documentclass[a4paper]{article}
\usepackage{pgf}
\usepackage{pgffor}
\usepackage{eso-pic}
\begin{document}
\AddToShipoutPictureFG{%
  \AtPageLowerLeft{%
    \begin{pgfpicture}
      \foreach \start/\end in {
        south west/north east,
        south west/east,
        south east/north west,
        south east/west,
        east/north west%
      }{
        \pgfpathmoveto{\pgfpointanchor{current page}{\start}}
        \pgfpathlineto{\pgfpointanchor{current page}{\end}}
      }
      \pgfusepath{stroke}
    \end{pgfpicture}%
  }%
}
blub\newpage bl
\end{document}

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.