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.

Creating a Gantt chart using the pgfgantt package, with days of the weeks as the titles, can be done using title list options as demonstrated in the package manual. But it doesn't seem to agree with beamer:

\documentclass{beamer}
%\documentclass{article}
\usepackage{pgfgantt}
\usepackage{pgfcalendar}

\begin{document}

\begin{frame}
\begin{ganttchart}[x unit = 3em]{7}
\gantttitlelist[title list options={var=\y, evaluate=\y as \x using "\pgfcalendarweekdayshortname{\y}"}]{0,...,6}{1}\\
\end{ganttchart}
\end{frame}

\end{document}

Error message:

! Use of \\gantttitlelist doesn't match its definition.
\kernel@ifnextchar ...rved@d =#1\def \reserved@a {
                                                  #2}\def \reserved@b {#3}\f...
l.11 \end{frame}

? x

Is there any workarounds?

share|improve this question
    
@percusse Very succinct solution! I think that deserves to be made into an answer. –  LianTze Lim Dec 8 '12 at 15:10
    
cybersingularity kindly agreed to add the missing details for me. –  percusse Dec 8 '12 at 21:26
    
@percusse cybersingularity Excellent, thank you both. –  LianTze Lim Dec 9 '12 at 14:25

1 Answer 1

up vote 5 down vote accepted

The same problem occurs using the article class with the translator package, the latter being loaded by beamer.

The macro \pgfcalendarweekdayshortname wraps its output in a \translate, which with translator's definition, does not appear to be safe in an expansion only context, the latter being the context in which evaluate for \foreach is executed.

There are a number of workarounds. Here's a couple:

  • The simplest, suggested by percusse, is to add \noexpand before \pgfcalendarweekdayshortname.

  • Alternatively (my original answer), one can reset \translate to behave like \@firstofone, which is what pgfcalendar sets it up to be when the translator package is not loaded (modulo \long).

    Workaround code in the context of the MWE:

    \documentclass{beamer}
    %\documentclass{article}
    %\usepackage{translator}
    \usepackage{pgfgantt}
    \usepackage{pgfcalendar}
    
    % by putting \resettranslate in a macro, we avoid issues with directly placing a \renewcommand or \makeatletter in beamer's frame environment
    \makeatletter
    \newcommand{\resettranslate}{\let\translate\@firstofone}
    \makeatother
    
    \begin{document}
    
    
    \begin{frame}
    \begin{ganttchart}[x unit = 3em]{7}
    \resettranslate
    \gantttitlelist[title list options={var=\y, evaluate=\y as \x using "\pgfcalendarweekdayshortname{\y}"}]{0,...,6}{1}\\
    \end{ganttchart}
    \end{frame}
    
    \end{document}
    

    For clarity, I have kept the patch local within the ganttchart environment. This means one needs the patch for every ganttchart environment unless one is prepared to change \translate document-wide (e.g. by executing \resettranslate immediately after its definition).

share|improve this answer

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.