# Commutative diagrams with TikZ: how do I compress this diagram?

So I am trying to do a taxonomy diagram using the tikzcd package. The diagram can be generated with following code (I do not how to show a picture of directly):

\documentclass
\begin{tikzcd}[ampersand replacement=\&,column sep=4em, cells={nodes={draw=gray}}, column sep=small]
\& \&  \text{Probability distribution inference} \arrow[dl] \arrow[dr] \& \text{Direct} \& \\
\& \text{Explicit density} \arrow[dl] \arrow[d] \& \& \text{Implicit density} \arrow[u] \arrow[d] \& \\
\text{Tractable density}\& \text{Approximate density} \arrow[d] \arrow[dr] \&  \& \text{Markov Chain} \&   \\
\& \text{Variational} \& \text{Markov Chain} \& \& \\
\end{tikzcd}
\end{document}


This goes outside the frame and there is a lot of white space in cells where I have not inserted any items. Also there is no symmetry in places where we would clearly want it. What commands can I use in order to fix this? In hindsight, tikzcd might not have been the optimal choice of constructing a taxonomy diagram, but I really like the esthetics of it.

• Welcome to tex.sx! Please post a complete MWE (minimal working example) instead of just a code snippet. It should start with \documentclass and end with \end{document}. Feb 3 at 11:25
• I tried doing this, but it does not work. @schtandard Feb 3 at 12:21
• Well, just adding \documentclass and \end{document} is not enough, of course. You need to make it a complete document. Feb 3 at 13:06

I guess (from "... goes outside the frame") that you use beamer presentation and that you looking for something like this:

With use of the makecell package and redefining cells parameters, it is possible to write multiline cells contents:

\documentclass{beamer}
\usepackage{makecell}
\usepackage{tikz-cd}

\begin{document}
\begin{frame}[fragile]
\frametitle{Taxonomy diagram}
\begin{center}
\begin{tikzcd}[column sep=1em,
cells={nodes={draw=gray, semithick,
align=center}},
]
&   &   \makecell{Probability\\ distribution\\ inference} \ar[dl] \ar[dr]
&   \makecell{Direct}
\\
&   \makecell{Explicit\\ density} \ar[dl] \ar[d]
&   &   \makecell{Implicit\\ density} \arrow[u] \arrow[d]
\\
\makecell{Tractable\\ density}
& \makecell{Approximate\\ density} \ar[d] \ar[dr]
&   &   \makecell{Markov\\ Chain}
\\
&   \makecell{Variational}
&   \makecell{Markov\\ Chain}
&
\end{tikzcd}
\end{center}
\end{frame}
\end{document}