
실패간트 차트와 테이블 결합이제 나는 표 형식의 환경을 사용하여 간트 차트를 피하려고 노력합니다. 그러나 나는pgfgantt-패키지에 몇 가지 문제가 있습니다.
아이디어
행 이름 열이 포함된 테이블을 만들고 있습니다. 그런 다음 정확히 동일한 너비의 24개 열을 따릅니다. 헤더에서는 각각 12개 열로 구성된 여러 열을 두 번 사용하여연령2017 및 2018. 아래에는 각각 3개의 열로 구성된 8개의 다중 열이 있습니다.병사매년. 마지막으로 cellcolor
특정 개월 수에 걸친 일종의 시간 표시줄을 얻는 데 사용하려고 합니다 . 다음과 같아야 합니다.
비어 있는 6개월, 회색으로 채워지는 12개월, 다시 비어 있는 6개월로 구성된 하나의 타임바(아래 매크로 참조)를 포함했습니다.
\timebar{title}{6}{12}{6}
첫 번째 문제
내 숙소의 너비는 모두 동일하므로 실제로 다음 MWE가 의도한 대로 작동할 것으로 기대합니다. 개월 수가 동일하지만 이동된 다른 시간 표시줄이 표시됩니다. 하지만 보시다시피 엉망입니다.
\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs,array}
\usepackage[colorlinks=true,linkcolor={black}]{hyperref}
\newcolumntype{C}{>{\centering}m{0.03\textwidth}}
\usepackage{colortbl}
\newcommand{\Year}[1]{ \multicolumn{12}{c|}{#1} }
\newcommand{\Quarter}[1]{\multicolumn{3}{C|}{#1}}
\newcommand{\FourQuarters}{\Quarter{I} & \Quarter{II} & \Quarter{III} & \Quarter{IV} }
\newcommand{\timebar}[4]{ #1 & \multicolumn{ #2 }{c}{} & \multicolumn{#3}{c}{{\cellcolor{black!20!white}}} & \multicolumn{#4}{c|}{} }
\begin{document}
\section{sectiontitle}\label{sec:sectiontitle}
\begin{table}[h]
\caption{table}
\centering
\begin{tabular}{c | cccccccccccc | cccccccccccc | }
\toprule
\multicolumn{1}{l|}{Title} & \Year{2017} & \Year{2018} \\
\multicolumn{1}{l|}{Subtitle} & \FourQuarters & \FourQuarters \\
\hline
\timebar{A}{1}{12}{11} \\
\timebar{A}{2}{12}{10} \\
\timebar{A}{3}{12}{9} \\
\timebar{A}{4}{12}{8} \\
\timebar{A}{5}{12}{7} \\
\timebar{A}{6}{12}{6} \\
\timebar{A}{7}{12}{5} \\
\timebar{A}{8}{12}{4} \\
\timebar{A}{9}{12}{3} \\
\timebar{A}{10}{12}{2} \\
\timebar{A}{11}{12}{1} \\
\timebar{A}{1}{12}{11} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
모든 막대는 모든 행에서 한 달씩 이동해야 하지만 길이는 동일해야 합니다. 그것이 내가 얻는 것입니다:
왜 이렇게이다? 어떻게 해결할 수 있나요?
두 번째 문제
내 계획은 다음과 같은 막대를 제공하는 ganttbar 패키지를 모방하는 것입니다.
\ganttbar{Title}{7}{22} %\\ Title, First month, last month
내 새로운 시간 표시줄 명령은 다음과 같습니다.
\timebar{Title}{6}{15}{3} %\\ Title, number months before timebar,
%\\ number months of timebar,
%\\ number months after timebar
Ganttbar와 같은 시간 표시줄에서 동일한 형식을 얻으려면 매크로에서 몇 가지 간단한 계산을 수행해야 합니다.
\newcommand{\timebar}[4]{ \ref{#1} & \nameref{#1}
& \multicolumn{#2 % should be Startmonth - 1
}{c}{}
& \multicolumn{#3 % should be Endmonth - Startmonth
}{c}{{\cellcolor{black!20!white}}}
& \multicolumn{#4 % should be Totalmonths - Endmonth + 1
}{c|}{} }
그래서 외부적으로는 두 개의 숫자 인수가 필요합니다.
#2
- 바의 첫 달#3
- 바의 마지막 달
내부적으로 매크로에는 세 가지 인수가 필요합니다.
#2 - 1
- 첫 번째 다중 열의 셀 수#3 - #2
- 두 번째 다중 열의 셀 수24 - #3 + 1
- 세 번째 다중 열의 셀 수
더 나아가 정렬 탭이 너무 많아 불가능합니다 \timebar{A}{0}{12}{12}
. \timebar{A}{12}{12}{0}
쉬운 해결책이 있나요?
그 계산은 어떻게 할 수 있나요? 그럼 마지막으로 내 타임바는 위의 간트바와 동일한 인수를 갖습니까?
참고로 간트차트
간트 차트는 다음과 같습니다.
\documentclass{scrreprt}
\usepackage[top=25mm, bottom=20mm, left=20mm, right=20mm, foot=20mm]{geometry}
\usepackage{booktabs}
\usepackage{translator}
\usepackage{pgfgantt}
\ganttset{
vgrid = dotted,
hgrid = dotted,
newline shortcut=true,
%
y unit title = 15pt,
title height = 1,
y unit chart = 15pt,
x unit=0.014\textwidth,
%
canvas/.style={
shape=rectangle,
draw=black,
line width = 0.4pt,
},
group peaks tip position=0,
group label node/.append style={align=right},
%
bar label node/.append style={align=right},
bar/.append style={fill=gray!20!white},
bar height=0.3,
bar top shift=0.3,
group top shift=0.5,
%
group peaks width=2,
%
milestone left shift=-1,
milestone right shift=2}
\begin{document}
\begin{table}[h]
\setlength{\tabcolsep}{0pt}
\caption{my gantt chartt}
\label{tab:gantt}
\centering
\begin{tabular}{@{}c@{}}
\toprule
\begin{ganttchart}{1}{24}
\gantttitle[]{2017}{12} \gantttitle[]{2018}{12} \\
\gantttitle{I}{3}\gantttitle{II}{3}\gantttitle{III}{3}\gantttitle{IV}{3}
\gantttitle{I}{3}\gantttitle{II}{3}\gantttitle{III}{3}\gantttitle{IV}{3} \\
\ganttbar{A}{1}{12}\\
\ganttbar{A}{2}{13}\\
\ganttbar{A}{3}{14}\\
\ganttbar{A}{4}{15}\\
\ganttbar{A}{5}{16}\\
\ganttbar{A}{6}{17}\\
\ganttbar{A}{7}{18}\\
\ganttbar{A}{8}{19}\\
\ganttbar{A}{9}{20}\\
\ganttbar{A}{10}{21}\\
\ganttbar{A}{11}{22}\\
\ganttbar{A}{12}{23}\\
\ganttbar{A}{13}{24}
\end{ganttchart}%
\end{tabular}
\end{table}
\end{document}
이것이 내가 필요한 기능이 많이 부족하기 때문에 ganttbar 패키지를 사용하지 않고 최종 결과여야 합니다.
이 질문은 가능한 한 빨리 현상금을 받게 될 것입니다.
답변1
더 나은 버전:
\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage[colorlinks=true,linkcolor={black}]{hyperref}
\usepackage{colortbl}
\newcommand{\TotalMonths}{24}
\newcommand{\Year}[1]{ \multicolumn{12}{c|}{#1} }
\newcommand{\Quarter}[1]{\multicolumn{3}{c|}{#1}}
\newcommand{\FourQuarters}{\Quarter{I} & \Quarter{II} & \Quarter{III} & \Quarter{IV} }
\newcommand{\timebar}[3]{%
\ref{#1} &
\nameref{#1} &
\multicolumn{\the\numexpr#2-1}{c}{} &
\multicolumn{\the\numexpr#3-#2}{c}{{\cellcolor{black!20!white}}}
& \multicolumn{\the\numexpr\TotalMonths-#3+1}{c|}{}
}
\begin{document}
\section{sectiontitle}\label{sec:sectiontitle}
\begin{table}[h]
\caption{table}
\centering
\begin{tabular}{cc | *{12}{c} | *{12}{c} | }
\toprule
\multicolumn{2}{l|}{Title} & \Year{2017} & \Year{2018} \\
\multicolumn{2}{l|}{Subtitle} & \FourQuarters & \FourQuarters \\
\hline
\timebar{sec:sectiontitle}{7}{22} \\
\timebar{sec:sectiontitle}{3}{16} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
답변2
약간의 영감을 받아이 답변루프를 사용하여 다음 솔루션을 생각해 냈습니다.
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs,array,multicol}
\newcommand*\TAB{&}
\long\def\gloop #1\grepeat
{\gdef \giterate {#1\expandafter \giterate \grepeat }\giterate }
\let\grepeat\fi
\newcounter{n}
\newcounter{m}
\newcounter{TotalMonths}
\newlength{\colwidth}
\setlength{\colwidth}{2mm}
\newcommand{\TotalMonths}{24}
\newcommand{\Year}[1]{ \multicolumn{12}{|c|}{#1}}
\newcommand{\Quarter}[1]{\multicolumn{3}{|c|}{#1}}
\newcommand{\FourQuarters}{\Quarter{I} & \Quarter{II} & \Quarter{III} & \Quarter{IV}}
\newcommand{\timebar}[3]{
\setcounter{TotalMonths}{\TotalMonths}%
\setcounter{n}{1}
\setcounter{m}{-1}
\stepcounter{TotalMonths}%
#1 & B
\gloop
\stepcounter{n}%
\stepcounter{m}%
\TAB
\ifnum #2<\value{n} \ifnum #3>\value{m}%
{\cellcolor{black!20!white}}\hspace*{\colwidth}%
\else
\hspace*{\colwidth}%
\fi
\else
\hspace*{\colwidth}%
\fi
\ifnum \value{TotalMonths}>\value{n}
\grepeat
}
\begin{document}
\begin{table}[h]
\caption{table}
\centering
\setlength{\tabcolsep}{0pt}
\begin{tabular}{ p{2cm}p{2cm} | *{12}{c} *{12}{c} | c }
\toprule
\multicolumn{2}{l}{Title} & \Year{2017} & \Year{2018} \\
\multicolumn{2}{l}{Subtitle} & \FourQuarters & \FourQuarters \\
\hline
\timebar{Hello World}{1}{10} \\
\timebar{Hello World}{2}{11} \\
\timebar{Hello World}{3}{12} \\
\timebar{Hello World}{4}{24} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}