지오메트리 레이아웃의 정확한 Tikz 좌표

지오메트리 레이아웃의 정확한 Tikz 좌표

를 사용하여 한 페이지에 여러 이미지를 배치합니다 Tikz. 나는 사용한다 geometry layout. layout실제 페이지가 아닌 페이지 왼쪽 상단의 정확한 좌표를 알고 싶습니다 . 좌표 스크립트를 알아냈는데 꼭 필요한지 잘 모르겠습니다. 어떤 제안이라도 환영합니다. 참고: 목표는 페이지 중앙 Tikz에 최종 그림(여러 이미지와 레이블로 구성)을 배치하는 것입니다 layout.

\documentclass[12pt]{extbook}
% ############################## geometry
\usepackage%[showframe]
           {geometry}
\geometry
  { hmarginratio =  1:1
  , vmarginratio = 1:1
  , bindingoffset = 0cm
  , onecolumn
  , a4paper
  , layoutwidth = 50 mm
  , layoutheight = 180 mm
  , layouthoffset=\dimexpr(\paperwidth-\csname Gm@layoutwidth\endcsname)/2\relax
   , layoutvoffset=\dimexpr(\paperheight-\csname Gm@layoutheight\endcsname)/2\relax
  , showcrop
  }
\usepackage{fancyhdr}
\usepackage{mwe}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}

\makeatletter
\def\parsecomma#1,#2\endparsecomma{\def\page@x{#1}\def\page@y{#2}}
\tikzdeclarecoordinatesystem{page}{
    \parsecomma#1\endparsecomma
    \pgfpointanchor{current page}{north east}
    % Save the upper right corner
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    % save the lower left corner
    \pgfpointanchor{current page}{south west}
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    % Transform to the correct placement
    \pgfmathparse{(\pgf@xc-\pgf@xb)/2.*\page@x+(\pgf@xc+\pgf@xb)/2.}
    \expandafter\pgf@x\expandafter=\pgfmathresult pt
    \pgfmathparse{(\pgf@yc-\pgf@yb)/2.*\page@y+(\pgf@yc+\pgf@yb)/2.}
    \expandafter\pgf@y\expandafter=\pgfmathresult pt
}
\makeatother

% ############################### Document
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[remember picture, overlay]
 \node[inner sep=0pt] (A) at (page cs:0,0.5)
    {\includegraphics[width=5cm]{example-image}};
 \draw[black, thick] ($(A.north west)$)  rectangle ($(A.south east)$);
 \node[inner sep=0pt] (B) at ([yshift=-71pt]A.south)
    {\includegraphics[width=5cm]{example-image}};
 \draw[black,thick] ($(B.north west)$)  rectangle ($(B.south east)$);
\end{tikzpicture}
\end{document}

답변1

레이아웃 영역의 중심을 찾는 또 다른 방법은 다음과 같습니다. (간단한지 아닌지...)

\documentclass[12pt]{extbook}
    % ############################## geometry
    \usepackage%[showframe]
               {geometry}

\makeatletter% rename layout variables
  \def\layoutwidth{\Gm@layoutwidth}
  \def\layoutheight{\Gm@layoutheight}
  \def\layouthoffset{\Gm@layouthoffset}
  \def\layoutvoffset{\Gm@layoutvoffset}
\makeatother

    \geometry
      { hmarginratio =  1:1
      , vmarginratio = 1:1
      , bindingoffset = 0cm
      , onecolumn
      , a4paper
      , layoutwidth = 50 mm
      , layoutheight = 180 mm
      , layouthoffset=\dimexpr(\paperwidth-\layoutwidth)/2\relax
       , layoutvoffset=\dimexpr(\paperheight-\layoutheight)/2\relax
      , showcrop
      }

    \usepackage{fancyhdr}
    \usepackage{mwe}
    \usepackage{graphicx}
    \usepackage{tikz}
    \usetikzlibrary{calc}

    \newsavebox{\tempbox}

    % ############################### Document
    \begin{document}
    \thispagestyle{empty}

    \savebox{\tempbox}{%
    \begin{tikzpicture}
     \node[inner sep=0pt] (A) at (0,0.5)
        {\includegraphics[width=5cm]{example-image}};
     \draw[black, thick] ($(A.north west)$)  rectangle ($(A.south east)$);
     \node[inner sep=0pt] (B) at ([yshift=-71pt]A.south)
        {\includegraphics[width=5cm]{example-image}};
     \draw[black,thick] ($(B.north west)$)  rectangle ($(B.south east)$);
    \end{tikzpicture}}

    \begin{tikzpicture}[remember picture, overlay]
    \path (current page.north west) ++(\layouthoffset,-\layoutvoffset)
      ++(0.5\layoutwidth,-0.5\layoutheight) coordinate(Center);
    \node[inner sep=0pt] at (Center) {\usebox{\tempbox}};
    \end{tikzpicture}
  \end{document}

관련 정보