This is a question which has been discussed here and here. One of the solution discussed is to use fit
to cover empty cells. However, while trying it, it displayed an alignment problem between the empty cells and the others. Here is the MWE from the discussion thread, and where alignment problem is:
\documentclass[xcolor=dvipsnames, 14pt]{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\begin{document}
\begin{frame}
\begin{tikzpicture} [
block/.style ={rectangle
%,text width=6em
, draw
, minimum height=4em
, minimum width=4em
, outer sep=0pt}
]
\matrix (table) [%
matrix of nodes
, nodes in empty cells
, ampersand replacement=\&
, nodes=block
] {%
A \& B \& C \& D \\
E \& \& \& G \\
H \& I \& J \& \\
K \& L \& M \& \\
};
%\node[fit=(table-2-2)(table-2-3), inner sep=0pt]{F};
%\node[fit=(table-3-4)(table-4-4), inner sep=0pt]{N};
\end{tikzpicture}
\end{frame}
\end{document}
Why do I need multicolumn cells? I actually want to plot the following stacked
I managed to do it in tikz, but the code is very inelegant (xshift, yshfit kind of tweaking). I was hoping Matrix could serve as a better solution, but met the aforementioned alignment issue. The following are the MWE of my tweaking solution:
\documentclass[xcolor=dvipsnames, 14pt]{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\begin{document}
\begin{frame}
\centering
\footnotesize
\begin{tikzpicture}[
, every node/.style={
, rectangle, rounded corners=1mm % the shape
, very thick , draw % the border
, fill=orange!50
}]
\node [minimum width=.6\textwidth] (a) {AAAA};
\node [minimum width=.3\textwidth] (b) at (a.north) [xshift=-16mm, yshift=4mm] {B};
\node [minimum width=.07\textwidth] (c) at (b.east) [xshift=5mm] {CCC};
\node [minimum width=.20\textwidth] (d) at (c.east) [xshift=12mm] {DDDDD};
\end{tikzpicture}
\end{frame}
\end{document}
Best Answer
For the alignment issue, you can use the keys
text height
,text depth
,row sep
andcolumn sep
:For the other layout, borrowing some of Jake's code from his answer to Creating a node fitting the horizontal width of two other nodes) to automate the calculations of wider nodes: