将表定位到节点的左下方

将表定位到节点的左下方

在此处输入图片描述

我在表格定位方面遇到了麻烦。我在页面中心正下方有一个节点,我想在这个节点的左下方放置一个表格,但在编译时,它会将表格放在顶部和顶部节点的前面。我想知道我可以用什么来解决这个问题。

\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}

答案1

您的代码有两个主要问题。首先,正如 Skillmon 所提到的,需要tabular进入节点内部。然后很容易放置它,特别是如果您加载库positioning。然后,可以说更糟糕的是,您正在嵌套tikzpictures,而共识是应该避免这种情况。您可以tikzpictures放入\saveboxes中,那就没有问题了。

查看修复后代码的输出

\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}

在此处输入图片描述

我实际上不太确定这是否是你想要的,但它可能是答案的基础。

相关内容