# Remove inner row separators of a matrix

I have the following code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[cell/.style={rectangle,draw=black}, nodes in empty cells]
\matrix[
matrix of math nodes,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
nodes={anchor=center, minimum width=2cm, cell},
column 1/.style = {nodes={minimum width=2cm}},
row 1/.style = {nodes={text height=1.3ex, text depth=0}},
row 2/.style = {text height=1.3ex, text depth=0},
row 3/.style = {text height=1.3ex, text depth=0},
row 4/.style = {text height=1.3ex, text depth=0},
row 5/.style = {text height=1.3ex, text depth=0},
row 6/.style = {text height=1.3ex, text depth=0},
] (m)
{ \\
\\
\\
i \mapsto 5 \\
\\
\\
};
\end{tikzpicture}

It produces this matrix:

Does anyone know how to remove all the inner row separators (or color them white to do not change the height)? I just want to keep the text surrounded by the big rectangle.

Edit 1:

I followed the first solution of the first comment (remove draw from the cell style options and use it for the \matrix), and tried to fill it with color by changing to column 1/.style = {nodes={minimum width=2cm, fill=purple}},, it shows the follows. However, I would like the background color to fill the entire rectangle.

The reason why I insist using matrix for this, is because this tikz picture will be aligned with other pictures having matrix (6 rows, height=1.3ex). I want them to have the same height. That's why I think maybe changing the color of row separators to white may be a good solution...

Edit 2:

I think I need to make my need clearer... Here is the code which produces 2 matrixes side by side. The matrix on the left side is a reference matrix; the one on the right side follows the solution of the first comment. I just want to make them to have the same height: one has inner row separates, the other does not have them and is filled by purple.

\begin{frame}
\begin{tikzpicture}[cell/.style={rectangle,draw=black}, nodes in empty cells]
\matrix[
matrix of math nodes,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
nodes={anchor=center, minimum width=2cm, cell},
column 1/.style = {nodes={minimum width=1.5cm}},
row 1/.style = {nodes={text height=1.3ex, text depth=0}},
row 2/.style = {text height=1.3ex, text depth=0},
row 3/.style = {text height=1.3ex, text depth=0},
row 4/.style = {text height=1.3ex, text depth=0},
row 5/.style = {text height=1.3ex, text depth=0},
] (m)
{ \\ \\ i \mapsto 5 \\ \\ \\ };
\end{tikzpicture}
\begin{tikzpicture}[cell/.style={rectangle}, nodes in empty cells]
\matrix[
matrix,
fill=purple,
matrix of math nodes,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
nodes={anchor=center, minimum width=2cm, cell},
column 1/.style = {nodes={minimum width=1.5cm}},
row 1/.style = {nodes={text height=1.3ex, text depth=0}},
row 2/.style = {text height=1.3ex, text depth=0},
row 3/.style = {text height=1.3ex, text depth=0},
row 4/.style = {text height=1.3ex, text depth=0},
row 5/.style = {text height=1.3ex, text depth=0},
] (m)
{ \\ \\ i \mapsto 5 \\ \\ \\ };
\end{tikzpicture}
\end{frame}

• Isn't it just a rectangle with some text inside it, then? – egreg Sep 12 '15 at 21:47
• Yes... Because I will align this picture with other pictures holding matrix, I want to make it a matrix... – SoftTimur Sep 12 '15 at 21:49

## 1 Answer

You can remove draw from the cell style options and use it for the \matrix (see below); however, using this for this seems like an overkill since a simple \node does the same job with much less effort as also shown below:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[cell/.style={rectangle}, nodes in empty cells]
\matrix[
draw,
matrix of math nodes,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
nodes={anchor=center, minimum width=2cm, cell},
column 1/.style = {nodes={minimum width=2cm}},
row 1/.style = {nodes={text height=1.3ex, text depth=0}},
row 2/.style = {text height=1.3ex, text depth=0},
row 3/.style = {text height=1.3ex, text depth=0},
row 4/.style = {text height=1.3ex, text depth=0},
row 5/.style = {text height=1.3ex, text depth=0},
row 6/.style = {text height=1.3ex, text depth=0},
] (m)
{ \\
\\
\\
i \mapsto 5 \\
\\
\\
};
\end{tikzpicture}

\begin{tikzpicture}[cell/.style={rectangle}, nodes in empty cells]
\node[
draw,
text width=2cm,minimum height=3cm,align=center] (m)
{$i \mapsto 5$};
\end{tikzpicture}

\end{document}

## Update:

Kill the inner sep for the \matrix but keep it for the nodes inside:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}

\colorlet{mycolor}{gray!10}

\begin{document}

\begin{frame}

\begin{tikzpicture}[cell/.style={rectangle,draw=black}, nodes in empty cells,baseline]
\matrix[
matrix of math nodes,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
nodes={anchor=center,cell},
column 1/.style = {nodes={minimum width=1.5cm}},
row 1/.style = {nodes={text height=1.3ex, text depth=0}},
row 2/.style = {text height=1.3ex, text depth=0},
row 3/.style = {text height=1.3ex, text depth=0},
row 4/.style = {text height=1.3ex, text depth=0},
row 5/.style = {text height=1.3ex, text depth=0},
] (m)
{ \\ \\ i \mapsto 5 \\ \\ \\ };
\end{tikzpicture}
\begin{tikzpicture}[cell/.style={rectangle,inner sep=0.3333em,draw},nodes in empty cells,baseline]
\matrix[
matrix,
nodes={anchor=center, minimum width=2cm, cell},
inner sep=0em,
fill=purple,
matrix of math nodes,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
column 1/.style = {nodes={minimum width=1.5cm}},
row 1/.style = {nodes={text height=1.3ex, text depth=0}},
row 2/.style = {text height=1.3ex, text depth=0},
row 3/.style = {text height=1.3ex, text depth=0},
row 4/.style = {text height=1.3ex, text depth=0},
row 5/.style = {text height=1.3ex, text depth=0},
] (m)
{ \\ \\ i \mapsto 5 \\ \\ \\ };
\end{tikzpicture}
\end{frame}

\end{document}

• @SoftTimur Again, use fill=purple for the \matrix, not for the nodes: \matrix[ draw, fill=purple,... – Gonzalo Medina Sep 12 '15 at 22:16
• Thank you... I edited my OP once again, hope my need is clearer now... – SoftTimur Sep 12 '15 at 22:58
• @SoftTimur Please see my updated answer. – Gonzalo Medina Sep 12 '15 at 23:24