如何使甘特图中的 href 可点击到标签?

如何使甘特图中的 href 可点击到标签?

我不知道这是否可能,但我有一个包含多个“嵌套”甘特图的文档,我想知道是否可以使用它们链接它们\href

\documentclass[12pt,letterpaper]{report}
\usepackage[utf8]{inputenc}

\usepackage{pgfgantt}
\usepackage{xcolor}

\ganttset{
  group/.append style={orange},
  milestone/.append style={red},
  progress label node anchor/.append style={text=red},
}

\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor={blue!50!black},
    citecolor={red!50!black},
    urlcolor={blue!80!black}
}

\begin{document}

\chapter{Project}
     % Ganttchart specs
     \begin{ganttchart}[
     y unit title=0.5cm,
     y unit chart=0.7cm,
     vgrid,hgrid,
     title height=1,
%     title/.style={fill=none},
     title label font=\bfseries\footnotesize,
     bar/.style={fill=blue},
     bar height=0.7,
%   progress label text={},
     group right shift=0,
     group top shift=0.7,
     group height=.3,
     group peaks width={0.2},
     inline]{1}{24}
    % 
    %-------------------------------------------------------
    \gantttitle{Title}{24}\\
    %
    \gantttitle[]{Year 1}{12}
    \gantttitle[]{Year 2}{12} \\
    %
    \gantttitle{Q1}{3}
    \gantttitle{Q2}{3}
    \gantttitle{Q3}{3}
    \gantttitle{Q4}{3}
    \gantttitle{Q1}{3}
    \gantttitle{Q2}{3}
    \gantttitle{Q3}{3} 
    \gantttitle{Q4}{3}\\
    %
    %-------------------------------------------------------
    % Task 1
    %\ganttgroup[inline=false]{Task 1}{1}{5}\\
    \ganttgroup[inline=false]{\href{task1}{Task 1}}{1}{5}\\
    \ganttbar[progress=60,inline=false]{Planning}{1}{4}\\
    \ganttmilestone[inline=false]{Milestone 1}{9} \\

    % Task 2
    %\ganttgroup[inline=false]{Task 2}{10}{15}\\
    \ganttgroup[inline=false]{\href{task1}{Task 2}}{10}{15}\\
    \ganttbar[progress=10,inline=false]{Building}{10}{13}\\
    \ganttmilestone[inline=false]{Milestone 1}{16} \\


\end{ganttchart}


\chapter{Task 1}\label{task1}
     \begin{ganttchart}[
     y unit title=0.5cm,
     y unit chart=0.7cm,
     vgrid,hgrid,
     title height=1,
%     title/.style={fill=none},
     title label font=\bfseries\footnotesize,
     bar/.style={fill=blue},
     bar height=0.7,
%   progress label text={},
     group right shift=0,
     group top shift=0.7,
     group height=.3,
     group peaks width={0.2},
     inline]{1}{20}
    % 
    %-------------------------------------------------------
    \gantttitle{Task}{20}\\
    %
    \gantttitle{W1}{4}
    \gantttitle{W2}{4}
    \gantttitle{W3}{4}
    \gantttitle{W4}{4}
    \gantttitle{W5}{4}\\
    %
    %-------------------------------------------------------
    \ganttgroup[inline=false]{Group 1}{1}{5}\\
    \ganttbar[progress=80,inline=false]{A}{1}{4}\\
    \ganttmilestone[inline=false]{Milestone}{9} \\

    \ganttgroup[inline=false]{Group 2}{6}{20} \\ 
    \ganttbar[progress=60,inline=false]{B1}{6}{14} \\
    \ganttmilestone[inline=false]{Milestone}{13} \\
    \ganttbar[progress=15,inline=false]{B2}{12}{16} \\
    \ganttmilestone[inline=false]{Milestone}{16} \\       

\end{ganttchart}

\chapter{Task 2}\label{task2}
     \begin{ganttchart}[
     y unit title=0.5cm,
     y unit chart=0.7cm,
     vgrid,hgrid,
     title height=1,
%     title/.style={fill=none},
     title label font=\bfseries\footnotesize,
     bar/.style={fill=blue},
     bar height=0.7,
%   progress label text={},
     group right shift=0,
     group top shift=0.7,
     group height=.3,
     group peaks width={0.2},
     inline]{1}{24}
    % 
    %-------------------------------------------------------
    \gantttitle{Task}{24}\\
    %
    \gantttitle{W1}{4}
    \gantttitle{W2}{4}
    \gantttitle{W3}{4}
    \gantttitle{W4}{4}
    \gantttitle{W5}{4}
    \gantttitle{W6}{4}\\
    %
    %-------------------------------------------------------
    \ganttgroup[inline=false]{Group 1}{1}{9}\\
    \ganttbar[progress=10,inline=false]{A}{1}{8}\\
    \ganttmilestone[inline=false]{Milestone}{13} \\

    \ganttgroup[inline=false]{Group 2}{6}{16} \\ 
    \ganttbar[progress=20,inline=false]{B}{9}{15} \\
    \ganttmilestone[inline=false]{Milestone}{13} \\

    \ganttgroup[inline=false]{Group 3}{15}{24} \\ 
    \ganttbar[progress=20,inline=false]{C}{15}{18} \\
    \ganttmilestone[inline=false]{Milestone}{22} \\

\end{ganttchart}

\end{document}

基本上,我希望能够点击每个任务,然后参考将我带到显示该任务详细信息的部分。

上述示例编译成功,似乎创建了链接,但这些链接不可点击。换句话说,我点击了“任务 1”,但它并没有将我带到文档的该部分。

答案1

应该\hyperref[task1]{Task 1}或者更简单:\nameref{task1}不需要记住相关章节的名称。

\href是用于链接到其他文档。

我在示例中展示了这两种方法。

\documentclass[12pt,letterpaper]{report}
\usepackage[utf8]{inputenc}

\usepackage{pgfgantt}
\usepackage{xcolor}

\ganttset{
  group/.append style={orange},
  milestone/.append style={red},
  progress label node anchor/.append style={text=red},
}

\usepackage{hyperref}
\hypersetup{
  colorlinks=true,
  linkcolor={blue!50!black},
  citecolor={red!50!black},
  urlcolor={blue!80!black}
}

\begin{document}

\chapter{Project}
     % Ganttchart specs
     \begin{ganttchart}[
     y unit title=0.5cm,
     y unit chart=0.7cm,
     vgrid,hgrid,
     title height=1,
%     title/.style={fill=none},
     title label font=\bfseries\footnotesize,
     bar/.style={fill=blue},
     bar height=0.7,
%   progress label text={},
     group right shift=0,
     group top shift=0.7,
     group height=.3,
     group peaks width={0.2},
     inline]{1}{24}
    % 
    %-------------------------------------------------------
    \gantttitle{Title}{24}\\
    %
    \gantttitle[]{Year 1}{12}
    \gantttitle[]{Year 2}{12} \\
    %
    \gantttitle{Q1}{3}
    \gantttitle{Q2}{3}
    \gantttitle{Q3}{3}
    \gantttitle{Q4}{3}
    \gantttitle{Q1}{3}
    \gantttitle{Q2}{3}
    \gantttitle{Q3}{3} 
    \gantttitle{Q4}{3}\\
    %
    %-------------------------------------------------------
    % Task 1
    %\ganttgroup[inline=false]{Task 1}{1}{5}\\
    \ganttgroup[inline=false]{\hyperref[task1]{Task 1}}{1}{5}\\
    \ganttbar[progress=60,inline=false]{Planning}{1}{4}\\
    \ganttmilestone[inline=false]{Milestone 1}{9} \\

    % Task 2
    %\ganttgroup[inline=false]{Task 2}{10}{15}\\
    \ganttgroup[inline=false]{\nameref{task2}}{10}{15}\\
    \ganttbar[progress=10,inline=false]{Building}{10}{13}\\
    \ganttmilestone[inline=false]{Milestone 1}{16} \\


\end{ganttchart}
\chapter{Task 1}\label{task1}
     \begin{ganttchart}[
     y unit title=0.5cm,
     y unit chart=0.7cm,
     vgrid,hgrid,
     title height=1,
%     title/.style={fill=none},
     title label font=\bfseries\footnotesize,
     bar/.style={fill=blue},
     bar height=0.7,
%   progress label text={},
     group right shift=0,
     group top shift=0.7,
     group height=.3,
     group peaks width={0.2},
     inline]{1}{20}
    % 
    %-------------------------------------------------------
    \gantttitle{Task}{20}\\
    %
    \gantttitle{W1}{4}
    \gantttitle{W2}{4}
    \gantttitle{W3}{4}
    \gantttitle{W4}{4}
    \gantttitle{W5}{4}\\
    %
    %-------------------------------------------------------
    \ganttgroup[inline=false]{Group 1}{1}{5}\\
    \ganttbar[progress=80,inline=false]{A}{1}{4}\\
    \ganttmilestone[inline=false]{Milestone}{9} \\

    \ganttgroup[inline=false]{Group 2}{6}{20} \\ 
    \ganttbar[progress=60,inline=false]{B1}{6}{14} \\
    \ganttmilestone[inline=false]{Milestone}{13} \\
    \ganttbar[progress=15,inline=false]{B2}{12}{16} \\
    \ganttmilestone[inline=false]{Milestone}{16} \\       

\end{ganttchart}

\chapter{Task 2}\label{task2}
     \begin{ganttchart}[
     y unit title=0.5cm,
     y unit chart=0.7cm,
     vgrid,hgrid,
     title height=1,
%     title/.style={fill=none},
     title label font=\bfseries\footnotesize,
     bar/.style={fill=blue},
     bar height=0.7,
%   progress label text={},
     group right shift=0,
     group top shift=0.7,
     group height=.3,
     group peaks width={0.2},
     inline]{1}{24}
    % 
    %-------------------------------------------------------
    \gantttitle{Task}{24}\\
    %
    \gantttitle{W1}{4}
    \gantttitle{W2}{4}
    \gantttitle{W3}{4}
    \gantttitle{W4}{4}
    \gantttitle{W5}{4}
    \gantttitle{W6}{4}\\
    %
    %-------------------------------------------------------
    \ganttgroup[inline=false]{Group 1}{1}{9}\\
    \ganttbar[progress=10,inline=false]{A}{1}{8}\\
    \ganttmilestone[inline=false]{Milestone}{13} \\

    \ganttgroup[inline=false]{Group 2}{6}{16} \\ 
    \ganttbar[progress=20,inline=false]{B}{9}{15} \\
    \ganttmilestone[inline=false]{Milestone}{13} \\

    \ganttgroup[inline=false]{Group 3}{15}{24} \\ 
    \ganttbar[progress=20,inline=false]{C}{15}{18} \\
    \ganttmilestone[inline=false]{Milestone}{22} \\

\end{ganttchart}

\end{document}

在此处输入图片描述

相关内容