[Tex/LaTex] Custom vertical lines with pgfgantt (pgf multiplier issues)

pgfganttpgfkeys

I'm having some issues drawing vertical lines in a ganttchart (using the pgfgantt package). The approach is to define the bars in the chart using a dd-mm-yyyy format but only showing the months.

To keep things clear, it would be useful to have vertical (dashed) lines separating the months. I haven't found a way to do this automatically (vgrid draws a line for every single day), so I ended up skipping (month length - 1) lines for every month. The main question would be, is there a better way to get the correct vertical lines?


Second, the MWE below works in a \documentclass[tikz]{standalone} setting but results in an error when used in a \documentclass[a4paper,11pt]{article} setting:

! Package pgfkeys Error: I do not know the key '/tikz/*{30}{draw=none}' and I am going to ignore it. Perhaps you misspelled it.

I'm using pgfgantt version 2013/06/01 v4.0. Do I need to include additional packages, what's going on?

[Edit] This turns out to be a conflict with the amsmath package, see comments below. This is now fixed.


MWE

\documentclass[tikz]{standalone}
\usepackage{pgfgantt}
\begin{document}

\begin{ganttchart}[y unit title=7mm,title height=1,y unit chart=10mm,bar top shift=.2,bar height=.6,bar/.append style={fill=black!10},bar label node/.append style={align=right},progress label text=,hgrid={*1{black!10, dashed}},vgrid={*{29}{draw=none}, dashed, *{30}{draw=none}, dashed, *{30}{draw=none}, dashed, *{27}{draw=none}, dashed, *{30}{draw=none}, dashed, *{29}{draw=none}, dashed, *{30}{draw=none}},x unit=.4mm,time slot format=little-endian]{01-11-2014}{31-05-2015}
\gantttitlecalendar{month=shortname} \\
\ganttbar{Topic I}{16-11-2014}{22-12-2014} 
\ganttbar{}{05-01-2015}{00-02-2015} \ganttnewline
\ganttbar{Topic II}{16-01-2015}{16-05-2015}
\end{ganttchart}

\end{document} 

Best Answer

This is due to the fact that amsmath changes the definition of the macro \@ifstar that pgfgantt uses to read off the style definitions. You can temporarily restore back the original definition of this macro though I haven't tested whether this breaks down anything in anywhere else. Seems working though. Also you might need to do the same to hgrid

\documentclass[tikz]{standalone}
\usepackage{pgfgantt}
\makeatletter
\let\origifstar=\@ifstar
\ganttset{
  vgrid/.code={%
    \begingroup
    \let\@ifstar=\origifstar
    \def\@tempa{#1}%
    \def\@tempb{false}%
    \ifx\@tempa\@tempb%
      \gtt@vgridfalse%
    \else%
      \gtt@vgridtrue%
      \def\@tempb{true}%
      \ifx\@tempa\@tempb%
        \def\gtt@vgridstyle{dotted}%
      \else%
        \def\gtt@vgridstyle{#1}%
      \fi%
    \fi%
    \endgroup
  },%
  vgrid/.default=dotted
}
\makeatother

\usepackage{amsmath}%<---- Delay the amsmath loading

\begin{document}

\begin{ganttchart}[
  y unit title=7mm,
  title height=1,
  y unit chart=10mm,
  bar top shift=.2,
  bar height=.6,
  bar/.append style={fill=black!10},
  bar label node/.append style={align=right},
  progress label text=,hgrid={*1{black!10, dashed}},
  vgrid={ *{29}{draw=none}, dashed, *{30}{draw=none}, dashed, *{30}{draw=none}, dashed, *{27}{draw=none}, dashed, *{30}{draw=none}, dashed,*{29}{draw=none},dashed, *{30}{draw=none}},
  x unit=.4mm,time slot format=little-endian]{01-11-2014}{31-05-2015}
\gantttitlecalendar{month=shortname} \\
\ganttbar{Topic I}{16-11-2014}{22-12-2014} 
\ganttbar{}{05-01-2015}{00-02-2015} \ganttnewline
\ganttbar{Topic II}{16-01-2015}{16-05-2015}
\end{ganttchart}
\end{document}