如何在节点内排版 TikZ 图片?

如何在节点内排版 TikZ 图片?

节点的内容以文本模式绘制。除了引入tikzpicture环境之外,有没有办法在节点内部绘制图片?

嵌套tikzpicture环境是有问题的,也因为内部环境继承所有 TikZ 属性来自周围tikzpicture环境。

答案1

您需要采取预防措施才能使用嵌套 tikzpicture,但这是可行的。

你还需要采取一定的预防措施来处理tikzpicture内部 tikzpicturescope内部 tikzpicture问题。一切都取决于情况和你想做什么,但我认为总有办法解决。

我负责下一个文件另一个问题。这里的问题是自动放置爱心,我需要使用外部节点“(txt)”将节点放置在 tikzpicture 节点内。好吧,Tikz 很神奇,可以毫无问题地做到这一点

在此处输入图片描述

\documentclass{scrartcl}
\usepackage[paperwidth=8cm,
            paperheight=8cm,
            margin=0cm,
            left=0cm,
            bottom=0mm]{geometry} 
%\PassOptionsToPackage{dvipsnames,svgnames}{xcolor}   
\usepackage{tikz}

 \begin{document} 
 \pagestyle{empty}   
 \setlength{\parindent}{0em} 

 \tikzset{text style/.style={align      = center,
                             text width = \textwidth}}    

\newcommand\mytext{The life that I have \\
Is all that I have \\
And the life that I have \\
Is yours. \\
The love that I have  \\
Of the life that I have \\
Is yours and yours and yours. \\

A sleep I shall have \\
A rest I shall have \\
Yet death will be but a pause.\\

For the peace of my years \\
In the long green grass \\
Will be yours and yours and yours.}

\null\vfill
\begin{tikzpicture}[remember picture]
\node[text style,color=red] (txt) {\mytext};

\node at (txt.center)     
{\begin{tikzpicture}[fill  = red]
\pgftransformscale{.025}
\pgfpathmoveto{\pgfqpoint{3600 pt}{3350 pt}}
\pgfpathcurveto{\pgfqpoint{3580 pt}{4270 pt}}
               {\pgfqpoint{870 pt}{6400 pt}}
               {\pgfqpoint{990 pt}{7860 pt}}%     
\pgfpathcurveto{\pgfqpoint{1040 pt}{8430 pt}}
               {\pgfqpoint{1590 pt}{9060 pt}}
               {\pgfqpoint{2200 pt}{9060 pt}}%
\pgfpathcurveto{\pgfqpoint{3610 pt}{9050 pt}}
               {\pgfqpoint{3600 pt}{7720 pt}}
               {\pgfqpoint{3600 pt}{7720 pt}}%
\pgfpathcurveto{\pgfqpoint{3600 pt}{7720 pt}}
               {\pgfqpoint{3580 pt}{9050 pt}}
               {\pgfqpoint{4990 pt}{9060 pt}}%
\pgfpathcurveto{\pgfqpoint{5600 pt}{9060 pt}}
               {\pgfqpoint{6150 pt}{8430 pt}}
               {\pgfqpoint{6200 pt}{7860 pt}}%
\pgfpathcurveto{\pgfqpoint{6320 pt}{6400 pt}}
               {\pgfqpoint{3610 pt}{4270 pt}}
               {\pgfqpoint{3600 pt}{3350 pt}}%
\pgfpathclose            
\pgfusepath{clip,fill,stroke}%
%
\node[white,
     anchor = north west,
     text style] at (txt.north west) {\mytext};  
\end{tikzpicture}};
\end{tikzpicture} 
\vfill
\end{document}

更新 我在第一个 tikzpicture 内的节点内的 tikzpicture 内的节点内添加了一个新的 tikpicture,并设置了不透明度和填充。

我从 pst-fun 的 ant 创建了 ant.pgf,但由于原始图片的使用,遇到了一些困难rlinetorcurveto而且我不知道是否可以用 pgf 来实现。

在此处输入图片描述

 %  http://altermundus.com/SandBox/ant1.pgf       
 \documentclass{scrartcl}
\usepackage[paperwidth=8cm,
            paperheight=8cm,
            margin=0cm,
            left=0cm,
            bottom=0mm]{geometry} 
\PassOptionsToPackage{dvipsnames,svgnames}{xcolor}   
\usepackage{tikz}
\makeatletter  
\newcommand{\callornament}[1]{%
\begingroup
\def\i{\pgfusepath{clip}}%
\let\o\pgfpathclose
\let\s\pgfusepathqfillstroke
\def\p ##1##2{\pgfqpoint{##1bp}{##2bp}}%
\def\m ##1 ##2 {\pgfpathmoveto{\p{##1}{##2}}}%
\def\l ##1 ##2 {\pgfpathlineto{\p{##1}{##2}}}%
\def\r ##1 ##2 ##3 ##4 {\pgfpathrectangle{\p{##1}{##2}}{\p{##3}{##4}}}%
\def\c ##1 ##2 ##3 ##4 ##5 ##6 {%
\pgfpathcurveto{\p{##1}{##2}}{\p{##3}{##4}}{\p{##5}{##6}}}%   
\@@input #1\relax
\endgroup}   
\makeatother

 \begin{document} 
 \pagestyle{empty}   
 \setlength{\parindent}{0em} 

 \tikzset{text style/.style={align      = center,
                             text width = \textwidth}}    

\newcommand\mytext{The life that I have \\
Is all that I have \\
And the life that I have \\
Is yours. \\
The love that I have  \\
Of the life that I have \\
Is yours and yours and yours. \\

A sleep I shall have \\
A rest I shall have \\
Yet death will be but a pause.\\

For the peace of my years \\
In the long green grass \\
Will be yours and yours and yours.}

\null\vfill
\begin{tikzpicture}[remember picture]
\node[text style,color=red] (txt) {\mytext};

\node (h) at (txt.center)     
{\begin{tikzpicture}[fill  = red]
\pgftransformscale{.025}
\pgfpathmoveto{\pgfqpoint{3600 pt}{3350 pt}}
\pgfpathcurveto{\pgfqpoint{3580 pt}{4270 pt}}
               {\pgfqpoint{870 pt}{6400 pt}}
               {\pgfqpoint{990 pt}{7860 pt}}%     
\pgfpathcurveto{\pgfqpoint{1040 pt}{8430 pt}}
               {\pgfqpoint{1590 pt}{9060 pt}}
               {\pgfqpoint{2200 pt}{9060 pt}}%
\pgfpathcurveto{\pgfqpoint{3610 pt}{9050 pt}}
               {\pgfqpoint{3600 pt}{7720 pt}}
               {\pgfqpoint{3600 pt}{7720 pt}}%
\pgfpathcurveto{\pgfqpoint{3600 pt}{7720 pt}}
               {\pgfqpoint{3580 pt}{9050 pt}}
               {\pgfqpoint{4990 pt}{9060 pt}}%
\pgfpathcurveto{\pgfqpoint{5600 pt}{9060 pt}}
               {\pgfqpoint{6150 pt}{8430 pt}}
               {\pgfqpoint{6200 pt}{7860 pt}}%
\pgfpathcurveto{\pgfqpoint{6320 pt}{6400 pt}}
               {\pgfqpoint{3610 pt}{4270 pt}}
               {\pgfqpoint{3600 pt}{3350 pt}}%
\pgfpathclose            
\pgfusepath{clip,fill,stroke}%
%
\node[white,
     anchor = north west,
     text style] at (txt.north west) {\mytext}; 
\node at (txt.center){\tikz \pgftransformscale{.0125}%
                           \pgfsetfillcolor{MidnightBlue}%
                           \pgfsetfillopacity{.5}%
                           \callornament{ant1.pgf} ;};    
\end{tikzpicture}};

\end{tikzpicture} 
\vfill
\end{document}

相关内容