# Stack Logic Symbols in Tikz

I want to reproduce diagrams like the following in tikz (taken from Sider's Logic for Philosophy, p. 189):

In particular, I can't figure out how to stack symbols as they are in this image (having 1s and 0s above certain operators, and asterisks either above or below). I've tried stacking with \mathop and \overset but neither is producing the result I need. Here is my current code:

$$\mathop{\Diamond}_{*}^{1} \Box P \rightarrow \Box \Diamond P$$ % kind of squished together and doesn't work in tikz node environment

$$\overset{1}{\Diamond} \Box P \rightarrow \Box \Diamond P$$ \\% works in tikz node but squished together and no option to put something underneath

\begin{center}
\begin{tikzpicture}[>=stealth',shorten >=2pt,shorten <=2pt]

\node[rectangle,draw,minimum height=2cm] (1) [label=left:$a$] {$\Diamond P \rightarrow \Box \Diamond P$};
\node[rectangle,draw,minimum height=2cm]  (2) [label=left:$b$, below left=of 1] {$\Box P$};
\node[rectangle,draw,minimum height=2cm] (3) [label=left:$c$, below right=of 1] {$\Diamond P$};

\path[->] (1) edge (2);
\path[->] (1) edge (3);

\end{tikzpicture}
\end{center}

• See stackengine package. I think it should be straightforward. Nov 7 '16 at 21:13
• @StevenB.Segletes I'm shocked, just shocked that you would suggest that, Steven. :) Nov 7 '16 at 21:18

Stacking can be obtained with array.

\documentclass{article}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,arrows,positioning}

\newenvironment{LfPmatrix}
{$\renewcommand{\arraystretch}{1.2}% \setlength{\arraycolsep}{0pt}% \begin{array}{*{7}{c}}} {\end{array}$}

\begin{document}

\begin{tikzpicture}[>=stealth',shorten >=2pt,shorten <=2pt]

\node[rectangle,draw,minimum height=1.5cm] (1) [label=left:r\strut]
{\begin{LfPmatrix}
\mathtt{1}&&&\mathtt{0}&\mathtt{0}\\
\Diamond&\Box&P&\to&\Box&\Diamond&P\\
{*}&&&&{*}
\end{LfPmatrix}};
\node[rectangle,draw,minimum height=1.5cm] (2) [label=left:a\strut, below left=of 1]
{\begin{LfPmatrix}
{*} \\
\mathtt{1} \\
\Box&P
\end{LfPmatrix}};
\node[rectangle,draw,minimum height=1.5cm] (3) [label=left:b\strut, below right=of 1]
{\begin{LfPmatrix}
{*} \\
\mathtt{0} \\
\Diamond P
\end{LfPmatrix}};

\path[->] (1) edge (2);
\path[->] (1) edge (3);

\end{tikzpicture}

\end{document}