问题

问题

我想要一个时间表如下,

在此处输入图片描述

具有更简单的用户界面,如下所示。

\legend[text="Women class", color=green!50]{w}
\legend[text="University student class", color=blue!50]{us}
\legend[text="Children class", color=yellow!50]{c}
\legend[text="Adult class", color=gray!50]{a}
\legend[text="Remedy class", color=gray]{r}
\begin{schedule}[subdiv=2]% multiple of 30 minute
\day{Mon}
\timeslot{14:00}{15:00}{us}
\timeslot{19:00}{20:30}{a}
\timeslot{20:30}{21:30}{r}
%it is also possible to add 2 or more layers in a day by breaking the line with \\
.
.
.
\day{Tue}
\timeslot{7:00}{8:00}{w}
\timeslot{19:00}{20:30}{a}
\timeslot{20:30}{21:30}{r}
.
.
.
\end{schedule}
  • 图中未使用的时间间隔必须自动修剪。
  • subdiv=n将一小时划分为 n 个子部分,每个部分都是 的倍数60/n
  • 底部的图例被打印成一列或多列,以节省更多空间。
  • 如果一行包含m多个层,则每个条的高度必须等于1/m单层条的高度。需要满足此要求才能使所有行具有相同的空间。

问题

这里有人能帮助我实现上面提到的更简单的用户界面吗?

我的尝试是以下 MWE。

平均能量损失

\documentclass[border=3pt]{standalone}
\usepackage{pgfgantt}
\usepackage{xcolor}

\ganttset{group/.append style={transparent}}

\begin{document}
    \begin{ganttchart}[
     y unit title=0.5cm,
     y unit chart=0.8cm,
     vgrid,hgrid,
     title height=1,
     title label font=\bfseries\footnotesize,
     bar height=0.7,
%   progress label text={},
     group right shift=0,
     group top shift=0.7,
     group height=.3,
     group peaks width={0.5},
     inline]{1}{22}
    %labels
    \gantttitle{7}{2}
    \gantttitle{8}{2}
    \gantttitle{10}{2}
    \gantttitle{11}{2}
    \gantttitle{12}{2}
    \gantttitle{13}{2}
    \gantttitle{14}{2} 
    \gantttitle{15}{2}
        \gantttitle{19}{2}
    \gantttitle{20}{2}
    \gantttitle{21}{2}\\
    % Setting group if any
    \ganttgroup[inline=false]{Mon}{0}{0}
        \ganttbar[bar/.append style={fill=blue!50}]{}{14}{15}
        \ganttbar[bar/.append style={fill=gray!30}]{}{18}{20}
        \ganttbar[bar/.append style={fill=gray}]{}{21}{22}\\

        \ganttgroup[inline=false]{Tue}{0}{0}
        \ganttbar[bar/.append style={fill=green!50}]{}{2}{3}
        \ganttbar[bar/.append style={fill=gray!30}]{}{18}{20}
        \ganttbar[bar/.append style={fill=gray}]{}{21}{22}\\

        \ganttgroup[inline=false]{Wed}{0}{0}
        \ganttbar[bar/.append style={fill=gray!30}]{}{18}{20}
        \ganttbar[bar/.append style={fill=gray}]{}{21}{22}\\

        \ganttgroup[inline=false]{Thu}{0}{0}
        \ganttbar[bar/.append style={fill=green!50}]{}{2}{3}
        \ganttbar[bar/.append style={fill=gray!30}]{}{18}{20}
        \ganttbar[bar/.append style={fill=gray}]{}{21}{22}\\

        \ganttgroup[inline=false]{Fri}{0}{0}
        \ganttbar[bar/.append style={fill=yellow!50}]{}{8}{9}
        \ganttbar[bar/.append style={fill=gray!30}]{}{18}{20}
        \ganttbar[bar/.append style={fill=gray}]{}{21}{22}\\

        \ganttgroup[inline=false]{Sat}{0}{0}
        \ganttbar[bar/.append style={fill=green!50}]{}{2}{3}
        \ganttbar[bar/.append style={fill=blue!50}]{}{14}{15}
        \ganttbar[bar/.append style={fill=gray!30}]{}{18}{20}
        \ganttbar[bar/.append style={fill=gray}]{}{21}{22}\\

        \ganttgroup[inline=false]{Sun}{0}{0}
        \ganttbar[bar/.append style={fill=red!50}]{}{6}{8}
        \ganttbar[bar/.append style={fill=magenta!50}]{}{12}{14}
\end{ganttchart}
%    \caption{Gantt diagram for 2013--2014 Project}
%\end{figure}
\end{document}

答案1

下图由以下用户命令生成;有关包含所有定义的完整代码,请参见下图。

\neweventtype{w}{Women class}{green!50}
\neweventtype{us}{University student class}{blue!50}
\neweventtype{c}{Children class}{yellow!50}
\neweventtype{a}{Adult class}{gray!50}
\neweventtype{r}{Remedy class}{gray}

\begin{schedule}
\sday{Mon}
\event{14:00}{15:00}{us}
\event{19:00}{20:30}{a}\\
\event{20:30}{21:30}{r}
\sday{Tue}
\event{7:00}{8:00}{w}
\event{19:00}{20:30}{a}
\event{20:30}{21:30}{r}
\end{schedule}

\legend

在此处输入图片描述

\documentclass{article}
\usepackage{pgfgantt}

\newcommand\legendentries{}
\makeatletter
\newcommand\neweventtype[3]% \newevent{id}{text}{color}
  {\colorlet{color-#1}{#3}%
   \g@addto@macro\legendentries{\legendentry{#1}{#2}}%
  }
\makeatother
\newcommand\legendentry[2]{\\ \tikz\node[draw,fill=color-#1]{}; & #2}
\newcommand\legend
  {\begin{tabular}{ll}
   \multicolumn{2}{l}{\bfseries Legend:}
   \legendentries
   \end{tabular}%
  }
\newcounter{time}
\newcounter{slot}
\newcommand\shour[2]%
  {\gantttitle{#1}{2}%
   \setcounter{time}{#1}%
   \addtocounter{time}{-1}%
   \setcounter{slot}{#2}%
   \expandafter\edef\csname from\arabic{time}:30\endcsname{\arabic{slot}}%
   \stepcounter{time}%
   \expandafter\edef\csname to\arabic{time}:00\endcsname{\arabic{slot}}%
   \stepcounter{slot}%
   \expandafter\edef\csname from\arabic{time}:00\endcsname{\arabic{slot}}%
   \expandafter\edef\csname to\arabic{time}:30\endcsname{\arabic{slot}}%
  }
\newenvironment{schedule}[1][]%
  {\begin{ganttchart}%
     [y unit title=0.5cm,
      y unit chart=0.8cm,
      vgrid,hgrid,
      title height=1,
      title label font=\bfseries\footnotesize,
      title/.style={draw=none, fill=none},
      bar height=0.7,
      %   progress label text={},
      group right shift=0,
      group top shift=0.7,
      group height=.3,
      group peaks width={0.5},
      inline,
      #1
     ]{1}{22}
     \shour{7}{1}
     \shour{8}{3}
     \shour{10}{5}
     \shour{11}{7}
     \shour{12}{9}
     \shour{13}{11}
     \shour{14}{13}
     \shour{15}{15}
     \shour{19}{17}
     \shour{20}{19}
     \shour{21}{21}
  }%
  {\end{ganttchart}%
  }
\ganttset{group/.append style={transparent}}
\newcommand\sday[1]{\\\ganttgroup[inline=false]{#1}{0}{0}}
\newcommand\event[3]{\ganttbar[bar/.append style={fill=color-#3}]{}{\csname from#1\endcsname}{\csname to#2\endcsname}}


\begin{document}
\neweventtype{w}{Women class}{green!50}
\neweventtype{us}{University student class}{blue!50}
\neweventtype{c}{Children class}{yellow!50}
\neweventtype{a}{Adult class}{gray!50}
\neweventtype{r}{Remedy class}{gray}

\noindent
\begin{schedule}
\sday{Mon}
\event{14:00}{15:00}{us}
\event{19:00}{20:30}{a}\\
\event{20:30}{21:30}{r}
\sday{Tue}
\event{7:00}{8:00}{w}
\event{19:00}{20:30}{a}
\event{20:30}{21:30}{r}
\end{schedule}
\bigskip

\noindent
\legend
\end{document}

相关内容