1

enter image description here

I am having trouble with the positioning of a table. I have a node just below the center of the page and would like to place a table on the bottom left of such node, but when compiling it places the table at the top and in front of the top node. I would like to know what may I use in order to fix this.

\documentclass[a4paper]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\usepackage{pdflscape}
\usepackage{float}
\restylefloat{table}
\begin{document}
\thispagestyle{empty}
\begin{landscape}
\centering
\begin{tikzpicture}[every node/.style={circle,draw=black},scale=0.75,every node/.append style={transform shape}]
\node(tre1)[circle,draw,scale=0.5]{
\begin{tikzpicture}
\node(tree1){1}
 child{node{2}}
 child{node{3}}
 child{node{4}};
\end{tikzpicture}
};
\node at ($(tre1) + (2,-13.5)$)(root)[circle,draw,scale=0.9]{
\begin{tikzpicture}  
\node(one){1};
\node[below of=one](two){2};
\node[right of=one]{3};
\node[right of=two]{4};
\end{tikzpicture}
};   
\begin{tabular}{|c|c|c|} \hline 
a & $a(P)$ & $A(P)$ \\ \hline

0 & 1 & 1 \\ \hline 

1 & 1 & 1 \\ \hline 

1 & 0 & 1 \\ \hline 

1 & 1 & 1 \\ \hline 

\end{tabular} 
\end{tikzpicture}
\end{landscape}
\end{document}
  • 3
    You can put the tabular inside of a node. This way you could use TikZ's placement options. – Skillmon Aug 14 '18 at 22:15
1

There were two major issues with your code. First, as mentioned by Skillmon, the tabular needs to go inside a node. Then it is easy to place it, in particular if you load the positioning library. Then, arguably even worse, you were nesting tikzpictures, and the consensus is that this is to be avoided. You may put tikzpictures inside \saveboxes, then there is no problem.

Looking at the output of the repaired code

\documentclass[a4paper]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc,shapes,positioning}
\usepackage{pdflscape}
\usepackage{float}
\restylefloat{table}
\tikzset{my commandments/.style={every node/.style={circle,draw=black},
scale=0.75,every node/.append style={transform shape}}}
\newsavebox\BoxOne
\sbox\BoxOne{\begin{tikzpicture}[my commandments,scale=1]
\node(tree1){1}
 child{node{2}}
 child{node{3}}
 child{node{4}};
\end{tikzpicture}}
\newsavebox\BoxTwo
\sbox\BoxTwo{\begin{tikzpicture}[my commandments,scale=1,node distance=8pt]  
\node(one){1};
\node[below=of one](two){2};
\node[right=of one]{3};
\node[right=of two]{4};
\end{tikzpicture}}

\begin{document}
\thispagestyle{empty}
\begin{landscape}
\centering
\begin{tikzpicture}[my commandments]
\node(tre1)[circle,draw,scale=0.5]{\usebox\BoxOne};
\node at ($(tre1) + (2,-13.5)$)(root)[circle,draw,scale=0.9]{\usebox\BoxTwo}; 
% comment this out to see that the nodes have the same size
%\node[blue,scale=0.5] at (root.center) {\usebox\BoxOne};
\node[below left=of root,rectangle,draw=none]{
\begin{tabular}{|c|c|c|} 
\hline 
a & $a(P)$ & $A(P)$ \\ 
\hline
0 & 1 & 1 \\ 
\hline 
1 & 1 & 1 \\ 
\hline 
1 & 0 & 1 \\ 
\hline 
1 & 1 & 1 \\ 
\hline 
\end{tabular}};
\end{tikzpicture}
\end{landscape}
\end{document}

enter image description here

I am actually not quite sure if that's what you're after, but it may be a basis of an answer.

  • I really appreciate the help. If I were to paste the table as a .png or .jpg document using the graphicx package, would I still run into the same type of problem? I do wish to not have that table in a bubble, and to have all nodes of equal radius (maybe I am asking for too much). – Stiven G Aug 15 '18 at 0:28
  • @StivenG I removed the bubble around the table and made the bubbles equally large. If you include graphics, sure, there is no "you should not nest tikzpictures" problem, but this is absolutely not necessary. I already added the saveboxes. Alternatives to this strategy is to put what you had in the nested tikzpictures into a path picture of an ambient node, or, what may even be simpler, use the fit library to draw a circle around these nodes. (I am just not sure I understand what want to achieve here.) – user121799 Aug 15 '18 at 0:37
  • Wow. Thanks man. This really helped so much. – Stiven G Aug 15 '18 at 0:38
  • 1
    @StivenG you should not include a png or jpg table. Vector graphic format would be fine, but it'll be hard to have matching fonts and sizes with this, so redoing a table in LaTeX is almost always the better option. – Skillmon Aug 15 '18 at 7:12

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.