使用 TikZ 和图片环境

使用 TikZ 和图片环境

请看我的例子:

  • 图片 蒂克兹

       \documentclass{article}
       \usepackage{color}
       \usepackage{tikz}
       \usepackage[english]{babel}
       \begin{document}
       \begin{tikzpicture}
       \path (0pt,0pt);% for adjusting to origin of entire document
       \draw[red]
       (0pt, 50pt) -- (120pt, 140pt) -- (240pt, 50pt);
       \end{tikzpicture}
       \begin{picture}(0,0)
       \color{blue}\qbezier(0, 50) (120, 140)(240, 50)
       \end{picture}
       \end{document}
    

结果: 在此处输入图片描述

  • 图片 蒂克兹

        \documentclass{article}
        \usepackage{color}
        \usepackage{tikz}
        \usepackage[english]{babel}
        \begin{document}
        \begin{picture}(0,0)
        \color{blue}\qbezier(0, 50) (100, 140)(200, 50)
        \end{picture}
        \begin{tikzpicture}
        \path (0pt,0pt);% for adjusting to origin of entire document
        \draw[red]
        (0pt, 50pt) -- (100pt, 140pt) -- (200pt, 50pt);
        \end{tikzpicture}
        \end{document}
    

结果: 在此处输入图片描述

  • 图片 没有 蒂克兹

        \documentclass{article}
        \usepackage{color}
        \usepackage{tikz}
        \usepackage[english]{babel}
        \begin{document}
        \begin{picture}(0,0)
        \color{blue}\qbezier(0, 50) (100, 140)(200, 50)
        \end{picture}
        \end{document}
    

结果: 在此处输入图片描述

从第三个示例中可以看出,图片环境的坐标与 TikZ 环境的坐标不同。是否可以描述蒂克兹与同一坐标系中的图形图片环境有?

答案1

不,坐标没有问题。问题是 tikz 默认使用边界框,而\begin{picture}(0,0)您的环境中没有边界框 picture。在第一部分中,我在 tikz 代码中使用“图片”,在其他部分中使用图片的边界框。备注:您的代码中空格放错了位置。

\documentclass{article}
\usepackage{color}
\usepackage{tikz}
\usepackage[english]{babel}
\begin{document} 
  \parindent=0pt
\begin{tikzpicture}
   \draw[help lines,step=10pt](0,0) grid (200pt,150pt);
   %\path (0pt,0pt);
    \draw[red]  (0pt, 50pt) -- (100pt, 140pt) -- (200pt, 50pt);
    \node[inner sep=0pt,anchor=south west] at (0,0){% 
    \begin{picture}(200,140)%
       \put(0,0){\line(1,0){200}} 
        \color{blue}\qbezier(0, 50) (100, 140)(200, 50)%
    \end{picture}% 
    };     
 \end{tikzpicture}%
   \begin{picture}(200,140)% 
     \put(0,0){\line(1,0){200}}
    \color{blue}\qbezier(0, 50) (100, 140)(200, 50)%
    \end{picture}           
  \begin{picture}(0,0)
    \color{blue}\qbezier(0, 50) (100, 140)(200, 50)%
    \end{picture}% 
    \begin{tikzpicture}
    \path (0pt,0pt);
    \draw[red]
    (0pt, 50pt) -- (100pt, 140pt) -- (200pt, 50pt);
    \end{tikzpicture}        
    \end{document}

在此处输入图片描述

更新

tikzpicture 的边界框为空的版本

\documentclass{article}
\usepackage{color}
\usepackage{tikz}  
\begin{document} 
  \parindent=0pt

\null\vspace{2cm} 

  \begin{picture}(0,0)
    \color{blue}\qbezier(0, 50) (100, 140)(200, 50)%
    \end{picture}% 
    \begin{tikzpicture}
    \draw[use as bounding box] (0,0) rectangle (0,0);     
    \path (0pt,0pt);
    \draw[red]
    (0pt, 50pt) -- (100pt, 140pt) -- (200pt, 50pt);
    \end{tikzpicture}% 
    \begin{picture}(0,0)
    \color{green}\qbezier(0, 50) (100, -90)(200, 50)%
    \end{picture}%         
\end{document} 

版本overlay

 \documentclass{article}
 \usepackage{color}
 \usepackage{tikz}  
 \begin{document} 
   \parindent=0pt

   \null\vspace{2cm} 

 \begin{picture}(0,0)
   \color{blue}\qbezier(0, 50) (100, 140)(200, 50)%
 \end{picture}% 
 \begin{tikzpicture}[overlay]
   \path (0pt,0pt);
   \draw[red]  (0pt, 50pt) -- (100pt, 140pt) -- (200pt, 50pt);
 \end{tikzpicture}% 
 \begin{picture}(0,0)
   \color{green}\qbezier(0, 50) (100, -90)(200, 50)%
 \end{picture}%          
 \end{document}

两段代码的结果是一样的。

在此处输入图片描述

相关内容