pgfgantt,在标签中换行文字

pgfgantt,在标签中换行文字

我的任务说明很长,因此我的甘特图超出了页面范围。有没有办法能够将文本换行,使其继续位于任务标题下方?我希望最终能够填写所有目标和任务,并将它们放在图表旁边的漂亮矩形包中。

这是我的代码:

\documentclass[11pt,a4paper,oneside]{article}
\usepackage{fancyhdr}
\usepackage{indentfirst}
\usepackage{pgf}
\usepackage{pgfgantt}
\usepackage{pgfcalendar}
\usepackage{rotating}

\begin{document}
\pagebreak
\begin{rotate}{270}
\begin{ganttchart}[y unit title=0.6cm,
y unit chart=0.7cm,
vgrid,
title height=.85,
hgrid=true,
canvas/.style={fill=yellow!25, draw=blue, solid, very thick}, 
bar/.style={fill=gray, rounded corners=3pt},
bar left shift=.05, 
bar right shift=-.05, 
bar top shift=.3, 
bar height=.3,vgrid={*1{blue, dashed}}, 
bar label font=\normalsize\color{black!50},
bar label anchor/.append style={align=left, text width=8mm},
group right shift=0,group top shift=.6,group height=.3,group peaks={}{}{0}]{23}
\gantttitle{2012}{5}
\gantttitle{2013}{12}
\gantttitle{2014}{6}\\
\gantttitlelist{8,...,12}{1}
\gantttitlelist{1,...,12}{1}
\gantttitlelist{1,...,6}{1}\\


\ganttgroup[group label anchor/.style={left=3.5cm}
]{Objective 1: Continuous news coverage of 911 events presented by Worldnet (Voice of America). Please Note: This news program was recorded by the non-profit Television Archive. The video is available as a "loan" only: This means it may be streamed but not downloaded. Network URL: http://www.ibb.gov}{1}{4}\\
\ganttbar{\textbf{Task a} International Union, United Automobile Workers of America
This is from the UAW-AFL faction that split with Homer Martin from the majority UAW-CIO HD6350.A8}{4}{2} \\
\ganttbar{\textbf{Task b}}{4}{2} \\
\ganttbar{\textbf{Task c}}{4}{2} \\

\ganttgroup{Objective 2:}{4}{6} \\
\ganttbar{Task a}{4}{6} \\
\ganttbar{Task b}{4}{6} \\

\ganttgroup{Objective 3}{4}{6} \\
\ganttbar{Task a}{4}{2} \\
\ganttbar{Task b}{4}{2} \\
\ganttbar{Task c}{4}{2} \\
\ganttbar{Task d}{4}{2} \\

\ganttgroup{Objective 4}{4}{6} \\
\ganttbar{Task a}{4}{2} \\
\ganttbar{Task b}{4}{2} \\

\ganttgroup{Objective 5}{4}{6} \\
\ganttbar{Task a}{4}{2} \\
\ganttbar{Task b}{4}{2} \\
\ganttbar{Task c}{4}{2} \\
\end{ganttchart}

\end{rotate}
\end{document}

答案1

经过多次(无果)尝试使用\parboxes 并修改文本允许的最大长度后,我认为考虑到目标和任务的文本长度,使用不同的方法是合适的。

一种选择是使用工具提示,这样甘特图只显示少量文本(标签),并且只有将鼠标悬停在该元素上时才可见给定目标或任务的信息。

facytooltips包有助于实现此任务。

您需要创建一个包含工具提示文本的 PDF 文件(每页一个工具提示)。可以使用 LaTeX 生成此 PDF 文档;在此示例中,我使用了一个文件(名为tasktips.tex),其内容如下:

\documentclass{article}
\usepackage{url}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[createtips]{fancytooltips}

\newcommand\MyTip[2]{%
  \keytip{#1}%
  \begin{mdframed}[
    innerlinewidth=1mm,linecolor=olive!50,
    backgroundcolor=yellow!20,roundcorner=5pt,rightmargin=.25\textwidth]
  #2
  \end{mdframed}%
  \newpage%
}

\begin{document}

\MyTip{obje1}{Continuous news coverage of 911 events presented by Worldnet (Voice of America). Please Note: This news program was recorded by the non-profit Television Archive. The video is available as a "loan" only: This means it may be streamed but not downloaded. Network URL: \url{http://www.ibb.gov}}

\MyTip{task1a}{ International Union, United Automobile Workers of America
This is from the UAW-AFL faction that split with Homer Martin from the majority UAW-CIO HD6350.A8}

\end{document}

\MyTip命令生成工具提示文本及其<key>;这<key>将在主文档(包含甘特图的文档)中使用。语法\MyTip是;

\MyTip{<key>}{<text>}

在示例中,每个工具提示文本将被放置在借助该mdframed包生成的带框彩色框内,但当然您可以根据需要更改样式。处理tasktips.tex(使用)后,您将获得一个包含工具提示的pdflatex文件。tasktips.pdf

filename现在在您的主文件中,您所要做的就是在加载 fancytooltips 时使用上一步中创建的 PDF 的名称作为包选项的值:

\usepackage[filename=tasktips,mouseover,noextratext]{fancytooltips}

然后在文档正文中使用以下\tooltip命令:

\tooltip{<text>}{<key>}

<text>与 对应的工具提示关联<key>。以下是包含甘特图和命令的文件\tooltip

\documentclass[11pt,a4paper,oneside]{article}
\usepackage{fancyhdr}
\usepackage{indentfirst}
\usepackage{pgf}
\usepackage{pgfgantt}
\usepackage{pgfcalendar}
\usepackage{rotating}
\usepackage[filename=tasktips,mouseover,noextratext]{fancytooltips}

\begin{document}
\pagebreak
\begin{rotate}{270}
\begin{ganttchart}[y unit title=0.6cm,
y unit chart=0.7cm,
vgrid,
title height=.85,
hgrid=true,
canvas/.style={fill=yellow!25, draw=blue, solid, very thick}, 
bar/.style={fill=gray, rounded corners=3pt},
bar left shift=.05, 
bar right shift=-.05, 
bar top shift=.3, 
bar height=.3,vgrid={*1{blue, dashed}}, 
bar label font=\normalsize\color{black!50},
bar label anchor/.append style={align=left, text width=1.5cm},
group right shift=0,group top shift=.6,group height=.3,group peaks={}{}{0}]{23}
\gantttitle{2012}{5}
\gantttitle{2013}{12}
\gantttitle{2014}{6}\\
\gantttitlelist{8,...,12}{1}
\gantttitlelist{1,...,12}{1}
\gantttitlelist{1,...,6}{1}\\


\ganttgroup{\tooltip{Objective 1}{obje1}}{1}{4} \\
\ganttbar{\tooltip{\textbf{Task a}}{task1a}}{4}{2} \\
\ganttbar{\textbf{Task b}}{4}{2} \\
\ganttbar{\textbf{Task c}}{4}{2} \\

\ganttgroup{Objective 2:}{4}{6} \\
\ganttbar{Task a}{4}{6} \\
\ganttbar{Task b}{4}{6} \\

\ganttgroup{Objective 3}{4}{6} \\
\ganttbar{Task a}{4}{2} \\
\ganttbar{Task b}{4}{2} \\
\ganttbar{Task c}{4}{2} \\
\ganttbar{Task d}{4}{2} \\

\ganttgroup{Objective 4}{4}{6} \\
\ganttbar{Task a}{4}{2} \\
\ganttbar{Task b}{4}{2} \\

\ganttgroup{Objective 5}{4}{6} \\
\ganttbar{Task a}{4}{2} \\
\ganttbar{Task b}{4}{2} \\
\ganttbar{Task c}{4}{2} \\

\end{ganttchart}

\end{rotate}
\end{document}

一些图片:

在此处输入图片描述

将鼠标悬停在文本上时,会出现工具提示:

在此处输入图片描述

在此处输入图片描述

缺点是您需要使用 AcrobatReader 才能正确显示工具提示。

相关内容