# Dynamic “expansion” of tikz calendar's cells?

Please, is that possible. Having started with this latex source, i would like to have calendar's cells "expandable" vertically -- please see the picture below.

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

\begin{document}

\def\testmsgShort{Short message}
\def\testmsgLong{Long message for testing purposes}

\begin{tikzpicture}[
every node/.style={
text width=3cm
}]
\calendar [
day list downward,
name=cal,
dates=2011-01-01 to 2011-01-11
]
if (weekend) [black!25];
\node [anchor=base west] at (cal-2011-01-03.base east)
{\textcolor{orange}{\textbf{\testmsgShort}}};
\node [anchor=base west] at (cal-2011-01-09.base east)
{\textcolor{orange}{\textbf{\testmsgLong}}};
\end{tikzpicture}

\end{document}


As you can see, long text nodes are not related to days (at least visually). More naturally would be to see a calendar in a form like a table with "day" and "label" columns. Well, i understand that it's hardly possible with a setup like this, because of calendar is already drawn, "printed out", so new nodes can not expand its "cells".

So, my questions is -- is this "cells expansion" possible with tikz/calendar? If yes -- how? Should i look for any other way? Which one, please?

Update:

Thank you, Jake!

Actually i would like to be possible to "collect" events, like this:

\tikzstyle{red events}=[
execute after day scope=
{
\redevent{2011-01-04}{This is a long event text.}
\redevent{2011-01-07}{Short event!}
}
]

\tikzstyle{blue events}=[
execute after day scope=
{
\blueevent{2011-01-04}{This is another long event text.}
\blueevent{2011-01-08}{Short another}
}
]

% ...
\calendar [
% ...
red events,
blue events
% ...


I am not sure that this is the optimal way to "collect events". Saying "collecting events" i mean that some events may be the same forever (think of birthdays), some others may be movable; i believe it's convenient to separate them and have a possibility to edit-comment-uncomment--etc-etc.

But this does not work with your code (i have overlapping events), and i could not imagine (i have poor tikz imagination so far, sorry), how to make it possible.

One way is, possibly, to define "initial offset" and accumulate it -- but wouldn't it be too expensive to define variables for offsets for whole year?

Is there any other way?

ps. Thank you a lot for your effort, Jake; your answer will be the best one in any case, but i would like to ask for even better solution (if that's possible), anyway .)

-

Okay, here's another attempt: The events are collected in macros that change the new event style:

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{calendar}

\begin{document}

\newcommand\event[2]{
\ifdate{equals=#1} {
% In the following, the event nodes are defined
% The \rule in the node text is necessary to match the "text depth=0.5ex" of the date nodes
\pgftransformxshift{\columnspace}
\node [anchor= north west,text height=1.5ex,
name=txt\pgfcalendarsuggestedname,
text width=3.5cm,event]
{#2\rule[-0.5ex]{0ex}{0ex}};
% Calculate the vertical offset of the southern anchors of the date and event nodes
\pgfextracty{\extray}{\pgfpointdiff
{\pgfpointanchor{txt\pgfcalendarsuggestedname}{south} }
{\pgfpointanchor{\pgfcalendarsuggestedname}{south} }
}
Shift by offset
\pgftransformshift{\pgfpointanchor{txt\pgfcalendarsuggestedname}{south west} }
\pgftransformxshift{-\columnspace}
}{}
}

\newcommand\redevents{
\tikzstyle{event}=[red]
\event{2011-01-04}{This is a very long event text running over three lines.}
\event{2011-01-07}{Short event!}
\event{2011-01-08}{Third of the longish events\ldots}
}
\newcommand\blueevents{
\tikzstyle{event}=[blue]
\event{2011-01-04}{This is another long event text.}
\event{2011-01-08}{Short another}
\event{2011-01-10}{Single blue event}
}

\begin{tikzpicture}

\def\dayyshift{2ex} % Set space between days
\def\columnspace{4pt} % Set extra space between day and event column

\newdimen{\extray} % Define new dimen for calculating vertical offset

\calendar [
name=cal,
dates=2011-01-01 to 2011-01-14,
every day/.style={
anchor=north east,
text depth=0.5ex,
text height=1.5ex,
text width=.3cm,
align=right},
execute after day scope=
{
\extray=0pt
\pgftransformshift{\pgfpointanchor{\pgfcalendarsuggestedname}{north east}}
%
\redevents
\blueevents
%
% Draw separator only if day of month is not 1
\ifdate {day of month=1} {}{\draw [gray] (\pgfcalendarsuggestedname.north west) ++(90:3pt) -- +(0:4cm);}
% Shift coordinate system to next date
\pgftransformshift{\pgfpointanchor{\pgfcalendarsuggestedname}{base east}}
\pgftransformyshift{-\extray}
\pgftransformyshift{-\dayyshift}
}
]
if (weekend) [gray!75];
\end{tikzpicture}
\end{document}


-
Thank you a lot, indeed! Please, could you take a look, i've updated my question. Thank you! –  brownian Jan 31 '11 at 8:41
Great! Well, my tikz misplaces hrules (img155.imageshack.us/img155/6037/testhg.png) and claims he doesn't know what's "align" (! Package pgfkeys Error: I do not know the key '/tikz/align' and I am going to ignore it. Perhaps you misspelled it.) -- but i believe it's my local problem. So, for now it is GREAT, thank you! –  brownian Jan 31 '11 at 14:56
@brownian: You need to update your PGF installation, see this question –  Jake Jan 31 '11 at 15:19
I have a question about node alignment. If I wanted to put a red circle around every Wednesday, I would normally do a "every day/.style={anchor=mid}", but this example relies on the "base east" anchor. How could I change this code to make this work? –  macmadness86 Aug 4 '12 at 14:09