2

Im trying to show how to factorise equations on latex Im using the following code. However, I want to the nodes coming from the 8x to be above the 4x's not the centre of the function and I dont want a space between the 2 parts.

\begin{tikzpicture}[edge from parent path=
{(\tikzparentnode.south) .. controls +(0,-1) and +(0,1)
.. (\tikzchildnode.north)}]
\node {$x^2 - 8x + 16$}
child {node {$x^2-4x$}}
child {node {$-4x+16$}};
\end{tikzpicture}

enter image description here

  • 1
    You should not put the equations to tikzpicture. Use remember picture TikZ option instead. –  Mar 27 '19 at 17:57
  • ... and I recommend the tikzmark library for that. –  Mar 27 '19 at 17:57

3 Answers3

7

Do you really need a hammersledge like TikZ for this?

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{gather*}
  x^2-8x + 16 \\[-1ex]
  x^2-\overbrace{\mathstrut 4x -4x} + 16
\end{gather*}

\end{document} 

enter image description here

If you really want to use graphic tools, I suggest using pstricks, namely the facilities of pst-node:

\documentclass[svgnames]{article}
\usepackage{mathtools}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

\begin{postscript}
    \begin{gather*}
      x^2-\Rnode{8}{8x} + 16 \\[2.5ex]
      x^2-\Rnode{4-4}{ 4x -4x} + 16
    \end{gather*}
\psset{linewidth=0.6pt, linecolor=LightSteelBlue,linejoin=1, arrows=->, arrowinset=0.12, nodesepA=2pt, angleA=-90, nodesepB=1pt, angleB=90}
\ncangle[offsetB=1.2em]{8}{4-4}
\ncangle[offsetB=-1.2em]{8}{4-4}
\end{postscript}

\end{document} 

enter image description here

Bernard
  • 271,350
5

A proposal not using tikzmark.

\documentclass{article} 
\usepackage{amsmath}
\usepackage{tikz}

\begin{document}
\[
\begin{array}{c}
    x^2-\tikz[baseline,remember picture] \node[anchor=base,inner xsep=0pt] (1) {$8x$};+16\\[3em]
    x^2-\tikz[baseline,remember picture] \node[anchor=base,inner xsep=0pt] (11) {$4x$};-\tikz[baseline,remember picture] \node[anchor=base,inner xsep=0pt] (12) {$4x$};+16
\end{array}
\]

\begin{tikzpicture}[remember picture,overlay]
\draw (1) to[out=-100,in=90] (11);
\draw (1) to[out=-80,in=90] (12);
\end{tikzpicture}
\end{document}

enter image description here

Some arrows will be great!

\documentclass{article} 
\usepackage{amsmath}
\usepackage{tikz}

\begin{document}
\[
\begin{array}{c}
    x^2-\tikz[baseline,remember picture] \node[anchor=base,inner xsep=0pt] (1) {$8x$};+16\\[3em]
    x^2-\tikz[baseline,remember picture] \node[anchor=base,inner xsep=0pt] (11) {$4x$};-\tikz[baseline,remember picture] \node[anchor=base,inner xsep=0pt] (12) {$4x$};+16
\end{array}
\]

\begin{tikzpicture}[remember picture,overlay,>=stealth]
\draw[->] (1) to[out=-100,in=90] (11);
\draw[->] (1) to[out=-80,in=90] (12);
\end{tikzpicture}
\end{document}

enter image description here

3

As pointed out by Joule V, it is arguably easier to typeset equation with the standard LaTeX tools, and I personally like to use tikzmark for that since, among other things, it detects the mode you are currently in.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\[\begin{array}{c}
x^2  \tikzmarknode{8}{-8x} + 16\\[0.6cm]
x^2\tikzmarknode{4a}{-4x}\tikzmarknode{4b}{-4x}+16
\end{array}
\begin{tikzpicture}[overlay,remember picture]
\foreach \X in {a,b}
{\draw[-latex] (8) to[out=-90,in=90] (4\X);}
\end{tikzpicture}\]
\end{document}

enter image description here

  • Copying your exact code doesnt work for me – Jettie Baker Mar 27 '19 at 18:09
  • 1
    @JettieBaker Most likely you do not have updated your TeX installation in a while. The \tikzmarknode command was added last year. See this thread for detecting the version of tikzmark on your machine. –  Mar 27 '19 at 18:11