Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to insert a multirow in a tikz matrix with a grid, so:

\documentclass{amsart} 
\usepackage{tikz}
\usetikzlibrary{matrix,fit}

\begin{document} 
\begin{tikzpicture}
\matrix (table) [%
  matrix of nodes,
  nodes in empty cells,
  draw,
  inner sep=0mm,
  minimum size=7mm
  ] {%
  \node[draw] {A}; & \node[draw] {B}; & \node[draw] {C}; & \node[draw] {D}; \\
  \node[draw] {E}; &   &   & \node[draw] {G}; \\   };
\node[draw,fit=(table-2-2)(table-2-3)]{F};
\end{tikzpicture}
\end{document}

With ugly results. Is there a way to fix this? A better way to implement it? Thanks.

share|improve this question

1 Answer 1

You have better control over the borders of your cells if you explicitly set the text height and depth. Furthermore, I would use styles to keep the code more maintainable. Here's an example of how your table could be implemented, based on the code used in " coloring every other row of a table, with vertical lines ".

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,fit}
\begin{document}

\tikzset{
    table nodes/.style={
        rectangle,
        draw=black,
        align=center,
        minimum height=7mm,
        text depth=0.5ex,
        text height=2ex,
        inner xsep=0pt,
        outer sep=0pt
    },      
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={
            table nodes
        },
        execute at empty cell={\node[draw=none]{};}
    }
}
\begin{tikzpicture}

\matrix (first) [table,text width=7mm,name=table]
{
A   & B & C & D\\
E   &   &   & F\\
};
\node[draw,fit=(table-2-2)(table-2-3),table nodes]{F};


\end{tikzpicture}
\end{document}

table with tikz

share|improve this answer
    
Can TikZ tables work like longtable which can span across pages? –  xport Jul 10 '11 at 5:04
2  
@xport: I don't think tikzpicture environments can span across pages, so TikZ matrices can't either. They're really not meant as a replacement for real LaTeX tables anyway, so you shouldn't expect too much from this approach. It can be useful if you're trying to do something special, most likely if you also need to place other TikZ elements. –  Jake Jul 10 '11 at 5:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.