1

I am trying to draw two forest and I've been able to. What I'd like to add now is a Equivalence arrow (\Leftrightarrow) in the middle of those, but well aligned.

Currently I have the following code:

\documentclass[a4paper,12pt]{article}

\usepackage{color,forest,tikz,amsmath,amsbsy,amsfonts,mathtools,amssymb,amsthm}

\begin{document}

\begin{center} \begin{forest} for tree = {draw,circle,edge={black,thick},inner sep=2pt, minimum width= .25cm, font = \small, s sep = 1cm} [,fill=black, label = {u} [,fill=red] [,fill=red] ] \end{forest} $\qquad \Rightarrow \qquad$ \begin{forest} for tree = {draw,circle,edge={black,thick},inner sep=2pt, minimum width= .25cm, font = \small, s sep = 1cm} [,fill=red, label = {u} [,fill=black] [,fill=black] ] \end{forest} \end{center}

\end{document}

And this gives me the following Output:

enter image description here

I would like to replace the Rightarrow with Leftrightarrow (I can do that by myself) well aligned with both the trees. Besides from this, is it also possible to paint half the Leftrightarrow as red and other half as black? If so, my desired output would be something like this: enter image description here

If it's not possible to draw a Leftrightarrow with two colors I would also accept a normal leftrightarrow!

Thanks for any help in advance!

imnothere
  • 14,215
Rodrigo
  • 491
  • 3
  • 9

2 Answers2

2

Note that the forest package automatically loads tikz so you don't have to reload it in your preamble. Similarly, mathtools automatically loads amsmath.

Since tikz is already loaded, you can place the 2-colored arrow as a tikzpicture between your trees.

\qquad\tikz[baseline=-7mm]{\node[red,left]{$\Leftarrow$};\node{$\Rightarrow$}}\qquad

enter image description here

You can adjust the height however you like.

This makes a doublewide arrow by placing two arrows side by side, with a slight overlap, which may or may not be what you want. Also, the two arrows overlap in a way that you may not want:

enter image description here

You can \clip the black arrow to make the join square. Here is a macro that draws the clipped version:

\newcommand{\Redblackarrow}[1][-7mm]{\tikz[baseline=#1]
    {\node[red,left]{$\Leftarrow$};\clip (-.18,-.2)rectangle(.2,.2);\node{$\Rightarrow$};}}

enter image description here

The 7mm raise is built in as a default, but you can adjust the height with an optional argument. For example, \Redblackarrow[-8mm] will raise the arrow 8mm instead of 7mm.

A different tikz solution for 2-color characters that clips the character in half and colors each half is here.

Here is the complete code:

\documentclass[a4paper,12pt]{article}

\usepackage{forest}

\newcommand{\Redblackarrow}[1][-6mm]{\tikz[baseline=#1] {\node[red,left]{$\Leftarrow$};\clip (-.18,-.2)rectangle(.2,.2);\node{$\Rightarrow$};}}

\begin{document}

[ \begin{forest} for tree = {draw,circle,edge={black,thick},inner sep=2pt, minimum width= .25cm, font = \small, s sep = 1cm} [,fill=black, label = {u} [,fill=red] [,fill=red] ] \end{forest} \qquad\Redblackarrow\qquad \begin{forest} for tree = {draw,circle,edge={black,thick},inner sep=2pt, minimum width= .25cm, font = \small, s sep = 1cm} [,fill=red, label = {u} [,fill=black] [,fill=black] ] \end{forest} ]

\end{document}

Sandy G
  • 42,558
0

As far as I can see, forest doesn't provide a method for vertically centering the output. However it's not difficult to define one.

\documentclass[a4paper,12pt]{article}
\usepackage{forest,mathtools,amssymb,amsthm}
\usepackage{trimclip}

\newenvironment{cforest} {\tabular{@{}c@{}}\forest} {\endforest\endtabular}

\newcommand{\cLeftrightarrow}[2]{% % #1 = left color, #2 = right color \clipbox{0pt 0pt {0.1\width} {-0.3\height}}{$\textcolor{#1}{\Leftarrow}$}% \clipbox{{0.1\width} 0pt 0pt {-0.3\height}}{$\textcolor{#2}{\Rightarrow}$}% }

\begin{document}

\begin{center} \begin{cforest} for tree = {draw,circle,edge={black,thick},inner sep=2pt, minimum width= .25cm, font = \small, s sep = 1cm} [,fill=black, label = {u} [,fill=red] [,fill=red] ] \end{cforest}% \qquad\cLeftrightarrow{red}{black}\qquad \begin{cforest} for tree = {draw,circle,edge={black,thick},inner sep=2pt, minimum width= .25cm, font = \small, s sep = 1cm} [,fill=red, label = {u} [,fill=black] [,fill=black] ] \end{cforest} \end{center}

\end{document}

The two-colored arrow needs a few tricks:

  1. the standard Computer Modern arrows have rounded end lines, so we need to clip them;
  2. the bounding box of the arrows does not fully contain them, so we need “negative clipping” at the top.

enter image description here

The two arrows have the same height, but the color difference makes an optical illusion because of the too contrasting colors.

egreg
  • 1,121,712