tikzpicture环境中各部分代码起什么作用?

tikzpicture环境中各部分代码起什么作用?

在此处输入图片描述

\documentclass{article} 
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[ultra thick]
\draw (0,0) rectangle node[yshift=  -1cm]{2} (2,1)
      (2,1) rectangle node[yshift=-1.5cm]{4} (5,3)
      (5,3) rectangle node[yshift=  -2cm]{6} (11,6);
\draw[shorten >=5, -stealth] (-1,-2) node[below]{a}--(0,0);
\draw[shorten >=5, -stealth]  (3,-2) node[below]{b}--(2,0);
\draw[shorten >=5, -stealth]  (6,-1) node[below]{c}--(5,1);
\draw[shorten >=5, -stealth]  (12,1) node[below]{d}--(11,3);
\end{tikzpicture}
\end{document}

答案1

像这样:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[ultra thick] % all lines will be ultra thick except if we pass another options
\draw (0,0) rectangle node[yshift=-1cm]  {2} ( 2,1) % draws a rectangle with opposite corners at (0,0) and (2,1)
                                                    % then puts a node 1cm below the rectangle center with label '2'
 
      (2,1) rectangle node[yshift=-1.5cm]{4} ( 5,3) % idem
      (5,3) rectangle node[yshift=-2cm]  {6} (11,6);% idem
\draw[shorten >=5, -stealth] (-1,-2) node[below]{a}-- (0,0); % draws a line from point (-1,-2) to point (0,0)
                                                             % the line terminates in a stealth type arrow (-stealth)
                                                             % the line is shortened at the end by 5pt (shorten >=5)
                                                             % then draws a node below the point (-1,-2) with label 'a'

\draw[shorten >=5, -stealth] ( 3,-2) node[below]{b}-- (2,0); % idem
\draw[shorten >=5, -stealth] ( 6,-1) node[below]{c}-- (5,1); % idem
\draw[shorten >=5, -stealth] (12, 1) node[below]{d}--(11,3); % idem
\end{tikzpicture}
\end{document}

相关内容