在两片森林之间添加箭头

在两片森林之间添加箭头

这是我的代码:

\documentclass[french, 12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[a4paper]{geometry}

\usepackage{graphicx} % Required for inserting images
\usepackage{tikz-cd}
\usepackage{adjustbox} %j'ai ajouté ce package pour utiliser la commande qui permet de centrer


\usepackage{forest}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{titlesec} %pour utiliser titleformat
\usepackage{xcolor}
\usepackage[skins]{tcolorbox}
\usepackage{float}
\usepackage{array}
\usepackage{subcaption}
\usepackage{tikz}


\usepackage[hidelinks]{hyperref}
\usepackage{enumitem}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{babel}
\usepackage{listings}

\begin{document}
\begin{forest}
    for tree={
        circle,
        l sep=5mm,
        s sep=25mm,
     },
     [C, fill=black!20,draw
        [A,fill=red!20,draw
            [$\alpha$]
            [B,fill=red!20,draw
                [$\beta$]
                [$\gamma$]
            ]
        ]
        [$\delta$]
    ]
 \end{forest}
 $\longrightarrow$
 \begin{forest}
 for tree={
        circle,
        l sep=5mm,
        s sep=25mm,
     },
    [C, fill=black!20 ,draw
        [B,fill=red!20 ,draw
            [A, fill=red!20, draw
                [$\alpha$]
                [$\beta$]
            ]
            [$\gamma$]
        ]
        [$\delta$]
    ]    
 \end{forest} 

\end{document}

在此处输入图片描述 我们想添加两个箭头,但似乎找不到答案。如果你能帮助我,那就太好了:) 在此处输入图片描述

答案1

tikzpicture一种方法是在森林之间放置一个。使用baseline中的选项设置基线forest。(该节点将成为基线。)

在此处输入图片描述

\documentclass[french, 12pt]{report}

\usepackage{forest}

\begin{document}
\begin{forest}
    for tree={
        circle,
        l sep=5mm,
        s sep=15mm,
     },
     [C, fill=black!20,draw
        [A,fill=red!20,draw, baseline %<--- set baseline for this forest at this node
            [$\alpha$]
            [B,fill=red!20,draw
                [$\beta$]
                [$\gamma$]
            ]
        ]
        [$\delta$]
    ]
 \end{forest}
% 
\begin{tikzpicture}[baseline=(A.text)] %<--- set baseline at this node
\draw[->](0,1)--node[above](A){Rotation droite de $y$}(4,1);
\draw[<-](0,0)--node[below]{Rotation gauche de $x$}(4,0);
\end{tikzpicture}
%
 \begin{forest}
 for tree={
        circle,
        l sep=5mm,
        s sep=15mm,
     },
    [C, fill=black!20 ,draw
        [B,fill=red!20 ,draw, baseline %<--- set baseline for this forest at this node
            [A, fill=red!20, draw
                [$\alpha$]
                [$\beta$]
            ]
            [$\gamma$]
        ]
        [$\delta$]
    ]    
 \end{forest} 

\end{document}

答案2

无需使用单独的tikzpicture,您只需将箭头添加到第一个forest环境中即可。只要箭头上方的标签比箭头短,这很简单。

这里我考虑标签文字较长的情况,如楼主原图所示,并且我们想要调整定位,使得第二棵树距离箭头不比第一棵树更远。

以下代码基本上忽略了箭头和标签,因此它们不会影响第一棵树的边界框,然后添加一条未绘制的路径以匹配箭头。实际上,这意味着两棵树都相对于箭头定位,并且标签溢出到两侧现有的空白处。

\documentclass[french, 12pt,a4paper]{report}
% ateb: https://tex.stackexchange.com/a/705147/ addaswyd o gwestiwn Caro: https://tex.stackexchange.com/q/705120/
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{geometry}
\usepackage{forest}
\usetikzlibrary{calc,arrows.meta}
\usepackage{babel}
\forestset{%
  ABC/.style={%
    for tree={%
      circle,
      l sep'=5mm,
      s sep'=15mm,
      font=\sffamily,
    },
  },
}
\tikzset{%
  arrow betwixt/.style={semithick,>=Stealth},
  arrow label/.style={midway,above,font=\sffamily\footnotesize,inner xsep=0pt},
}
\begin{document}
\begin{forest}
  ABC,
  [C, fill=black!20
    [A,fill=red!20
        [$\alpha$]
        [B,fill=red!20
            [$\beta$]
            [$\gamma$]
        ]
    ]
    [$\delta$]
  ]
  \begin{scope}[overlay]
    \draw [arrow betwixt,->] ($(!r.center)!.5!(!r2.center)$) coordinate  (a)  (a -| current bounding box.east) coordinate (b) -- ++(25mm,0pt) node [arrow label] {Rotation droite de y}; 
    \draw [arrow betwixt,<-] ($(!r11.center)!.5!(!r122.center)$) coordinate (c)  (c -| b)  -- ++(25mm,0pt) node [arrow label] {Rotation gauche de x};
  \end{scope}
  \path (current bounding box.east) -- ++(25mm,0pt);
\end{forest}%
\begin{forest}
  ABC,
  [C, fill=black!20 
      [B,fill=red!20 
          [A, fill=red!20
              [$\alpha$]
              [$\beta$]
          ]
          [$\gamma$]
      ]
      [$\delta$]
  ]    
\end{forest}

\end{document}

箭头表示两棵树的关系

相关内容