2

I choose width=18cm, height=26cm in geometry.sty.
If I set the origin at the page center and positionate a node at (-0.5\textwidth, 0.5\textheight) I get a gap over the tikzpicture.

How to get rid of that gap.

enter image description here

\documentclass[]{scrartcl}
\usepackage[showframe=true, width=18cm, height=26cm]{geometry}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc, matrix}
\pagestyle{empty}

\begin{document}
\begin{tikzpicture}[
  shift={(current page.center)},
  overlay,remember picture,
  nodes={inner sep=0pt,outer sep=0pt}
]
  \node[
    anchor=north west, 
    draw, red, 
    minimum width=1.0\textwidth,text width=1.0\textwidth-2mm,
    minimum height=6cm,text depth=6cm-4mm,
    align=left, 
  ] at (-0.5\textwidth, 0.5\textheight) (Textbox) {ABC};

  % Help
  \node[blue] at (0,0) {x};
  \draw[blue] (0,0) -- (0,0.5\textheight);
\end{tikzpicture}
\end{document}
  • I think the showframe option shows a wrong frame because if you draw \draw[blue] (0,0)--(0,-0.5\textheight);, the line overpasses bottom text border by the same amount which is missing to reach top border. – Ignasi May 27 '20 at 9:46
3

Explanation

You shift the tikz coordinates by paper size (shift={(current page.center)}), but put the node relative to text area size (at (-0.5\textwidth, 0.5\textheight)).

  • Since the left and right margin between paper size and text area size is the same (in your example), node Textbox is both horizontally centered relative to paper and text area.
  • Since the upper and lower margin between that two sizes are different, node Textbox is not vertically centered relative to text area.

Solution

Package tikzpagenodes provides extra nodes having the size of text area, marginpar area, and header and footer area. The new node current page text area is your help:

\documentclass[]{scrartcl}
\usepackage[showframe=true, width=18cm, height=26cm]{geometry}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc, matrix}
\pagestyle{empty}

\begin{document}
\begin{tikzpicture}[
  % replace node "current page"
  shift={(current page text area.center)},
  overlay,remember picture,
  nodes={inner sep=0pt,outer sep=0pt}
]
  \node[
    anchor=north west, 
    draw, red, 
    minimum width=1.0\textwidth,text width=1.0\textwidth-2mm,
    minimum height=6cm,text depth=6cm-4mm,
    align=left, 
  ] at (-0.5\textwidth, 0.5\textheight) (Textbox) {ABC};

  % Help
  \node[blue] at (0,0) {x};
  \draw[blue] (0,0) -- (0,0.5\textheight);
\end{tikzpicture}
\end{document}

enter image description here

  • Aha, tikzpagenodes.sty, I understand. Very good. – cis May 27 '20 at 10:07

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.