6

I am using the package pgfgantt to create a table displaying people serving on a committee over a period of time. (Probably not what it was intended for but it produced a nice output for what I wanted.) The one issue I have run into was that I want the make the headings/title look like they would in my other tables. What I mean is that the "main" \gantttitle would have a \toprule etc. and the bottom of the table would have a \bottomrule. I have tried entering this type of code into the ganttchart but it won't compile.

I have a MWE that has a the Gantt Chart as I have it set up (but with some irrelevant fun data in it) and a smaller table to show the format I hope to be able to put on the chart.

\documentclass[a4paper]{memoir}
\usepackage{libertine}
\usepackage{pgfgantt}
\usepackage[graphicx]{realboxes}

\begin{document}

\begin{table}
\centering
\caption{Members of the Intergalactic committee}
\label{IGC-Mem}
\resizebox{\textwidth}{!}{
\begin{ganttchart}[y unit title=0.65cm,y unit chart=0.80cm,vgrid={draw=none, draw=none, dotted},title height=1.00,bar/.append style={fill=gray!30},bar height=0.50,canvas/.style=%
{shape=rectangle, draw=black, dotted}]{1}{21}
\gantttitle{Members of IGC by delegation}{21}\\
\gantttitle{2525}{3} 
\gantttitle{2526}{3} 
\gantttitle{2527}{3} 
\gantttitle{2528}{3} 
\gantttitle{2529}{3} 
\gantttitle{2530}{3}
\gantttitle{2531}{3}\\
%Member Details
\ganttbar{The Federation}{1}{1}
\ganttbar[inline]{Capt. Kirk}{1}{6}
\ganttbar[inline]{Mr.~ Spock}{7}{21} \\
\ganttbar{The Empire}{1}{1} 
\ganttbar[inline]{Darth Vader}{1}{7}\\
\ganttbar{The Republic}{21}{21}
\ganttbar[inline]{Princess Leia}{8}{17}
\ganttbar[inline]{Han Solo}{18}{21}\\
\ganttbar{Earth}{1}{1}
\ganttbar[inline]{Buck Rodgers}{1}{21}\\
\ganttbar{Red Dwarf}{1}{1}
\ganttbar[inline]{D. Lister}{1}{3}
\ganttbar[inline]{A. Rimmer}{4}{9}
\ganttbar[inline]{Kryten}{10}{21}\\
\ganttbar{Romulan}{1}{1}
\ganttbar[inline]{Vreenak}{1}{21}\\
\ganttbar{Imaginationland}{21}{21}
\ganttbar[inline]{Leopold "Butters" Stotch}{12}{21}
\end{ganttchart}
}
\hrulefill
\end{table}

\begin{table}
\centering
\caption{Members of the Intergalactic committee}
\label{IGC-Mem1}
\resizebox{\textwidth}{!}{%
\begin{tabular}{@{}llllllll@{}}
\toprule
\multicolumn{8}{c}{\textbf{Members of the IGC by delegation}}                                                                                                                                                                                                                                                                                  \\ \midrule
                                & \multicolumn{1}{c}{{2525}} & \multicolumn{1}{c}{{2526}} & \multicolumn{1}{c}{{2527}} & \multicolumn{1}{c}{{2528}} & \multicolumn{1}{c}{{2529}} & \multicolumn{1}{c}{{2530}} & \multicolumn{1}{c}{{2531}} \\
\multicolumn{1}{l|}{The Federation} & \multicolumn{2}{c|}{Capt. Kirk}                         & \multicolumn{5}{c|}{Mr. Spock}                                                                                                             \\ \cline{2-8} 
\multicolumn{1}{l|}{The Empire}        & \multicolumn{5}{c|}{Darth Vader}                                                                                                                                     \\ \cline{2-8} 
\multicolumn{1}{l|}{Earth}         & \multicolumn{7}{c|}{Buck Rodgers}                                                                                                                                                                                                    \\ \cline{2-8}  \bottomrule
\end{tabular}
}
\end{table}

\end{document}

I tried editing the Canvas in the ganttchart settings but that has only got me as far as what is in the MWE above. If you need any more info please let me know in the comments. Effectively what I would like is the main heading in the Gantt Chart to look like a table heading.

  • Probably a naïve question, but why not use a table if you want it to look like one? – cfr Aug 15 '15 at 21:12
  • @cfr Prefer the look of the gantt chart body. Just wanted to see if could get \toperule etc look in it to match other table headings. – gman Aug 15 '15 at 21:18
  • Package tikz-timing does something similar. – Symbol 1 Aug 17 '15 at 6:01
4

Here's one possibility; you first box the Gantt chart and then place it inside a TikZ named \node; using \draw and the node anchors you can now easily place the rules. \heaverulewidth for line width gives the thickness of \toprule and \bottomrule, and \lightrulewidth gives the one from \midrule; I also set inner xsep to \tabcolsep to have the usual horizontal padding for the contents of a table (you can set it to 0pt if you want to).

enter image description here

The code:

\documentclass[a4paper]{memoir}
\usepackage{libertine}
\usepackage{pgfgantt}
\usepackage[graphicx]{realboxes}

\newsavebox\mybox
\begin{lrbox}{\mybox}
\begin{ganttchart}[
  y unit title=0.65cm,
  y unit chart=0.80cm,
  vgrid={
    draw=none, 
    draw=none, 
    dotted
  },
  title height=1.00,
  bar/.append style={fill=gray!30},
  bar height=0.50,
  canvas/.style={
    shape=rectangle, 
    draw=none
    },
    title/.style={draw=none}
]{1}{21}
\gantttitle{Members of IGC by delegation}{21}\\
\gantttitle{2525}{3} 
\gantttitle{2526}{3} 
\gantttitle{2527}{3} 
\gantttitle{2528}{3} 
\gantttitle{2529}{3} 
\gantttitle{2530}{3}
\gantttitle{2531}{3}\\
%Member Details
\ganttbar{The Federation}{1}{1}
\ganttbar[inline]{Capt. Kirk}{1}{6}
\ganttbar[inline]{Mr.~ Spock}{7}{21} \\
\ganttbar{The Empire}{1}{1} 
\ganttbar[inline]{Darth Vader}{1}{7}\\
\ganttbar{The Republic}{21}{21}
\ganttbar[inline]{Princess Leia}{8}{17}
\ganttbar[inline]{Han Solo}{18}{21}\\
\ganttbar{Earth}{1}{1}
\ganttbar[inline]{Buck Rodgers}{1}{21}\\
\ganttbar{Red Dwarf}{1}{1}
\ganttbar[inline]{D. Lister}{1}{3}
\ganttbar[inline]{A. Rimmer}{4}{9}
\ganttbar[inline]{Kryten}{10}{21}\\
\ganttbar{Romulan}{1}{1}
\ganttbar[inline]{Vreenak}{1}{21}\\
\ganttbar{Imaginationland}{21}{21}
\ganttbar[inline]{Leopold "Butters" Stotch}{12}{21}
\end{ganttchart}
\end{lrbox}

\begin{document}

\begin{table}
\centering
\caption{Members of the Intergalactic committee}
\label{IGC-Mem}
\begin{tikzpicture}
\node[inner ysep=0pt,outer sep=0pt,inner xsep=\tabcolsep]
  (gantt)
  {\resizebox{\textwidth}{!}{\usebox\mybox}};
\draw[line width=\heavyrulewidth] 
  (gantt.north west) -- (gantt.north east);
\draw[line width=\lightrulewidth] 
  ([yshift=-17pt]gantt.north west) -- ([yshift=-17pt]gantt.north east);
\draw[line width=\heavyrulewidth] 
  (gantt.south west) -- (gantt.south east);
\end{tikzpicture}
\end{table}

\end{document}

A variation on the same idea, but this time just the midlle rule is \drawn:

\documentclass[a4paper]{memoir}
\usepackage{libertine}
\usepackage{pgfgantt}
\usepackage[graphicx]{realboxes}

\newsavebox\mybox
\begin{lrbox}{\mybox}
\begin{ganttchart}[
  y unit title=0.65cm,
  y unit chart=0.80cm,
  vgrid={
    draw=none, 
    draw=none, 
    dotted
  },
  title height=1.00,
  bar/.append style={fill=gray!30},
  bar height=0.50,
  canvas/.style={
    shape=rectangle, 
    draw=none
    },
    title/.style={draw=none}
]{1}{21}
\gantttitle{Members of IGC by delegation}{21}\\
\gantttitle{2525}{3} 
\gantttitle{2526}{3} 
\gantttitle{2527}{3} 
\gantttitle{2528}{3} 
\gantttitle{2529}{3} 
\gantttitle{2530}{3}
\gantttitle{2531}{3}\\
%Member Details
\ganttbar{The Federation}{1}{1}
\ganttbar[inline]{Capt. Kirk}{1}{6}
\ganttbar[inline]{Mr.~ Spock}{7}{21} \\
\ganttbar{The Empire}{1}{1} 
\ganttbar[inline]{Darth Vader}{1}{7}\\
\ganttbar{The Republic}{21}{21}
\ganttbar[inline]{Princess Leia}{8}{17}
\ganttbar[inline]{Han Solo}{18}{21}\\
\ganttbar{Earth}{1}{1}
\ganttbar[inline]{Buck Rodgers}{1}{21}\\
\ganttbar{Red Dwarf}{1}{1}
\ganttbar[inline]{D. Lister}{1}{3}
\ganttbar[inline]{A. Rimmer}{4}{9}
\ganttbar[inline]{Kryten}{10}{21}\\
\ganttbar{Romulan}{1}{1}
\ganttbar[inline]{Vreenak}{1}{21}\\
\ganttbar{Imaginationland}{21}{21}
\ganttbar[inline]{Leopold "Butters" Stotch}{12}{21}
\end{ganttchart}
\end{lrbox}

\begin{document}

\begin{table}
\centering
\caption{Members of the Intergalactic committee}
\label{IGC-Mem}
\tikz{
  \node[inner sep=0pt,outer sep=0pt] (gantt)
  {\begin{tabular}{c}
    \toprule
    \resizebox{\textwidth}{!}{\usebox\mybox} \\
    \bottomrule
   \end{tabular}%
   };
  \draw[line width=\lightrulewidth]
    ([yshift=-19pt]gantt.north west) -- ([yshift=-19pt]gantt.north east);
}   
\end{table}

\end{document}
  • +1 looks great. Just showing my lack of knowledge :-) but why is it required to put the gantt table in the preamble? – gman Aug 17 '15 at 9:39
  • 1
    @gman It's not required to put it in the preamble; the important thing is to box it and this can be done either in the preamble or in the document body; since pgfgantt internally uses a tikzpicture, what we are really doing is to nest tikzpictures and this is something that might produce undesired results (although perhaps not in such a simple case as this one), so it's a good precaution in any case to first box the Gantt table. – Gonzalo Medina Aug 17 '15 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.