tikz/pgf:路径的绝对定位

tikz/pgf:路径的绝对定位

我没有采取回答在框架上绝对定位路径beamer。我实际的代码项目中的路径是在外部软件中生成的,非常复杂 - 我无法更改坐标。

\documentclass{beamer}
\usepackage{tikz}
\begin{document}

\begin{frame}

% Taken from https://tex.stackexchange.com/questions/348392/
\begin{tikzpicture}[remember picture,overlay]
    \useasboundingbox (current page.north west) rectangle (current page.south east);
    % Position the center of the following drawing at (.5\paperwidth,.5\paperheight) 
    \path[
        draw = blue,
        line width = 2pt
        ] (0,0) -- (1,2) -- (2,2) -- cycle;
\end{tikzpicture}        
% Indicate the actual center
\begin{tikzpicture}[remember picture,overlay]
    \node at (current page.center) {Center};
\end{tikzpicture}   

\end{frame}

\end{document}

enter image description here

答案1

可能不太正确,但如果您接受路径的中心是其边界框的中心,它似乎可以工作。

enter image description here

\documentclass{beamer}
\usepackage{tikz}
\begin{document}

\begin{frame}
\begin{tikzpicture}[remember picture,overlay]
    \node at (current page.center) {Center};
    \node[anchor=center, draw] at (current page.center) {%
         \begin{tikzpicture}[baseline=(current bounding box.center)]
             \path[
                draw = blue,
                line width = 2pt
                ] (0,0) -- (1,2) -- (2,2) -- cycle;
         \end{tikzpicture}%        
    };
\end{tikzpicture}   
\end{frame}

\end{document}

如果你不想嵌套 tikzpictures,复杂的路径可以绘制为一个standalone文档,可以插入到node里面\includegraphics

%ComplexPath.tex
\documentclass[tikz, border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \path[
        draw = blue,
        line width = 2pt
        ] (0,0) -- (1,2) -- (2,2) -- cycle;
\end{tikzpicture}        
\end{document}

生成(具有透明背景):

enter image description here

可将其包含在主文档中:

%Main document
\documentclass{beamer}
\usepackage{tikz}
\begin{document}

\begin{frame}
\begin{tikzpicture}[remember picture,overlay]
     \node at (current page.center) {Center};
     \node at (current page.center) {\includegraphics{ComplexPath}};
\end{tikzpicture}   
\end{frame}

\end{document}

相关内容