箭头函数图

箭头函数图

我想要构建如下图表:

箭头图来自 https://www.haskell.org/arrows/syntax.html

或者这样,但没有顶部文字:

另一个箭头图

我怎样才能在 LaTeX 中做到这一点?


到目前为止,我已经

\begin{tikzpicture}[
  hidden/.style={
    transparent
  },
  arr/.style={
    rectangle, 
    minimum size=6mm,rounded corners=1mm,
    very thick,draw=orange,
    font=\itshape
  },
  op/.style={
    rectangle,minimum size=6mm,rounded corners=3mm,
    very thick,draw=black
  },
  var/.style={
    font=\itshape
  },
  every on chain/.style={join}, every join/.style={->}
]

\matrix[column sep=4mm] {
  % First row:
  & & \node (f) [arr] {f}; & & & \\
  % Second row:
  \node (start) [hidden] {};     &
  \node (x)     [var]    {x};    &
  & % f
  & % g
  \node (plus)  [op]    {+};     &
  \node (end)   [hidden] {};     \\
  % Third row:
  & & & \node (g) [arr] {g}; & & \\
  };

{ [start chain]
  \chainin (start);
  \chainin (x);
  { [start branch=f]
    \chainin (f);
  }
  { [start branch=g]
    \chainin (g);
  }
  \chainin (plus) [join=with chain/f-end, join=with chain/g-end];
  \chainin (end);
}
\end{tikzpicture}

上述 LaTeX 的输出

但我不知道如何解决这些问题:

  1. 我无法用橙色盒子包裹整个东西。我需要任意链式嵌套;我甚至不知道从哪里开始第二个示例图像。
  2. x是一个节点而不是一个标签。
  3. 有一个从x到 的箭头+
  4. 2 和 3 阻止我将“拆分”和“交换”做得像第二个示例图像的第一个和第三个子框那样好看。
  5. 我无法标记盒子的输出,例如第一个例子中的y和,或第二个例子中的大多数标签。z

答案1

我已经使用 Mathcha 工具创建了你的第一张图片(像往常一样):https://www.mathcha.io/editor

我希望我的绘图比你的第一幅图更接近......这里的代码(总是)很长。

在此处输入图片描述

%% Compile and read me!
\documentclass[a4paper,12pt]{article}
\usepackage{newtxtext,newtxmath}
\usepackage{tikz}


\begin{document}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,435); %set diagram left start at 0, and has height of 435

%Rounded Rect [id:dp3681361804386978] 
\draw  [color={rgb, 255:red, 210; green, 105; blue, 30 }  ,draw opacity=1 ][line width=1.5]  (118,185.6) .. controls (118,172.57) and (128.57,162) .. (141.6,162) -- (437.4,162) .. controls (450.43,162) and (461,172.57) .. (461,185.6) -- (461,256.4) .. controls (461,269.43) and (450.43,280) .. (437.4,280) -- (141.6,280) .. controls (128.57,280) and (118,269.43) .. (118,256.4) -- cycle ;
%Straight Lines [id:da3338900763412975] 
\draw [line width=1.5]    (84,222) -- (147,222) -- (179,254) ;
%Straight Lines [id:da7996129840856614] 
\draw [line width=1.5]    (179,190) -- (147,222) ;

%Straight Lines [id:da9958818927435902] 
\draw [line width=1.5]    (179,190) -- (214,190) ;
\draw [shift={(218,190)}, rotate = 180] [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.08]  [draw opacity=0] (13.4,-6.43) -- (0,0) -- (13.4,6.44) -- (8.9,0) -- cycle    ;
%Straight Lines [id:da6891092515638224] 
\draw [line width=1.5]    (179,254) -- (300,254) ;
\draw [shift={(304,254)}, rotate = 180] [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.08]  [draw opacity=0] (13.4,-6.43) -- (0,0) -- (13.4,6.44) -- (8.9,0) -- cycle    ;
%Rounded Rect [id:dp6536571054416698] 
\draw  [color={rgb, 255:red, 210; green, 105; blue, 30 }  ,draw opacity=1 ][line width=1.5]  (218,181.12) .. controls (218,177.74) and (220.74,175) .. (224.12,175) -- (284.88,175) .. controls (288.26,175) and (291,177.74) .. (291,181.12) -- (291,199.48) .. controls (291,202.86) and (288.26,205.6) .. (284.88,205.6) -- (224.12,205.6) .. controls (220.74,205.6) and (218,202.86) .. (218,199.48) -- cycle ;
%Straight Lines [id:da6580347293760087] 
\draw [line width=1.5]    (291,190) -- (364,190) -- (386.83,207.56) ;
\draw [shift={(390,210)}, rotate = 217.57] [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.08]  [draw opacity=0] (13.4,-6.43) -- (0,0) -- (13.4,6.44) -- (8.9,0) -- cycle    ;
%Rounded Rect [id:dp8739833672580277] 
\draw  [color={rgb, 255:red, 210; green, 105; blue, 30 }  ,draw opacity=1 ][line width=1.5]  (304,242.64) .. controls (304,239.26) and (306.74,236.52) .. (310.12,236.52) -- (349.88,236.52) .. controls (353.26,236.52) and (356,239.26) .. (356,242.64) -- (356,261) .. controls (356,264.38) and (353.26,267.12) .. (349.88,267.12) -- (310.12,267.12) .. controls (306.74,267.12) and (304,264.38) .. (304,261) -- cycle ;
%Straight Lines [id:da8158930252978749] 
\draw [line width=1.5]    (357,253) -- (371,253) -- (388.82,239.42) ;
\draw [shift={(392,237)}, rotate = 502.7] [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.08]  [draw opacity=0] (13.4,-6.43) -- (0,0) -- (13.4,6.44) -- (8.9,0) -- cycle    ;
%Shape: Circle [id:dp14302906684281536] 
\draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ,draw opacity=1 ][line width=1.5]  (386,222.5) .. controls (386,212.84) and (393.84,205) .. (403.5,205) .. controls (413.16,205) and (421,212.84) .. (421,222.5) .. controls (421,232.16) and (413.16,240) .. (403.5,240) .. controls (393.84,240) and (386,232.16) .. (386,222.5) -- cycle ;
%Straight Lines [id:da09927360792164697] 
\draw [line width=1.5]    (421,222.5) -- (472,222.5) ;
\draw [shift={(476,222.5)}, rotate = 180] [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.08]  [draw opacity=0] (13.4,-6.43) -- (0,0) -- (13.4,6.44) -- (8.9,0) -- cycle    ;
% Text Node
\draw (246,180) node [anchor=north west][inner sep=0.75pt]  [font=\large]  {$f$};
% Text Node
\draw (324,245) node [anchor=north west][inner sep=0.75pt]  [font=\large]  {$g$};
% Text Node
\draw (397,217) node [anchor=north west][inner sep=0.75pt]  {$\mathbf{+}$};
% Text Node
\draw (126,200) node [anchor=north west][inner sep=0.75pt]  [font=\Large]  {$x$};
% Text Node
\draw (302,170) node [anchor=north west][inner sep=0.75pt]  [font=\large]  {$y$};
% Text Node
\draw (360,235) node [anchor=north west][inner sep=0.75pt]  [font=\small]  {$Z$};


\end{tikzpicture}

\end{document}

相关内容