# How to extend the table when text longer then the size of a cell is inserted?

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

\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={
rectangle,
draw=black,
align=center
},
minimum height=1.5em,
text depth=0.5ex,
text height=2ex,
nodes in empty cells,
%%
every even row/.style={
nodes={fill=gray!20}
},
column 1/.style={
nodes={text width=2em,font=\bfseries}
},
row 1/.style={
nodes={
fill=black,
text=white,
font=\bfseries
}
}
}
}

\begin{tikzpicture}

\matrix (first) [table,text width=6em]
{
& Monday   & Tuesday & Wednesday & Thursday & Friday\\
1   & A & B & C & D & E \\
2   & F & G & H & J & K \\
3   & A & B & C & D & E \\
4   & F & G & H & J & K \\
};

\end{tikzpicture}
\end{document}


What if I write to the first cell 'Monday is the first day of the day' instead of just monday?

I want the cell to adapt vertically, increasing the height of the whole row, to accomodate the text

How to do that?

-
You mean the linebreaks are added or the cell width is increased? –  percusse Mar 5 '13 at 10:03
the extra text that would exceed the cell width simply doesnt show up...I want the extra text to automatically go to a new newline. –  user494461 Mar 5 '13 at 11:03

## 1 Answer

Here is a not-so-manual approach by just deciding on how many lines the largest test will cover in the first row and adjusting the row height accordingly

 \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\tikzset{
table/.style={
matrix of nodes,
nodes in empty cells,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={
rectangle,
draw=black,
minimum width=6em,
},
every even row/.style={
nodes={fill=gray!20}
},
row 1/.style={
nodes={draw,
fill=black,
text=white,
font=\bfseries,
align=center,
anchor=center,
minimum height=9ex, % Roughly 3ex for each line break
inner sep=0,
},
},
column 1/.style={
nodes={minimum width=2em,font=\bfseries},
},
row 1 column 6/.style={text width=4em,align=center,} % Align the width of the cell
}
}

\begin{document}
\begin{tikzpicture}
\matrix (first) [table]
{
& Monday   & Tuesday & Wednesday & Thursday & Friday I'm in love\\
1   & A & B & C & D & E \\
2   & F & G & H & J & K \\
3   & A & B & C & D & E \\
4   & F & G & H & J & K \\
};
\end{tikzpicture}
\end{document}


Sorry, The Cure is playing on the radio.

-