1. MEW 解决方案

1. MEW 解决方案

我只想增加节点标签和甘特图开头之间的空间。它只需要足够大,这样第一个就不会与里程碑重叠。有什么想法可以做到这一点吗?我仍然希望文本右对齐。

甘特图

编辑:抱歉,我应该附上我的代码来制作这个图表。如下:

\begin{ganttchart}[ 
vgrid={{Gray}},
time slot format= {isodate},
x unit = 0.8cm,
y unit title = 0.6cm,
y unit chart = 0.6cm,
compress calendar,
bar label node/.style={text width=6cm,align=right,font=\RaggedLeft, anchor=east},
milestone label node/.style={text width=6cm,align=right,font=\RaggedLeft, anchor=east},
group label node/.style={text width=6cm,align=right,font=\RaggedLeft, anchor=east},
%FlonLon suggstion tried here] 
{2018-12-01}{2019-12-31}
\gantttitlecalendar{year, month=shortname} \\
\ganttmilestone[milestone/.append style={fill=gray!50}]{Proposal decision}{2018-11-30} \\ %0
\ganttbar[bar/.append style={fill=red!90}]{Potential proposal amendments}{2018-12-10}{2018-12-21} \\ %1
\ganttbar[bar/.append style={fill=red!90}]{Travel \& accommodation research}{2019-01-01}{2019-02-28} \\ %2
\ganttmilestone[milestone/.append style={fill=gray!50}]{Travel \& accommodation booking deadline}{2019-02-28} \\ %3
\ganttbar[bar/.append style={fill=orange!90}]{Background theory reading}{2019-03-01}{2019-06-30} \\ %4
\ganttbar[bar/.append style={fill=orange!90}]{Final admin (insurance, accounts etc.)}{2019-06-01}{2019-06-30} \\ %5     
\ganttgroup[group/.append style={fill=blue!90}]{\textbf{IPP, Prague}}{2019-07-01}{2019-09-30} \\ %6
\ganttmilestone[milestone/.append style={fill=gray!50}]{Sandpit event}{2019-09-01} \\ %7
\ganttbar[bar/.append style={fill=OliveGreen}]{Writing project up}{2019-10-07}{2019-11-31} \\ %8
\ganttlink{elem1}{elem2}
\ganttlink{elem2}{elem3}
\ganttlink{elem3}{elem4}
\ganttlink{elem4}{elem6}
\ganttlink{elem5}{elem6}
\ganttlink{elem6}{elem8}
\end{ganttchart}

@FlonLon,我尝试了你的修复方法,但没有效果。我猜是因为我还使用了压缩日历或声明了有关节点的其他内容?

答案1

我将anchor=east在标签节点样式中用left=7pt(或其他距离,根据需要进行调整)进行替换。

我还建议为不同标签节点样式中的所有常用选项定义一种样式。例如添加

\tikzset{
  labelnodes/.style={text width=6cm,align=right,font=\RaggedLeft, left=7pt}
}

然后使用

bar label node/.style={labelnodes},
milestone label node/.style={labelnodes},
group label node/.style={labelnodes},

如果您对这三者之一有特定的选择,只需将其添加到之后即可labelnodes

在此处输入图片描述

\documentclass[border=5mm,dvipsnames]{standalone}
\usepackage{pgfgantt,ragged2e}
\tikzset{
  labelnodes/.style={text width=6cm,align=right,font=\RaggedLeft, left=7pt}
}
\begin{document}
\begin{ganttchart}[ 
vgrid={{Gray}},
time slot format= {isodate},
x unit = 0.8cm,
y unit title = 0.6cm,
y unit chart = 0.6cm,
compress calendar,
bar label node/.style={labelnodes},
milestone label node/.style={labelnodes},
group label node/.style={labelnodes},
] 
{2018-12-01}{2019-12-31}
\gantttitlecalendar{year, month=shortname} \\
\ganttmilestone[milestone/.append style={fill=gray!50}]{Proposal decision}{2018-11-30} \\ %0
\ganttbar[bar/.append style={fill=red!90}]{Potential proposal amendments}{2018-12-10}{2018-12-21} \\ %1
\ganttbar[bar/.append style={fill=red!90}]{Travel \& accommodation research}{2019-01-01}{2019-02-28} \\ %2
\ganttmilestone[milestone/.append style={fill=gray!50}]{Travel \& accommodation booking deadline}{2019-02-28} \\ %3
\ganttbar[bar/.append style={fill=orange!90}]{Background theory reading}{2019-03-01}{2019-06-30} \\ %4
\ganttbar[bar/.append style={fill=orange!90}]{Final admin (insurance, accounts etc.)}{2019-06-01}{2019-06-30} \\ %5     
\ganttgroup[group/.append style={fill=blue!90}]{\textbf{IPP, Prague}}{2019-07-01}{2019-09-30} \\ %6
\ganttmilestone[milestone/.append style={fill=gray!50}]{Sandpit event}{2019-09-01} \\ %7
\ganttbar[bar/.append style={fill=OliveGreen}]{Writing project up}{2019-10-07}{2019-11-31} \\ %8
\ganttlink{elem1}{elem2}
\ganttlink{elem2}{elem3}
\ganttlink{elem3}{elem4}
\ganttlink{elem4}{elem6}
\ganttlink{elem5}{elem6}
\ganttlink{elem6}{elem8}
\end{ganttchart}
\end{document} 

答案2

1. MEW 解决方案

以下是通过调整标签格式来解决问题的 MWE。使用的文档这里

\documentclass[12pt]{article}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[milestone label text={#1~\hspace{1pt}}]{1}{6}
        \gantttitle{2018}{6} \\
        \gantttitlelist{1,...,6}{1} \\
        \ganttmilestone{Milestone}{0}\\
        \ganttbar{Task 1}{1}{2} 
    \end{ganttchart}
\end{document} 

关键是[milestone label text={#1~\hspace{1pt}}]

前:

标签重叠的甘特图

后:

无标签重叠的甘特图

我个人也会调整其他标签类型,以便它们与图表具有相同的距离,但您会明白的。

2. OP 专用解决方案

您的代码未包含您使用的软件包,因此需要花费很长时间才能编译代码。该hspace选项确实不再适用于您的代码,相反,我只是包含了milestone label text={#1\mbox{ }}。它并不漂亮,但它确实将您的标签移到了里程碑的左侧。

以下是我使用的代码:

\documentclass[10pt]{article}
\usepackage{pgfgantt,tikz,xcolor,pgfkeys,pgfplots,ragged2e,pgfkeys}
\definecolor{OliveGreen}{RGB}{59,179,0}
\definecolor{Gray}{RGB}{211,211,211}

\usepackage[utf8]{inputenc}
\begin{document}

\begin{ganttchart}[ 
    vgrid={{Gray}},
    time slot format=isodate-yearmonth,
    x unit = 0.5cm,
    y unit title = 0.6cm,
    y unit chart = 0.6cm,
    bar label node/.style={text width=6cm,align=right,font=\RaggedLeft, anchor=east},
    milestone label node/.style={text width=6cm,align=right,font=\RaggedLeft, anchor=east},
    milestone label text={#1\mbox{ }},
    group label node/.style={text width=6cm,align=right,font=\RaggedLeft, anchor=east}] 
    {2018-12-01}{2019-12-31}
    \gantttitlecalendar{year, month=shortname} \\
    \ganttmilestone[milestone/.append style={fill=gray!50}]{Proposal decision}{2018-11-30} \\ %0
    \ganttbar[bar/.append style={fill=red!90}]{Potential proposal amendments}{2018-12-10}{2018-12-21} \\ %1
    \ganttbar[bar/.append style={fill=red!90}]{Travel \& accommodation research}{2019-01-01}{2019-02-28} \\ %2
    \ganttmilestone[milestone/.append style={fill=gray!50}]{Travel \& accommodation booking deadline}{2019-02-28} \\ %3
    \ganttbar[bar/.append style={fill=orange!90}]{Background theory reading}{2019-03-01}{2019-06-30} \\ %4
    \ganttbar[bar/.append style={fill=orange!90}]{Final admin (insurance, accounts etc.)}{2019-06-01}{2019-06-30} \\ %5     
    \ganttgroup[group/.append style={fill=blue!90}]{\textbf{IPP, Prague}}{2019-07-01}{2019-09-30} \\ %6
    \ganttmilestone[milestone/.append style={fill=gray!50}]{Sandpit event}{2019-09-01} \\ %7
    \ganttbar[bar/.append style={fill=OliveGreen}]{Writing project up}{2019-10-07}{2019-11-31} \\ %8
    \ganttlink{elem1}{elem2}    \ganttlink{elem2}{elem3}
    \ganttlink{elem3}{elem4}    \ganttlink{elem4}{elem6}
    \ganttlink{elem5}{elem6}    \ganttlink{elem6}{elem8}
\end{ganttchart}
\end{document}

正如您所看到的,它不能准确地再现您的图表,因为缺少太多东西;但我希望修复对您有用?

前:

前

后:

后

相关内容