需要帮助在页面上绘制对角线

需要帮助在页面上绘制对角线

这是对问题的后续有没有一个包可以在页面上画一条对角线-不使用 TikZ,试图实现下列答案。然而,我认为这个问题太过广泛,无法在评论中得到处理。

我有以下 MWE,它可以很好地在页面上绘制主对角线和下部两个半对角线。

\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}

但是,我无法画出两条上半对角线。我尝试了所有可能性,但最终只能画出一条水平线或一条在已经画好的线上的线。

根据pgf手册,路径操作应该是相对的。那么这里出了什么问题?我试图在代码的注释中指出我要做什么,所以也许我已经在那里做错了,但却意外地得到了正确的结果。

答案1

使用current pageTikZ 中的节点来减轻痛苦或将绘制命令转换为 pgf,尽管这与 TikZ/PGF 无关,或者我不明白为什么你不想要 TikZ 但可以使用 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}

生成的页面图像

答案2

pgf并且tikz图片默认使用尽可能小的边界框。最后一张 pgf 图片的边界框高度仅为,.5\paperheight并且插入在纸张的左下角。因此,“上半对角线”移到了页面底部。

但是您可以使用特殊节点“当前页面”并将其添加\pgfusepath{use as bounding box}为环境中的第一行pgfpicture

\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}

结果是

在此处输入图片描述

在您的示例中,您可以在单个中使用单个路径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}

或者使用包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}

结果:

在此处输入图片描述

相关内容