8

For finding right margins, it might be interesting to display on each page the diagonal of the page (as well as the diagonal of the double page), see the pictures in this question, where this picture

Canonical page construction

probably gets best the intended result (just the diagonals).

Of course, one could do it with TikZ, but due to the externalization process I would prefer to get it without TikZ. Best would be a result that puts this over every page, similar like the showframe commands.

jjdb
  • 2,238

4 Answers4

17

enter image description here

\documentclass[a4paper]{article}
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth
\makeatletter

\dimen4=.996264\paperheight
\dimen6=.996264\paperwidth

\pdfliteral page{%
q
n
0  0 m
\strip@pt\dimen6 \space \strip@pt\dimen4 \space l
s
Q}
\begin{document}
zzzz
\end{document}
David Carlisle
  • 757,742
  • to put it on every page just define \@oddhead to have that \pdfliteral (or \@evenhead as well for two sided documents) – David Carlisle May 11 '17 at 18:10
  • Or use everypage. Wow! I have a PDF manual (1213 pages) but it never showed how to do anything like that. – John Kormylo May 11 '17 at 18:23
  • @JohnKormylo I'm sure the pdf manual has an example of drawing a line somewhere (it did last time I looked, I think:-) – David Carlisle May 11 '17 at 18:24
  • 3
    Ouch, that's pretty low level.... – JPi May 11 '17 at 21:32
  • 6
    @JPi I think you meant to say "nice, that's impressively efficient" ? – David Carlisle May 11 '17 at 21:48
  • 1
    Absolutely, of course. – JPi May 11 '17 at 22:13
  • Great impressively efficient answer. However, could you please comment the code a bit more? For me not being a TeX-wizard it is quite difficult to follow. – jjdb May 12 '17 at 06:51
  • 3
    @jjdb It's just PDF not tex, q= save state n = new path, 0 0 m = move to origin xx yy l = line to xx yy, s = stroke (draw) the path, Q = restore state. .996264 is 72/72.27 = conversion from tex to pdf points – David Carlisle May 12 '17 at 06:56
  • Unfortunately it is incompatible with the lscape package: \begin{landscape}zzzz\end{landscape}. – AlexG May 12 '17 at 08:16
  • @AlexG not really incompatible just "unaware": it assumes that the height is \paperheight and the width is \paperwidth if in some context you have swapped those round you need to swap them here as well. That is sort of inevitable in a package-free core primitives solution as here: you need to test for those things explicitly. – David Carlisle May 12 '17 at 08:19
  • Actually, the outbox of a landscape page (without header and footer) is rotated for shipout, \textwidth and \textheight were swapped previously, but \paperheight and \paperwidth remain untouched. – AlexG May 12 '17 at 09:20
  • @AlexG I know what lscape does (I wrote it:-) but I just meant that you need to adjust the coordinates to whatever you need, if you are just poking literal pdf drawing operators into the output you can't expect it to automatically adjust to some latex package being loaded. – David Carlisle May 12 '17 at 09:22
11

This not using tikz ;-)

\documentclass[a4paper]{article}
\usepackage{pgf}
\usepackage{eso-pic}

\begin{document}
\AddToShipoutPictureFG{%
\AtPageLowerLeft{%
 \begin{pgfpicture}
  \pgfpathmoveto{\pgfpoint{0mm}{\paperheight}}
  \pgfpathlineto{\pgfpoint{\paperwidth}{0mm}}
  \pgfusepath{stroke}
 \end{pgfpicture}}}%
blub\newpage blub
\end{document}
Ulrike Fischer
  • 327,261
  • 2
    That's funny... – JPi May 11 '17 at 21:33
  • A great answer, thank you too. the problem was mainly with the externalize, which could also be solved as shown in the other answer. However, I tried to implement your solution, but wandered into difficulties for the upper semi-diagonals. I put that as a new question. – jjdb May 12 '17 at 15:48
10

You could also use package pict2e:

\documentclass{article}
\usepackage{eso-pic}
\usepackage{pict2e}

\begin{document}
\AddToShipoutPictureFG{%
  \AtPageLowerLeft{%
    \Line(\LenToUnit{\paperwidth},0)(0,\LenToUnit{\paperheight})%
  }%
}
Text\newpage Text
\end{document}

enter image description here


enter image description here

Code:

\documentclass{scrbook}
\newcommand*\snum{10}% number of segments
\KOMAoptions{DIV=\snum}

\usepackage{eso-pic}
\usepackage{pict2e}
\usepackage{xcolor}
\usepackage{ifthen}
\usepackage{calc}

\newcounter{segment}
\newlength\circletextwidth
\setlength\circletextwidth{\paperwidth*\ratio{\paperwidth}{\paperheight}}

\usepackage{blindtext}
\begin{document}
\AddToShipoutPictureFG{%
  \AtPageLowerLeft{%
    \ifodd\value{page}%
      \setcounter{segment}{1}
      \whiledo{\value{segment}<\snum}{%
        \Line
          (\LenToUnit{\value{segment}\paperwidth/\snum},0)%
          (\LenToUnit{\value{segment}\paperwidth/\snum},\LenToUnit{\paperheight})%
        \Line
          (0,\LenToUnit{\value{segment}\paperheight/\snum})%
          (\LenToUnit{\paperwidth},\LenToUnit{\value{segment}\paperheight/\snum})%
        \stepcounter{segment}%
      }%
      \linethickness{2pt}%
      \moveto(\LenToUnit{\paperwidth/\snum},\LenToUnit{2\paperheight/\snum})%
        \lineto(\LenToUnit{\paperwidth-2\paperwidth/\snum},\LenToUnit{2\paperheight/\snum})%
        \lineto(\LenToUnit{\paperwidth-2\paperwidth/\snum},\LenToUnit{\paperheight-\paperheight/\snum})%
        \lineto(\LenToUnit{\paperwidth/\snum},\LenToUnit{\paperheight-\paperheight/\snum})%
        \closepath
        \textcolor{red}{\strokepath}%
      \textcolor{blue}{%
        \Line(\LenToUnit{\paperwidth},0)(0,\LenToUnit{\paperheight})%
        \Line(0,\LenToUnit{.5\paperheight})(\LenToUnit{\paperwidth},\LenToUnit{\paperheight})%
      }
    \else
      \linethickness{2pt}%
      \moveto(\LenToUnit{2\paperwidth/3-2\circletextwidth/3},\LenToUnit{2\paperheight/3-2\paperwidth/3})%
        \lineto(\LenToUnit{2\paperwidth/3+\circletextwidth/3},\LenToUnit{2\paperheight/3-2\paperwidth/3})%
        \lineto(\LenToUnit{2\paperwidth/3+\circletextwidth/3},\LenToUnit{2\paperheight/3+\paperwidth/3})%
        \lineto(\LenToUnit{2\paperwidth/3-2\circletextwidth/3},\LenToUnit{2\paperheight/3+\paperwidth/3})%
        \closepath
        \textcolor{red}{\strokepath}%
        \moveto(\LenToUnit{.5\paperwidth},\LenToUnit{5\paperheight/\snum})%
        \circlearc[1]{\LenToUnit{.5\paperwidth}}{\LenToUnit{2\paperheight/3-\paperwidth/6}}
          {\LenToUnit{.5\paperwidth}}{0}{360}%
        \textcolor{green}{\strokepath}%
      \textcolor{blue}{%
          \Line(0,0)(\LenToUnit{\paperwidth},\LenToUnit{\paperheight})%
          \Line(0,0)(\LenToUnit{\paperwidth},\LenToUnit{.5\paperheight})%
      }%
    \fi
  }%
}
\Blindtext[20]
\end{document}

Changing \snum to 8

\newcommand*\snum{8}

results in

enter image description here

esdd
  • 85,675
8

Since you already have your answer and mentioned as the reason for your preference not to use TikZ potential problems with the external library, I thought I'd add a solution showing that this can be worked around, for others who (like me) at some point have gotten tripped up by this. Maybe you already know this anyway but still prefer not to use TikZ, in which case apologies for bothering you. But just in case not:

You can disable and enable externalization for specific sections of your document or single pictures via:

  • \tikzexternaldisable and \tikzexternalenable (p.613 in pgfman.pdf)
  • \tikzset{external/export next=false} (or true, if you so desire). (p.612 in pgfman.pdf). I use this heavily to decorate chapter and part pages and a few other things in a class I'm writing, while still having external enabled by default, and it has served me quite well.

Example:

\documentclass[a4paper,oneside]{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize %Enable
\pagestyle{empty}

\begin{document}

% This picture will be externalized
\begin{tikzpicture}
    \draw (0,0) circle (4cm);
\end{tikzpicture}

% Disable externalization from here on forward
\tikzexternaldisable

% These two pictures will not be externalized
\begin{tikzpicture}[remember picture,overlay]
    \draw[red] (current page.north east) -- (current page.south west);
\end{tikzpicture}

\begin{tikzpicture}[remember picture,overlay]
    \draw[cyan] (current page.east) -- (current page.west);
\end{tikzpicture}

% Enable externalization from here on forward
\tikzexternalenable

% This picture will be externalized
\begin{tikzpicture}
    \draw (0,0) rectangle (4,2);
\end{tikzpicture}

% Disable Externalize for the next picture only
\tikzset{external/export next=false}%
% This picture will not be externalized
\begin{tikzpicture}[remember picture,overlay]
    \draw[blue] (current page.south east) -- (current page.north west);
\end{tikzpicture}

% This picture will be externalized. Note that we did not
% have to re-enable externalization explicitly.
\begin{tikzpicture}
    \draw[magenta] (5,0) rectangle (11,2);
\end{tikzpicture}
\end{document}

Result: result

alpenwasser
  • 2,455