pgfgantt - 不同风格的里程碑

pgfgantt - 不同风格的里程碑

我可以在一张甘特图中显示两组里程碑吗?每组里程碑的样式都不同(例如颜色、形状等)?

答案1

您可以使用通常的pgf样式机制来设置不同的样式,这里Mile1Mile2,您可以将其传递给可选参数\ganttmilestone

示例输出

\documentclass{article}

\usepackage{pgfgantt}

\begin{document}
\begin{ganttchart}[Mile1/.style={milestone/.append style={fill=red}},
  Mile2/.style={milestone/.append style={fill=blue,shape=rectangle}}]{1}{12}
  \gantttitle{2011}{12} \\
  \gantttitlelist{1,...,12}{1} \\
  \ganttgroup{Group 1}{1}{7} \\
  \ganttbar{Task 1}{1}{2} \\
  \ganttlinkedbar{Task 2}{3}{7}
  \ganttnewline
  \ganttmilestone[Mile1]{Milestone}{7}
  \ganttnewline
  \ganttbar{Final Task}{8}{12}
  \ganttlink{elem2}{elem3}
  \ganttlink{elem3}{elem4}
  \ganttnewline
  \ganttmilestone[Mile2]{Milestone}{10}
  \ganttnewline
  \ganttmilestone[Mile1]{Milestone}{12}
\end{ganttchart}
\end{document}

答案2

当然可以。您可以使用带星号的版本\newganttchartelement。请参阅2.7 定义自定义图表元素包文档。下面是一个定义第二种里程碑的小例子,我mymilestone用不同的形状、颜色和字体来称呼它:

\documentclass{article}
\usepackage{pgfgantt}

\newganttchartelement*{mymilestone}{
mymilestone/.style={
  shape=isosceles triangle,
  inner sep=0pt,
  draw=cyan,
  top color=white,
  bottom color=cyan!50
  },
mymilestone incomplete/.style={
  /pgfgantt/mymilestone,
  draw=yellow,
  bottom color=yellow!50
  },
mymilestone label font=\slshape,
mymilestone left shift=0pt,
mymilestone right shift=0pt
}

\begin{document}

\begin{ganttchart}[
  milestone/.append style={fill=orange}]{1}{12}
\gantttitle{2011}{12} \\
\gantttitlelist{1,...,12}{1} \\
\ganttgroup{Group 1}{1}{7} \\
\ganttbar{Task 1}{1}{2} \\
\ganttlinkedbar{Task 2}{3}{7} \ganttnewline
\ganttmilestone{Milestone}{7} \ganttnewline
\ganttmymilestone{New milestone}{8} \ganttnewline
\ganttbar{Final Task}{9}{12}
\ganttlink{elem2}{elem3}
\ganttlink{elem3}{elem4}
\ganttlink{elem4}{elem5}
\end{ganttchart}

\end{document}

在此处输入图片描述

答案3

使用 Fontawesome 5 符号作为里程碑

\documentclass[margin=1cm]{standalone}
\usepackage{pgfgantt}
\usepackage{fontawesome5}

\newganttchartelement*{checkin}{
  checkin/.style={font={\faSignIn*}}
}

\newganttchartelement*{checkout}{
  checkout/.style={font={\faSignOut*}}
}

\begin{document}
  \begin{ganttchart}{1}{12}
    \gantttitle{2022}{12} \\
    \gantttitlelist{1,...,12}{1} \\
    \ganttgroup{Group 1}{1}{7} \\
    \ganttbar{Task 1}{1}{2} \\
    \ganttlinkedbar{Task 2}{3}{7} \ganttnewline
    \ganttcheckin{}{4}
    \ganttmilestone{Milestone}{7}
    \ganttcheckout{}{10}\ganttnewline
    \ganttbar{Final Task}{8}{12}
    \ganttlink{elem2}{elem3}
    \ganttlink{elem3}{elem6}
  \end{ganttchart}
\end{document}

在此处输入图片描述

笔记

  • LaTeX 包fontawesome5通过单个符号名称提供符号(在示例中\faIcon{sign-in-alt} or \faSignIn*)。fontawesome.com您可能会遇到无法使用的别名。因为sign-in-alt存在别名right-to-bracket。首先检查 LaTeX 包的文档,以明确在遇到如下错误时可以在 LaTeX 中使用哪一个:

    Package fontawesome5 Error: The requested icon right-to-bracket was not found.
    
  • 另一个原因可能是该符号是在后来的版本中添加的。

相关内容