我正在使用以下代码,但我想加入一些如图所示的破折号。
\documentclass[a4paper, 12pt,fleqn]{article}
\usepackage{pgfgantt}
\begin{document}
\begin{figure}
\centering
{\sffamily
\begin{ganttchart}[%
inline,
y unit title=1.1cm,
canvas/.style={draw=none},
title/.style={draw=none},
bar inline label anchor=west,
bar inline label node/.append style={anchor=west, text=white},
bar/.append style={fill=cyan!90!black,},
bar height=.8,]{0}{18}
\ganttbar[inline=false]{M1}{0}{3}
\ganttbar{J1}{0}{3}
\ganttbar{J2}{3}{4}
\ganttbar{}{5}{18}\\
\ganttbar[inline=false]{M2}{0}{5}
\ganttbar{J2}{5}{8}
\ganttbar{J1}{8}{12}
\ganttbar{}{12}{18}\\
\gantttitlelist{0,...,18}{1}
\end{ganttchart}
}
\caption{To demonstrate Flow shop Scheduling}
\end{figure}
\end{document}
有没有办法重建甘特图以获得这种外观
我只想要一条带有 t 和破折号的线。其余部分应该与上面代码的输出类似。
答案1
这是一种可能性,尽管它有点不合理。
首先,在环境tikzpicture
周围添加一个环境pgfgantt
。这用于绘制一些额外的东西。
在 中\gantttitlelist
,添加[title label node/.append style={alias=n\x,opacity=0}]
。\x
是数字,因此编号为 1 的节点将被赋予别名n1
,依此类推。当不透明度为零时,数字是不可见的。
我认为标题列表中的节点是等距放置的,但由于它们的宽度不同,因此使用它们的角作为参考并不准确。所以我要做的是计算两个节点(n0
和n1
)中心之间的水平距离,然后在节点锚点的左侧绘制此距离的刻度north
。这似乎是准确的。
\documentclass[a4paper, 12pt,fleqn]{article}
\usepackage{pgfgantt}
\usetikzlibrary{calc}
\begin{document}
\begin{figure}
\centering
\sffamily
\begin{tikzpicture}
\begin{ganttchart}[%
inline,
y unit title=1.1cm,
canvas/.style={draw=none},
title/.style={draw=none},
bar inline label anchor=west,
bar inline label node/.append style={anchor=west, text=white},
bar/.append style={fill=cyan!90!black,},
bar height=.8,]{0}{18}
\ganttbar[inline=false]{M1}{0}{3}
\ganttbar{J1}{0}{3}
\ganttbar{J2}{3}{4}
\ganttbar{}{5}{18}\\
\ganttbar[inline=false]{M2}{0}{5}
\ganttbar{J2}{5}{8}
\ganttbar{J1}{8}{12}
\ganttbar{}{12}{18}\\
\gantttitlelist[title label node/.append style={alias=n\x,opacity=0}]{0,...,18}{1}
\end{ganttchart}
\draw [-latex] (n0.north west) -- ([xshift=7pt]n18.north east) node[right] {$t$};
\foreach \N in {0,...,18} {
\draw
let
\p1=(n0.center), \p2=(n1.center),\n1={(\x2-\x1)/2}
in
(n\N.north) +(-\n1,2pt) -- +(-\n1,-2pt) node[below,font=\small]{\N};
}
% draw tick for 19
\draw
let
\p1=(n0.center), \p2=(n1.center),\n1={(\x2-\x1)/2}
in
(n18.north) +(\n1,2pt) -- +(\n1,-2pt) node[below,font=\small]{19};
\end{tikzpicture}
\caption{To demonstrate Flow shop Scheduling}
\end{figure}
\end{document}
答案2
在最终理解了原作者想要什么之后,我找到了一个可能的解决方案,使用pst-plot
包裹:
\documentclass{article}
\usepackage{geometry} % avoid `overfull \hbox' warning
\usepackage{pst-plot}
\psset{
xunit = 0.6,
dimen = m
}
\def\Gantt(#1,#2)[#3]#4{%
\psframe[fillstyle = solid, fillcolor = cyan]%
(!#1 #2 0.8 sub)(!#1 #3 add #2 0.1 sub)
\uput[0](!#1 #2 0.45 sub){\textcolor{white}{$\mathrm{#4}$}}}
% marco syntax:
% \Gantt(<t-start>,<stack number, vertical>){<t-lengte>}[<label>]
\begin{document}
\begin{center}
\begin{pspicture}(-0.9,-0.52)(19.78,2.5) % boundry found manually
\psline(0,0)(0,2.5)
\psaxes[yAxis = false]{->}(0,0)(19.35,0)[$t$,0][,90]
\multido{\r = 0.55+1, \i = 1+1}{2}{\rput(-0.55,\r){$\mathrm{M\i}$}}
\Gantt(0,1)[5]{}
\Gantt(5,1)[3]{J2}
\Gantt(8,1)[4]{J1}
\Gantt(12,1)[7]{}
\Gantt(0,2)[3]{J1}
\Gantt(3,2)[2]{J2}
\Gantt(5,2)[14]{}
\end{pspicture}
\end{center}
\end{document}