3

Question:

Right now i am working in mini page, the problem is components of mini page are not placed at good place. I want to reduce the space between them and both start from the same line from top (i mean horizontally in same line)

MWE:

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,vmargin=0.5in,hmargin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath,amsfonts,amssymb,cancel}
\usepackage{array,booktabs}
\usepackage{forest}
\usepackage{parskip}
\usepackage{tcolorbox}
\begin{document}
\begin{minipage}[t]{.45\textwidth}
    \begin{forest}
        for tree={circle,draw, l sep=10pt}
        [140,black 
        [2]
        [70
        [2] 
        [35
        [5]
        [7]
        ]       
        ]
        ]
    \end{forest}
\end{minipage}
%\hfill
\begin{minipage}[b]{.55\textwidth}
    \begin{align*}
    140 &= 2 \times 2 \times 5 \times 7&\\
    &= 2^2 \times 5 \times 7 
    \end{align*}
\end{minipage}
\end{document}
5

The reference point for a forest is at the bottom. You can make it at the top so it aligns with a standard line of text with \adjustbox and valign=t. For the equation use aligned.

Finally, decide for the spacing between the objects, here \quad is used.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{forest}
\usepackage{adjustbox}

\begin{document}

\adjustbox{valign=t}{%
  \begin{forest}
    for tree={circle,draw, l sep=10pt}
    [140,black
      [2]
      [70
        [2]
        [35
          [5]
          [7]
        ]
      ]
    ]
  \end{forest}%
}% end of adjustbox (the % next to the brace is important
\qquad
$\begin{aligned}[t]
  140 &= 2 \times 2 \times 5 \times 7&\\
      &= 2^2 \times 5 \times 7 
\end{aligned}$

\end{document}

enter image description here

With the baseline option, you can vertically align the two parts so that the two instances of 140 are at the same height.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{forest}

\begin{document}

\begin{forest} baseline, for tree={circle,draw, l sep=10pt}
  [140,black
    [2]
    [70
      [2]
      [35
        [5]
        [7]
      ]
    ]
  ]
\end{forest}\qquad
$\begin{aligned}[t]
  140 &= 2 \times 2 \times 5 \times 7&\\
      &= 2^2 \times 5 \times 7 
\end{aligned}$

\end{document}

enter image description here

For vertical centering,

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{forest}
\usepackage{adjustbox}

\begin{document}

\begin{adjustbox}{valign=c}
\begin{forest} baseline=center, for tree={circle,draw, l sep=10pt}
  [140,black
    [2]
    [70
      [2]
      [35
        [5]
        [7]
      ]
    ]
  ]
\end{forest}
\end{adjustbox}\qquad
$\begin{aligned}
  140 &= 2 \times 2 \times 5 \times 7&\\
      &= 2^2 \times 5 \times 7 
\end{aligned}$

\end{document}

If you want to set this inside a math display, omit the $ characters and exploit gathered.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{forest}

\begin{document}

\begin{equation*}
\begin{gathered}
\begin{forest} baseline=center, for tree={circle,draw, l sep=10pt}
  [140,black
    [2]
    [70
      [2]
      [35
        [5]
        [7]
      ]
    ]
  ]
\end{forest}
\end{gathered}\qquad
\begin{aligned}
  140 &= 2 \times 2 \times 5 \times 7&\\
      &= 2^2 \times 5 \times 7 
\end{aligned}
\end{equation*}

\end{document}

enter image description here

  • Pleased to know new things. one request, Is it possible to place right part in the middle? i am asking Just for getting additional information. – Sandy Mar 19 at 10:21
  • @Sandy In the middle of what? – egreg Mar 19 at 10:22
  • i mean middle of first part, slightly below from its original position – Sandy Mar 19 at 10:27
  • @Sandy Do you mean that you want the two instances of 140 being aligned? – egreg Mar 19 at 10:29
  • Keep left part (tree) as it is. I don't want to move it. I am asking that how the equations part can we push vertically below exact in the middle of the tree. – Sandy Mar 19 at 10:35
2
\documentclass[12pt,a4paper]{article} 
\usepackage[a4paper,vmargin=0.5in,hmargin=0.5in]{geometry} 
\usepackage[utf8]{inputenc} 
\usepackage[misc]{ifsym} 
\usepackage{amsmath,amsfonts,amssymb,cancel} 
\usepackage{array,booktabs} 
\usepackage{forest} 
\usepackage{parskip} 
\usepackage{tcolorbox} 
\usepackage{varwidth} 
\begin{document} 
\begin{varwidth}[t]{.45\textwidth} \vspace{0pt}
\begin{forest} for tree={circle,draw, l sep=10pt} [140,black [2] [70 
    [2] [35 [5] [7] ]
    ] ] 
\end{forest} 
\end{varwidth} 
%\hfill 
\begin{varwidth}[t]{.55\textwidth} \vspace{0pt}
$ 140 = 2 \times 2 \times 5 \times 7 = 2^2 \times 5 \times 7 $
\end{varwidth} 
\end{document}

enter image description here

  • Nice it works. One question how can i place second component in the middle? – Sandy Mar 19 at 10:10
  • Put it between the two varwidth without an empty line! – user2478 Mar 19 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.