I'm using tables with the tabular
environment, with cells containing tikzpicture
. I would like to center the contents of the cells both vertically and horizontally, and have little labels in the top left corner of each cell. As far as I've looked, the alignment problem is fixable with some tweaks, such as \setlength\extrarowheight{..}
before the table, and [..]
after line breaks inside the table. The \def\arraystretch{..}
approach also works to give more padding, but in a way that I don't fully understand, so I'm not using that.
This is my current code of a table of graphs:
\documentclass{article}
\usepackage{array,tikz}
\tikzset{nnode/.style={circle,draw=black,inner sep=1.4pt,fill}}
\begin{document}
\setlength\extrarowheight{3pc}
\begin{tabular}{|>{\centering\arraybackslash}m{7pc}
|>{\centering\arraybackslash}m{7pc}
|>{\centering\arraybackslash}m{7pc}|}
\hline\begin{tikzpicture}
\node[nnode] (a) at (0,0){};
\node[nnode] (b) at (1,0){};
\draw (-.5,0) circle (.5);
\draw (1.5,0) circle (.5);
\draw (a) to (b);
\end{tikzpicture}
&
\begin{tikzpicture}
\node[nnode] (a) at (0,0){};
\node[nnode] (b) at (1,0){};
\draw (-.5,0) circle (.5);
\draw (1.5,0) circle (.5);
\draw (a) to (b);
\end{tikzpicture}
&
\begin{tikzpicture}
\node[nnode] (a) at (0,0){};
\node[nnode] (b) at (1,0){};
\draw (-.5,0) circle (.5);
\draw (1.5,0) circle (.5);
\draw (a) to (b);
\end{tikzpicture}
\\[2pc]\hline
\begin{tikzpicture}
\node[nnode] (a) at (0,0){};
\node[nnode] (b) at (1.5,0){};
\draw (.75,0) circle (.75);
\draw (a) to (b);
\end{tikzpicture}
&
\begin{tikzpicture}
\node[nnode] (a) at (0,0){};
\node[nnode] (b) at (1.5,0){};
\draw (.75,0) circle (.75);
\draw (a) to (b);
\end{tikzpicture}
&
\begin{tikzpicture}
\node[nnode] (a) at (0,0){};
\node[nnode] (b) at (1.5,0){};
\draw (.75,0) circle (.75);
\draw (a) to (b);
\end{tikzpicture}
\\[2pc]\hline
\end{tabular}
\end{document}
The result is this:
I have several issues with this.
- Why are the elements of the last column displaced?
I think this might have to do with the [2pc]
I have at the end of the rows, but I'm not sure. The general placement of the graphs isn't centered either, but I've found that alignment in tables is a common issue, and probably the horizontal and vertical alignment of a tikzpicture
has been resolved somewhere (a link to such a place would be appreciated!), so I won't focus on that.
- How could I put in labels in each top left corner of each cell?
I would want each of the labels to be individually editable, with the end result looking something like this (of course, with the graphs centered both vertically and horizontally):
I know that there are several other packages for making tables (and making tables with tikz
seems too cumbersome), but I couldn't decide which one was suited best for this. I've thought of padding the cells instead of centering (a mix of both which I've used here), but again, no one approach solves all my queries. Any and all tips pertaining to these problems are appreciated!