I want to create a table with arrows between some cells, for which I've used tabularx
and TkiZ. I have the following problems:
- Text in cells aligned vertically to the center and at the same heigh (TikZ nodes are not inline with normal cells text in a same row).
- Inability to align to the center with
\begin{center}•\end{center}
. - I don't know how to fix the size of the cells.
This is what I currently have:
Code
\documentclass{article}
\usepackage{tabularx}
\usepackage{tikz}
\tikzset{every picture/.style={remember picture}}
\begin{document}
\begin{tabularx}{\textwidth}{r|c|c|c|c|l}
&$D_1$&$D_2$&$D_3$&$D_4$&foo\\ \cline{1-6}
$O_1$&\tikz[baseline]{\node (a11) {50};}&\tikz[baseline]{\node (a12) {0};}&&&50\\[2em] \cline{1-6}
$O_2$&&\tikz[baseline]{\node (a22) {60};}&&&60\\[2em] \cline{1-6}
$O_3$&&\tikz[baseline]{\node (a32) {10};}&\tikz[baseline]{\node (a33) {30};}&\tikz[baseline]{\node (a34) {10};}&50\\[2em] \cline{1-6}
$O_4$&&&&\tikz[baseline]{\node (a44) {50};}&50\\[2em] \cline{1-6}
bar&50&70&30&60&210\\
\end{tabularx}
\begin{tikzpicture}[overlay]
\path[thick,->] (a11) edge (a12);
\path[thick,->] (a12) edge (a22);
\path[thick,->] (a22) edge (a32);
\path[thick,->] (a32) edge (a33);
\path[thick,->] (a33) edge (a34);
\path[thick,->] (a34) edge (a44);
\end{tikzpicture}
\end{document}
Besides, I get the following warnings:
Underfull
\hbox
(badness 10000) in alignment at lines 13–13Overfull
\hbox
(15.0pt too wide) in paragraph at lines 13–22
Best Answer
Another possible solution where the OP code is used but slightly modified. The underfull problem is taken care by adding an X column in the last column so that
\textwidth
is satisfied.The OP's
tikz
struture in the cell is redefined astikzmark
taking two arguments. and connected by\link
macro.Create a new column type M with horizontal and vertical centering:
Code