如何为甘特图添加类似表格的标题格式?

如何为甘特图添加类似表格的标题格式?

我正在使用该包pgfgantt创建一个表格,显示一段时间内委员会中任职的人员。(可能不是它的预期用途,但它产生了我想要的不错的输出。)我遇到的一个问题是,我想让标题/标题看起来就像在我的其他表格中一样。我的意思是“主”\gantttitle将有一个\toprule等,表格底部将有一个\bottomrule。我曾尝试将这种类型的代码输入甘特图,但它无法编译。

我有一个 MWE,其中有我设置的甘特图(但其中包含一些不相关的有趣数据)和一个较小的表格来显示我希望能够放在图表上的格式。

\documentclass[a4paper]{memoir}
\usepackage{libertine}
\usepackage{pgfgantt}
\usepackage[graphicx]{realboxes}

\begin{document}

\begin{table}
\centering
\caption{Members of the Intergalactic committee}
\label{IGC-Mem}
\resizebox{\textwidth}{!}{
\begin{ganttchart}[y unit title=0.65cm,y unit chart=0.80cm,vgrid={draw=none, draw=none, dotted},title height=1.00,bar/.append style={fill=gray!30},bar height=0.50,canvas/.style=%
{shape=rectangle, draw=black, dotted}]{1}{21}
\gantttitle{Members of IGC by delegation}{21}\\
\gantttitle{2525}{3} 
\gantttitle{2526}{3} 
\gantttitle{2527}{3} 
\gantttitle{2528}{3} 
\gantttitle{2529}{3} 
\gantttitle{2530}{3}
\gantttitle{2531}{3}\\
%Member Details
\ganttbar{The Federation}{1}{1}
\ganttbar[inline]{Capt. Kirk}{1}{6}
\ganttbar[inline]{Mr.~ Spock}{7}{21} \\
\ganttbar{The Empire}{1}{1} 
\ganttbar[inline]{Darth Vader}{1}{7}\\
\ganttbar{The Republic}{21}{21}
\ganttbar[inline]{Princess Leia}{8}{17}
\ganttbar[inline]{Han Solo}{18}{21}\\
\ganttbar{Earth}{1}{1}
\ganttbar[inline]{Buck Rodgers}{1}{21}\\
\ganttbar{Red Dwarf}{1}{1}
\ganttbar[inline]{D. Lister}{1}{3}
\ganttbar[inline]{A. Rimmer}{4}{9}
\ganttbar[inline]{Kryten}{10}{21}\\
\ganttbar{Romulan}{1}{1}
\ganttbar[inline]{Vreenak}{1}{21}\\
\ganttbar{Imaginationland}{21}{21}
\ganttbar[inline]{Leopold "Butters" Stotch}{12}{21}
\end{ganttchart}
}
\hrulefill
\end{table}

\begin{table}
\centering
\caption{Members of the Intergalactic committee}
\label{IGC-Mem1}
\resizebox{\textwidth}{!}{%
\begin{tabular}{@{}llllllll@{}}
\toprule
\multicolumn{8}{c}{\textbf{Members of the IGC by delegation}}                                                                                                                                                                                                                                                                                  \\ \midrule
                                & \multicolumn{1}{c}{{2525}} & \multicolumn{1}{c}{{2526}} & \multicolumn{1}{c}{{2527}} & \multicolumn{1}{c}{{2528}} & \multicolumn{1}{c}{{2529}} & \multicolumn{1}{c}{{2530}} & \multicolumn{1}{c}{{2531}} \\
\multicolumn{1}{l|}{The Federation} & \multicolumn{2}{c|}{Capt. Kirk}                         & \multicolumn{5}{c|}{Mr. Spock}                                                                                                             \\ \cline{2-8} 
\multicolumn{1}{l|}{The Empire}        & \multicolumn{5}{c|}{Darth Vader}                                                                                                                                     \\ \cline{2-8} 
\multicolumn{1}{l|}{Earth}         & \multicolumn{7}{c|}{Buck Rodgers}                                                                                                                                                                                                    \\ \cline{2-8}  \bottomrule
\end{tabular}
}
\end{table}

\end{document}

我尝试在甘特图设置中编辑画布,但只能达到上面 MWE 中的效果。如果您需要更多信息,请在评论中告诉我。实际上,我希望甘特图中的主标题看起来像表格标题。

答案1

有一种可能性是;您首先将甘特图装箱,然后将其放置在名为的 TikZ 中\node;使用\draw和节点锚点,您现在可以轻松放置规则。\heaverulewidth对于给出和line width的厚度,并给出从;我还将设置为具有表格内容的通常水平填充(如果您愿意,可以将其设置为)。\toprule\bottomrule\lightrulewidth\midruleinner xsep\tabcolsep0pt

在此处输入图片描述

代码:

\documentclass[a4paper]{memoir}
\usepackage{libertine}
\usepackage{pgfgantt}
\usepackage[graphicx]{realboxes}

\newsavebox\mybox
\begin{lrbox}{\mybox}
\begin{ganttchart}[
  y unit title=0.65cm,
  y unit chart=0.80cm,
  vgrid={
    draw=none, 
    draw=none, 
    dotted
  },
  title height=1.00,
  bar/.append style={fill=gray!30},
  bar height=0.50,
  canvas/.style={
    shape=rectangle, 
    draw=none
    },
    title/.style={draw=none}
]{1}{21}
\gantttitle{Members of IGC by delegation}{21}\\
\gantttitle{2525}{3} 
\gantttitle{2526}{3} 
\gantttitle{2527}{3} 
\gantttitle{2528}{3} 
\gantttitle{2529}{3} 
\gantttitle{2530}{3}
\gantttitle{2531}{3}\\
%Member Details
\ganttbar{The Federation}{1}{1}
\ganttbar[inline]{Capt. Kirk}{1}{6}
\ganttbar[inline]{Mr.~ Spock}{7}{21} \\
\ganttbar{The Empire}{1}{1} 
\ganttbar[inline]{Darth Vader}{1}{7}\\
\ganttbar{The Republic}{21}{21}
\ganttbar[inline]{Princess Leia}{8}{17}
\ganttbar[inline]{Han Solo}{18}{21}\\
\ganttbar{Earth}{1}{1}
\ganttbar[inline]{Buck Rodgers}{1}{21}\\
\ganttbar{Red Dwarf}{1}{1}
\ganttbar[inline]{D. Lister}{1}{3}
\ganttbar[inline]{A. Rimmer}{4}{9}
\ganttbar[inline]{Kryten}{10}{21}\\
\ganttbar{Romulan}{1}{1}
\ganttbar[inline]{Vreenak}{1}{21}\\
\ganttbar{Imaginationland}{21}{21}
\ganttbar[inline]{Leopold "Butters" Stotch}{12}{21}
\end{ganttchart}
\end{lrbox}

\begin{document}

\begin{table}
\centering
\caption{Members of the Intergalactic committee}
\label{IGC-Mem}
\begin{tikzpicture}
\node[inner ysep=0pt,outer sep=0pt,inner xsep=\tabcolsep]
  (gantt)
  {\resizebox{\textwidth}{!}{\usebox\mybox}};
\draw[line width=\heavyrulewidth] 
  (gantt.north west) -- (gantt.north east);
\draw[line width=\lightrulewidth] 
  ([yshift=-17pt]gantt.north west) -- ([yshift=-17pt]gantt.north east);
\draw[line width=\heavyrulewidth] 
  (gantt.south west) -- (gantt.south east);
\end{tikzpicture}
\end{table}

\end{document}

相同想法的变体,但这次只是中间规则\drawn

\documentclass[a4paper]{memoir}
\usepackage{libertine}
\usepackage{pgfgantt}
\usepackage[graphicx]{realboxes}

\newsavebox\mybox
\begin{lrbox}{\mybox}
\begin{ganttchart}[
  y unit title=0.65cm,
  y unit chart=0.80cm,
  vgrid={
    draw=none, 
    draw=none, 
    dotted
  },
  title height=1.00,
  bar/.append style={fill=gray!30},
  bar height=0.50,
  canvas/.style={
    shape=rectangle, 
    draw=none
    },
    title/.style={draw=none}
]{1}{21}
\gantttitle{Members of IGC by delegation}{21}\\
\gantttitle{2525}{3} 
\gantttitle{2526}{3} 
\gantttitle{2527}{3} 
\gantttitle{2528}{3} 
\gantttitle{2529}{3} 
\gantttitle{2530}{3}
\gantttitle{2531}{3}\\
%Member Details
\ganttbar{The Federation}{1}{1}
\ganttbar[inline]{Capt. Kirk}{1}{6}
\ganttbar[inline]{Mr.~ Spock}{7}{21} \\
\ganttbar{The Empire}{1}{1} 
\ganttbar[inline]{Darth Vader}{1}{7}\\
\ganttbar{The Republic}{21}{21}
\ganttbar[inline]{Princess Leia}{8}{17}
\ganttbar[inline]{Han Solo}{18}{21}\\
\ganttbar{Earth}{1}{1}
\ganttbar[inline]{Buck Rodgers}{1}{21}\\
\ganttbar{Red Dwarf}{1}{1}
\ganttbar[inline]{D. Lister}{1}{3}
\ganttbar[inline]{A. Rimmer}{4}{9}
\ganttbar[inline]{Kryten}{10}{21}\\
\ganttbar{Romulan}{1}{1}
\ganttbar[inline]{Vreenak}{1}{21}\\
\ganttbar{Imaginationland}{21}{21}
\ganttbar[inline]{Leopold "Butters" Stotch}{12}{21}
\end{ganttchart}
\end{lrbox}

\begin{document}

\begin{table}
\centering
\caption{Members of the Intergalactic committee}
\label{IGC-Mem}
\tikz{
  \node[inner sep=0pt,outer sep=0pt] (gantt)
  {\begin{tabular}{c}
    \toprule
    \resizebox{\textwidth}{!}{\usebox\mybox} \\
    \bottomrule
   \end{tabular}%
   };
  \draw[line width=\lightrulewidth]
    ([yshift=-19pt]gantt.north west) -- ([yshift=-19pt]gantt.north east);
}   
\end{table}

\end{document}

相关内容