在 TikZ 或类似软件中制作图表

在 TikZ 或类似软件中制作图表

我想制作这样的图表

在此处输入图片描述

在 Ti 中是否可能Z?

我的尝试的 MWE

%\documentclass{standalone}
%\usepackage{tikz}
\documentclass[10pt,border=3mm,tikz]{standalone}% better visibility

\begin{document}
\begin{tikzpicture}
    % First Horizontal Line and Vertical Lines
    \draw [thick] (0,0) -- (5,0);
    \draw [thick] (0,-0.2) -- (0,0.2);
    \draw [thick] (5,-0.2) -- (5,0.2);
    
    % Second Horizontal Line and Vertical Lines
    \draw [thick] (6,0) -- (11,0);
    \draw [thick] (6,-0.2) -- (6,0.2);
    \draw [thick] (11,-0.2) -- (11,0.2);
\end{tikzpicture}
\end{document}

结果

答案1

她是 MWE 临时添加的一个

\documentclass[margin=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
    % First Horizontal Line and Vertical Lines
    \draw [thick] (0,0) coordinate (Zero) -- (5,0) coordinate (A);
    \draw [thick] (0,-0.2) node[below] {\strut$0$} -- (0,0.2);
    \draw [thick] (5,-0.2) node[below] {\strut$a$} -- (5,0.2);
   
    % Second Horizontal Line and Vertical Lines
    \draw [thick] (6,0) coordinate (B) -- (11,0) coordinate (C);
    \draw [thick] (6,-0.2) node[below] {\strut$b$} -- (6,0.2);
    \draw [thick] (11,-0.2) node[below] {\strut$C$} -- (11,0.2);

    \coordinate (T0) at ($(Zero)+(0,-1)$);
    \coordinate (Ta) at ($(A)+(0,-1)$);
    \coordinate (Tb) at ($(B)+(0,-1)$);
    \coordinate (Tc) at ($(C)+(0,-1)$);

    \draw[<-] (T0) -- (Ta) node[pos=0.5,above] {\footnotesize $a\to0$};

    \draw[->] (Tb) -- ($(Tb)!0.45!(Tc)$);
    \draw[->] (Tc) -- ($(Tb)!0.55!(Tc)$);

    \coordinate (D) at ($(Tb)!0.5!(Tc)$);

    \node[above] at (D) {\footnotesize $b\to C$};

    \coordinate (E) at ($(T0)!0.5!(Ta)+(0,-0.5)$);

    \draw (E) -- ++(0,-1) node[below] {$0$};
    \draw ($(D)+(0,-0.5)$) coordinate(D') -- ++(0,-1) coordinate(D'') node[below]  {$bC$} ;

    \fill ($(D')!0.5!(D'')$) circle (2pt);
    

  \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

首先选择初始坐标作为起点,然后借助修饰符扩展图表,这样会更容易,而不是尝试计算中点,例如0.2让其Tikz执行计算部分

例如在下面的代码中 \coordinate (e) at ($(a)!0.5!(b)$);充当坐标之间0.5midpointa,b

 \documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{calc} 
\usetikzlibrary{angles,intersections,quotes}

\begin{document}
\begin{tikzpicture}
    \draw [help lines] (0,0) grid (4,3);
    
    \coordinate[label=-90:A] (a) at (1,0);
    \coordinate (b) at (1,2);
    \coordinate [label=-90:C](c) at (3,0);
    \coordinate (d) at (3,2);
    
    \draw[red, line width=1pt] (a) -- (b);
    \draw[blue, line width=1pt] (c) -- (d); 
    \coordinate (e) at ($(a)!0.5!(b)$);
    \coordinate (f) at ($(c)!0.5!(d)$); 
    
    \draw[green, line width=1pt, shorten <=0.5pt, shorten >=0.5pt] (e) -- (f);
    
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

为了激发你的编程技能,让我们尝试对你的 MWE 进行一些重构:

  • 两条线除了坐标外都相同
  • 所以让我们把它们视为一个route对象
  • 可以Tikz通过\pic
  • 它允许复制您已有的内容...
  • 和新的选择

经常重构代码是一个好主意 ;-)

结果

\documentclass[10pt,border=3mm,tikz]{standalone}% better visibility

\begin{document}
\begin{tikzpicture}[
    route/.pic={% ~~~ refactoring duplicate parts ~~~
        \draw [thick] (0,0) -- (5,0);
        \draw [thick] (0,-0.2) -- (0,0.2);
        \draw [thick] (5,-0.2) -- (5,0.2);
    }
]
    % === Reproduction of what was already available =====
    % ~~~ First Horizontal Line and Vertical Lines
    \pic at (0,0) {route};    
    % ~~~ Second Horizontal Line and Vertical Lines
    \pic at (6,0) {route};
    
    % === New options ========
    % ~~~ going crazy to demonstrate \pics ~~~
    \pic[rotate=30,dotted]          at (45:4)   {route};    
    \pic[rotate=-15,red,scale=0.5]  at (45:4)   {route};    
    
\end{tikzpicture}
\end{document}

相关内容