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. – user156344 Mar 27 '19 at 17:57
  • ... and I recommend the tikzmark library for that. – user121799 Mar 27 '19 at 17:57
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

| improve this answer | |
  • May be the first minus should be under the brace too. – Kpym Mar 27 '19 at 18:42
  • @Kpym: I don't think so. I tried it and to the eye, it looks asymmetric. The aim, it seems, is to make visible that 8x splits into two 4x. In my opinion, the signs are off-topic here. – Bernard Mar 27 '19 at 18:48
  • that is definitely one way of doing it. thank you – Jettie Baker Mar 27 '19 at 18:53
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

| improve this answer | |
  • thank you it works. however it come up red – Jettie Baker Mar 27 '19 at 18:10
  • @JettieBaker Do you add any additional options? For example, change all math-mode to red, change default color in TikZ to red, etc? – user156344 Mar 27 '19 at 18:11
  • even when i just create a brand new document it still comes up red. would it maybe because im using overleaf – Jettie Baker Mar 27 '19 at 18:14
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

| improve this answer | |
  • 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. – user121799 Mar 27 '19 at 18:11

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.