[Tex/LaTex] How to nicely place two heaps next to each other

nodestikz-pgftikz-trees

I am quite new to latex and I have a question on how to place two heaps of this size nicely next to each other in latex. For example:

\[\begin{tikzpicture}[every node/.style={circle,draw},level 1/.style={sibling distance=30mm},level 2/.style={sibling distance=10mm}]
    \tikzstyle{every node}=[circle,draw]
    \node {7}
           child{node{12}
             child{node{25}} child{node{14}}}
           child{node{9}}
    ;
\end{tikzpicture}\]


\[\begin{tikzpicture}[every node/.style={circle,draw},level 1/.style={sibling distance=30mm},level 2/.style={sibling distance=10mm}]
    \tikzstyle{every node}=[circle,draw]
    \node {7}
           child{node{12}
             child{node{25}} child{node{14}}}
           child{node{9}
             child{node{41}}}
    ;
\end{tikzpicture}\]

Best Answer

A blank line is mark-up for a paragraph break. As you probably know, it is the standard, recommended way to indicate that a new paragraph is required in text. It is no different here.

Moreover, \[...\] puts the contents in display maths mode, which will centre the contents with vertical space above and below.

You don't need to put a tikzpicture in maths mode and it is probably a bad idea. So just don't use \[...\] and remove the blank lines.

\tikzstyle{} is deprecated and, in your examples, is simply repeating settings you've already configured anyway.

To keep formatting of the 'heap's consistent, consider using a TikZ style, set here using \tikzset and named heap:

\documentclass{article}
\usepackage{tikz}
\tikzset{
  heap/.style={
    every node/.style={circle,draw},
    level 1/.style={sibling distance=30mm},
    level 2/.style={sibling distance=10mm}
  }
}
\begin{document}
\begin{tikzpicture}[heap]
  \node {7}
  child{node{12}
    child{node{25}} child{node{14}}}
  child{node{9}}
  ;
\end{tikzpicture}
\begin{tikzpicture}[heap]
  \node {7}
  child{node{12}
    child{node{25}} child{node{14}}}
  child{node{9}
    child{node{41}}}
  ;
\end{tikzpicture}
\end{document}

2 heaps