Chronosys printing measurement units
I'm using the chronosys (http://ctan.mirror.rafal.ca/macros/latex/contrib/chronosys/docchronosys_en.pdf) package to prepare a timeline with the code below.
1) This code is printing a line at the top of the page that is showing the conversion from points to inches . How do I supress this?
2) How do I get the textwidth option to work to have the text of the events wrap?
3) Lastly, is there a way to build in a bit of whitespace between the timeline and the vertical mark leading to the event name?
documentclass{article}
usepackage{chronosys}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronograduation[periode]{1}
chronoevent[markdepth=5, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=15, year=false]{1999}{CEPA Amendments Passed}
chronoevent[markdepth=15, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=5, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
chronosys
add a comment |
I'm using the chronosys (http://ctan.mirror.rafal.ca/macros/latex/contrib/chronosys/docchronosys_en.pdf) package to prepare a timeline with the code below.
1) This code is printing a line at the top of the page that is showing the conversion from points to inches . How do I supress this?
2) How do I get the textwidth option to work to have the text of the events wrap?
3) Lastly, is there a way to build in a bit of whitespace between the timeline and the vertical mark leading to the event name?
documentclass{article}
usepackage{chronosys}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronograduation[periode]{1}
chronoevent[markdepth=5, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=15, year=false]{1999}{CEPA Amendments Passed}
chronoevent[markdepth=15, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=5, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
chronosys
The value ofmarkdepth
must be a dimen not a number.
– Ulrike Fischer
May 27 '15 at 13:59
add a comment |
I'm using the chronosys (http://ctan.mirror.rafal.ca/macros/latex/contrib/chronosys/docchronosys_en.pdf) package to prepare a timeline with the code below.
1) This code is printing a line at the top of the page that is showing the conversion from points to inches . How do I supress this?
2) How do I get the textwidth option to work to have the text of the events wrap?
3) Lastly, is there a way to build in a bit of whitespace between the timeline and the vertical mark leading to the event name?
documentclass{article}
usepackage{chronosys}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronograduation[periode]{1}
chronoevent[markdepth=5, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=15, year=false]{1999}{CEPA Amendments Passed}
chronoevent[markdepth=15, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=5, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
chronosys
I'm using the chronosys (http://ctan.mirror.rafal.ca/macros/latex/contrib/chronosys/docchronosys_en.pdf) package to prepare a timeline with the code below.
1) This code is printing a line at the top of the page that is showing the conversion from points to inches . How do I supress this?
2) How do I get the textwidth option to work to have the text of the events wrap?
3) Lastly, is there a way to build in a bit of whitespace between the timeline and the vertical mark leading to the event name?
documentclass{article}
usepackage{chronosys}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronograduation[periode]{1}
chronoevent[markdepth=5, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=15, year=false]{1999}{CEPA Amendments Passed}
chronoevent[markdepth=15, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=5, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
chronosys
chronosys
edited May 27 '15 at 23:34
Martin Schröder
12.9k640125
12.9k640125
asked May 27 '15 at 13:06
spindoctorspindoctor
31029
31029
The value ofmarkdepth
must be a dimen not a number.
– Ulrike Fischer
May 27 '15 at 13:59
add a comment |
The value ofmarkdepth
must be a dimen not a number.
– Ulrike Fischer
May 27 '15 at 13:59
The value of
markdepth
must be a dimen not a number.– Ulrike Fischer
May 27 '15 at 13:59
The value of
markdepth
must be a dimen not a number.– Ulrike Fischer
May 27 '15 at 13:59
add a comment |
3 Answers
3
active
oldest
votes
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronograduation[periode]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
In terms of your "gap" I would move the scale to the top like this (choice of colors is yours -- you could make all black)
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronoperiodecoloralternation{black,green,black,green}
chronograduation[periode][dateselevation=0pt]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
add a comment |
A new version (slightly amended) of chronos. The code is only as long as it is because it is attempting to become a more flexible substitute for chronosys
, which is extremely problematic in many ways. (If it does exactly what you want, great. If you want to tweak it a little, good luck.)
documentclass[border=10pt,multi,tikz]{standalone}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
timeline height=2mm,
start date=1995-01-01,
end date=2008-01-01,
only years,
events/.append style={text width=20mm},
timeline line={shorten >=-10mm, -{Triangle Cap[length=10mm]}},
timeline font=footnotesize,
timeline marks,
only text,
}
]
chronosevent{1995}{Debate on CEPA Begins}(-5pt)
chronosevent{1999}{CEPA Amendments Passed}(-15pt)
chronosevent{2007}[text width=30mm]{BPA Risk Assessment Begins}(-30pt)
chronosevent{2006}{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=1995-01-01,
end date=2008-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{1995}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{1999}[my box=green!75!black]{CEPA Amendments Passed}(-15pt)
chronosevent[magenta]{2007}[text width=30mm, my box=magenta]{BPA Risk Assessment Begins}(-30pt)
chronosevent[orange]{2006}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
end{document}
Two versions of your timeline from the code above:
This is actually so beautiful, can you please tell me how to add date as dd/mm/yyyy in the box ?
– Sari
Jan 30 '18 at 8:01
@Sari Try deleting the keyonly text
from the options for thetikzpicture
. You may need to alter the date format, too.
– cfr
Jan 30 '18 at 23:25
add a comment |
why the line of 2008 above the box of 2007? I did not change any code. I want to change the line of 2008 below of the box of 2007.
documentclass[border=10pt,multi,tikz]{standalone}
%usepackage[UTF8]{ctex}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usepackage{enumitem}
%usepackage{lipsum}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=2007-01-01,
end date=2019-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{2007}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{2008}[my box=green!75!black]{CEPA Amendments Passed}(-40pt)
chronosevent[magenta]{2009}[text width=30mm, my box=magenta]{begin{itemize}[before=color{magenta}sffamily]
item try
item try
end{itemize}
}(-80pt)
chronosevent[orange]{2011}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {2007} (chronos end |- n) node {2019};
end{tikzpicture}
end{document}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f247210%2fchronosys-printing-measurement-units%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronograduation[periode]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
In terms of your "gap" I would move the scale to the top like this (choice of colors is yours -- you could make all black)
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronoperiodecoloralternation{black,green,black,green}
chronograduation[periode][dateselevation=0pt]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
add a comment |
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronograduation[periode]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
In terms of your "gap" I would move the scale to the top like this (choice of colors is yours -- you could make all black)
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronoperiodecoloralternation{black,green,black,green}
chronograduation[periode][dateselevation=0pt]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
add a comment |
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronograduation[periode]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
In terms of your "gap" I would move the scale to the top like this (choice of colors is yours -- you could make all black)
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronoperiodecoloralternation{black,green,black,green}
chronograduation[periode][dateselevation=0pt]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronograduation[periode]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
In terms of your "gap" I would move the scale to the top like this (choice of colors is yours -- you could make all black)
documentclass{article}
usepackage{chronosys}
usepackage{ragged2e}
begin{document}
begin{chronology}[startyear=1995, stopyear=2008]
chronoperiodecoloralternation{black,green,black,green}
chronograduation[periode][dateselevation=0pt]{1}
chronoevent[markdepth=20pt, year=false, textwidth=1cm]{1995}{Debate on CEPA Begins}
chronoevent[markdepth=50pt, year=false]{1999}{parbox{2.5cm}{RaggedRight{CEPA Amendments Passed this is a long label}}}
chronoevent[markdepth=50pt, year=false]{2007}{BPA Risk Assessment Begins}
chronoevent[markdepth=20pt, year=false]{2006}{Categorization of DSL}
end{chronology}
end{document}
edited May 27 '15 at 17:48
answered May 27 '15 at 17:24
Aubrey BlumsohnAubrey Blumsohn
2,6111020
2,6111020
add a comment |
add a comment |
A new version (slightly amended) of chronos. The code is only as long as it is because it is attempting to become a more flexible substitute for chronosys
, which is extremely problematic in many ways. (If it does exactly what you want, great. If you want to tweak it a little, good luck.)
documentclass[border=10pt,multi,tikz]{standalone}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
timeline height=2mm,
start date=1995-01-01,
end date=2008-01-01,
only years,
events/.append style={text width=20mm},
timeline line={shorten >=-10mm, -{Triangle Cap[length=10mm]}},
timeline font=footnotesize,
timeline marks,
only text,
}
]
chronosevent{1995}{Debate on CEPA Begins}(-5pt)
chronosevent{1999}{CEPA Amendments Passed}(-15pt)
chronosevent{2007}[text width=30mm]{BPA Risk Assessment Begins}(-30pt)
chronosevent{2006}{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=1995-01-01,
end date=2008-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{1995}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{1999}[my box=green!75!black]{CEPA Amendments Passed}(-15pt)
chronosevent[magenta]{2007}[text width=30mm, my box=magenta]{BPA Risk Assessment Begins}(-30pt)
chronosevent[orange]{2006}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
end{document}
Two versions of your timeline from the code above:
This is actually so beautiful, can you please tell me how to add date as dd/mm/yyyy in the box ?
– Sari
Jan 30 '18 at 8:01
@Sari Try deleting the keyonly text
from the options for thetikzpicture
. You may need to alter the date format, too.
– cfr
Jan 30 '18 at 23:25
add a comment |
A new version (slightly amended) of chronos. The code is only as long as it is because it is attempting to become a more flexible substitute for chronosys
, which is extremely problematic in many ways. (If it does exactly what you want, great. If you want to tweak it a little, good luck.)
documentclass[border=10pt,multi,tikz]{standalone}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
timeline height=2mm,
start date=1995-01-01,
end date=2008-01-01,
only years,
events/.append style={text width=20mm},
timeline line={shorten >=-10mm, -{Triangle Cap[length=10mm]}},
timeline font=footnotesize,
timeline marks,
only text,
}
]
chronosevent{1995}{Debate on CEPA Begins}(-5pt)
chronosevent{1999}{CEPA Amendments Passed}(-15pt)
chronosevent{2007}[text width=30mm]{BPA Risk Assessment Begins}(-30pt)
chronosevent{2006}{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=1995-01-01,
end date=2008-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{1995}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{1999}[my box=green!75!black]{CEPA Amendments Passed}(-15pt)
chronosevent[magenta]{2007}[text width=30mm, my box=magenta]{BPA Risk Assessment Begins}(-30pt)
chronosevent[orange]{2006}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
end{document}
Two versions of your timeline from the code above:
This is actually so beautiful, can you please tell me how to add date as dd/mm/yyyy in the box ?
– Sari
Jan 30 '18 at 8:01
@Sari Try deleting the keyonly text
from the options for thetikzpicture
. You may need to alter the date format, too.
– cfr
Jan 30 '18 at 23:25
add a comment |
A new version (slightly amended) of chronos. The code is only as long as it is because it is attempting to become a more flexible substitute for chronosys
, which is extremely problematic in many ways. (If it does exactly what you want, great. If you want to tweak it a little, good luck.)
documentclass[border=10pt,multi,tikz]{standalone}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
timeline height=2mm,
start date=1995-01-01,
end date=2008-01-01,
only years,
events/.append style={text width=20mm},
timeline line={shorten >=-10mm, -{Triangle Cap[length=10mm]}},
timeline font=footnotesize,
timeline marks,
only text,
}
]
chronosevent{1995}{Debate on CEPA Begins}(-5pt)
chronosevent{1999}{CEPA Amendments Passed}(-15pt)
chronosevent{2007}[text width=30mm]{BPA Risk Assessment Begins}(-30pt)
chronosevent{2006}{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=1995-01-01,
end date=2008-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{1995}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{1999}[my box=green!75!black]{CEPA Amendments Passed}(-15pt)
chronosevent[magenta]{2007}[text width=30mm, my box=magenta]{BPA Risk Assessment Begins}(-30pt)
chronosevent[orange]{2006}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
end{document}
Two versions of your timeline from the code above:
A new version (slightly amended) of chronos. The code is only as long as it is because it is attempting to become a more flexible substitute for chronosys
, which is extremely problematic in many ways. (If it does exactly what you want, great. If you want to tweak it a little, good luck.)
documentclass[border=10pt,multi,tikz]{standalone}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
timeline height=2mm,
start date=1995-01-01,
end date=2008-01-01,
only years,
events/.append style={text width=20mm},
timeline line={shorten >=-10mm, -{Triangle Cap[length=10mm]}},
timeline font=footnotesize,
timeline marks,
only text,
}
]
chronosevent{1995}{Debate on CEPA Begins}(-5pt)
chronosevent{1999}{CEPA Amendments Passed}(-15pt)
chronosevent{2007}[text width=30mm]{BPA Risk Assessment Begins}(-30pt)
chronosevent{2006}{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=1995-01-01,
end date=2008-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{1995}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{1999}[my box=green!75!black]{CEPA Amendments Passed}(-15pt)
chronosevent[magenta]{2007}[text width=30mm, my box=magenta]{BPA Risk Assessment Begins}(-30pt)
chronosevent[orange]{2006}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {1995} (chronos end |- n) node {2008};
end{tikzpicture}
end{document}
Two versions of your timeline from the code above:
answered Dec 12 '16 at 0:40
cfrcfr
157k8191390
157k8191390
This is actually so beautiful, can you please tell me how to add date as dd/mm/yyyy in the box ?
– Sari
Jan 30 '18 at 8:01
@Sari Try deleting the keyonly text
from the options for thetikzpicture
. You may need to alter the date format, too.
– cfr
Jan 30 '18 at 23:25
add a comment |
This is actually so beautiful, can you please tell me how to add date as dd/mm/yyyy in the box ?
– Sari
Jan 30 '18 at 8:01
@Sari Try deleting the keyonly text
from the options for thetikzpicture
. You may need to alter the date format, too.
– cfr
Jan 30 '18 at 23:25
This is actually so beautiful, can you please tell me how to add date as dd/mm/yyyy in the box ?
– Sari
Jan 30 '18 at 8:01
This is actually so beautiful, can you please tell me how to add date as dd/mm/yyyy in the box ?
– Sari
Jan 30 '18 at 8:01
@Sari Try deleting the key
only text
from the options for the tikzpicture
. You may need to alter the date format, too.– cfr
Jan 30 '18 at 23:25
@Sari Try deleting the key
only text
from the options for the tikzpicture
. You may need to alter the date format, too.– cfr
Jan 30 '18 at 23:25
add a comment |
why the line of 2008 above the box of 2007? I did not change any code. I want to change the line of 2008 below of the box of 2007.
documentclass[border=10pt,multi,tikz]{standalone}
%usepackage[UTF8]{ctex}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usepackage{enumitem}
%usepackage{lipsum}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=2007-01-01,
end date=2019-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{2007}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{2008}[my box=green!75!black]{CEPA Amendments Passed}(-40pt)
chronosevent[magenta]{2009}[text width=30mm, my box=magenta]{begin{itemize}[before=color{magenta}sffamily]
item try
item try
end{itemize}
}(-80pt)
chronosevent[orange]{2011}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {2007} (chronos end |- n) node {2019};
end{tikzpicture}
end{document}
add a comment |
why the line of 2008 above the box of 2007? I did not change any code. I want to change the line of 2008 below of the box of 2007.
documentclass[border=10pt,multi,tikz]{standalone}
%usepackage[UTF8]{ctex}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usepackage{enumitem}
%usepackage{lipsum}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=2007-01-01,
end date=2019-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{2007}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{2008}[my box=green!75!black]{CEPA Amendments Passed}(-40pt)
chronosevent[magenta]{2009}[text width=30mm, my box=magenta]{begin{itemize}[before=color{magenta}sffamily]
item try
item try
end{itemize}
}(-80pt)
chronosevent[orange]{2011}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {2007} (chronos end |- n) node {2019};
end{tikzpicture}
end{document}
add a comment |
why the line of 2008 above the box of 2007? I did not change any code. I want to change the line of 2008 below of the box of 2007.
documentclass[border=10pt,multi,tikz]{standalone}
%usepackage[UTF8]{ctex}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usepackage{enumitem}
%usepackage{lipsum}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=2007-01-01,
end date=2019-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{2007}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{2008}[my box=green!75!black]{CEPA Amendments Passed}(-40pt)
chronosevent[magenta]{2009}[text width=30mm, my box=magenta]{begin{itemize}[before=color{magenta}sffamily]
item try
item try
end{itemize}
}(-80pt)
chronosevent[orange]{2011}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {2007} (chronos end |- n) node {2019};
end{tikzpicture}
end{document}
why the line of 2008 above the box of 2007? I did not change any code. I want to change the line of 2008 below of the box of 2007.
documentclass[border=10pt,multi,tikz]{standalone}
%usepackage[UTF8]{ctex}
usepackage{pgfcalendar}
usepackage{datenumber,xparse,fp}
usepackage{enumitem}
%usepackage{lipsum}
usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
makeatletter
ExplSyntaxOn
tl_new:N l_chronos_date_tl
tl_new:N l_chronos_dateformat_tl
tl_new:N l_chronos_year_tl
tl_new:N l_chronos_yearformat_tl
tl_set:Nn l_chronos_dateformat_tl { !d/!m/!Y }
tl_set:Nn l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
cs_new_protected_nopar:Npn chronos_year_shorten:n #1
{
chronos_year_shorten_aux:w #1 q_stop % expl3 manuaal, 46
}
cs_new_protected_nopar:Npn chronos_year_shorten_aux:w #1 #2 #3 #4 q_stop
{
#3 #4
}
cs_generate_variant:Nn chronos_year_shorten:n { V , c }
cs_generate_variant:Nn int_abs:n { c }
cs_generate_variant:Nn tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
cs_new_protected_nopar:Npn chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_date_tl l_chronos_dateformat_tl
tl_replace_all:Nnx l_chronos_date_tl { !a } { pgfcalendarweekdayshortname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !A } { pgfcalendarweekdayname{thechronos@weekday} }
tl_replace_all:Nnx l_chronos_date_tl { !b } { pgfcalendarmonthshortname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !B } { pgfcalendarmonthname{csname chronos@#1monthendcsname} }
tl_replace_all:Nnx l_chronos_date_tl { !d } { csname chronos@#1dayendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !E } { chronos_dateformat_era:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !m } { csname chronos@#1monthendcsname }
tl_replace_all:Nnx l_chronos_date_tl { !q } { chronos_dateformat_sign:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Q } { chronos_dateformat_signs:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !y } { chronos_year_shorten:c { chronos@#1year } }
tl_replace_all:Nnx l_chronos_date_tl { !Y } { int_abs:c { chronos@#1year } }
l_chronos_date_tl
}
cs_new_protected_nopar:Npn chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
tl_set_eq:NN l_chronos_year_tl l_chronos_yearformat_tl
tl_replace_all:Nnx l_chronos_year_tl { !E } { chronos_dateformat_era:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !q } { chronos_dateformat_sign:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Q } { chronos_dateformat_signs:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !y } { chronos_year_shorten:n { #1 } }
tl_replace_all:Nnx l_chronos_year_tl { !Y } { int_abs:n { #1 } }
l_chronos_year_tl
}
cs_new_protected_nopar:Npn chronos_dateformat_sign:n #1
{
int_compare:nT { #1 < 0 } { - }
}
cs_generate_variant:Nn chronos_dateformat_sign:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_signs:n #1
{
int_compare:nTF
{ #1 < 0 } { - }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { + }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_signs:n { c }
cs_new_protected_nopar:Npn chronos_dateformat_era:n #1
{
int_compare:nTF
{ #1 < 0 } { chronos@yearbce }
{
int_compare:nT { #1 > 0 }
{
ifchronos@yearzerorelax
else
int_compare:nT { #1 > 1} { chronos@yearce }
fi
}
}
}
cs_generate_variant:Nn chronos_dateformat_era:n { c }
cs_new_protected_nopar:Npn chronos_set_dateformat:n #1
{
tl_set:Nn l_chronos_dateformat_tl { #1 }
tl_replace_all:Nnn l_chronos_dateformat_tl { ~ } { c_space_token }
}
cs_new_protected_nopar:Npn chronos_set_yearformat:n #1
{
tl_set:Nn l_chronos_yearformat_tl { #1 }
tl_replace_all:Nnn l_chronos_yearformat_tl { ~ } { c_space_token }
}
% user interface
NewDocumentCommand chronos@setdateformat { m }
{
chronos_set_dateformat:n { #1 }
}
NewDocumentCommand chronos@setyearformat { m }
{
chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
NewDocumentCommand chronos@showdate { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_dateformat:n { #1 }
}
pgfcalendarjuliantoweekday{csname thechronos@#2dateendcsname}{c@chronos@weekday}%
chronos_show_date:n { #2 }
group_end:
}
NewDocumentCommand chronos@showyear { o m }
{
group_begin:
IfValueT { #1 }
{
chronos_set_yearformat:n { #1 }
}
chronos_show_year:n { #2 }
group_end:
}
ExplSyntaxOff
newlengthchronos@tempdima
newcounter{chronos@date}
newcounter{chronos@startdate}
newcounter{chronos@enddate}
newcounter{chronos@startyear}
newcounter{chronos@endyear}
newcounter{chronos@yeardate}
newcounter{chronos@thingdate}
newcounter{chronos@otherthingdate}
newcounter{chronos@weekday}
newcounter{chronos@tempcnta}
newififchronos@marks
chronos@marksfalse
newififchronos@timeline@showyears
chronos@timeline@showyearstrue
newififchronos@eventyearsonline
chronos@eventyearsonlinefalse
newififchronos@yearzero
chronos@yearzerofalse
newififchronos@onlytext
chronos@onlytextfalse
newififchronos@markeras
chronos@markerasfalse
newififchronos@yearsonline
chronos@yearsonlinefalse
newififchronos@eventdatessplit
chronos@eventdatessplitfalse
pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
tikzset{%
/handlers/.chronos too/.code={%
edefchronos@tempc{pgfkeyscurrentpath}%
edefchronos@tempd{#1}%
tikzset{%
pgfkeyscurrentpath @too/.code={%
tikzset{%
/chronos/chronos@tempd/.append style={##1},
}%
},
chronos@tempc/.forward to=chronos@tempc @too,
}%
},
chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
tikzset{%
align=center,
anchor=mid,
fixed point arithmetic,
/chronos/.cd,
#1,
timeline config,
timeline config/.code={},
}%
ifnumchronos@startyear=chronos@endyear
tikzset{%
/chronos/timeline no years,
}%
fi
setlengthchronos@tempdima{chronos@timelinemargin}%
ifchronos@markeras
{%
chronos@timelinefont
pgfmathsetmacrochronos@tempe{((width("chronos@bce"))>(width("chronos@ce"))) ? (width("chronos@bce")) : (width("chronos@ce"))}%
xdefchronos@tempf{chronos@tempe}%
}%
addtolengthchronos@tempdima{chronos@tempf pt}%
fi
pgfmathsetmacrochronos@unit{(chronos@width-2*chronos@tempdima)/(thechronos@enddate-thechronos@startdate)}%
draw [/chronos/timeline@line, line width=chronos@height] (-chronos@tempdima,0) coordinate (chronos pre) -- +(chronos@width,0) coordinate (chronos post);
coordinate (chronos base) at (0,-.5*chronos@height);
coordinate (chronos top) at (0,.5*chronos@height);
coordinate (chronos foot) at (0,{-.5*chronos@height-chronos@borderheight});
coordinate (chronos head) at (0,{.5*chronos@height+chronos@borderheight});
coordinate (chronos start) at (0,0);
coordinate (chronos end) at ([xshift=-chronos@tempdima]chronos post);
ifdimchronos@borderheight>0pt
fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
fi
ifchronos@timeline@showyears
pgfmathsetcounter{chronos@startyear}{chronos@startyear}%
pgfmathsetcounter{chronos@endyear}{chronos@endyear}%
deftempa{none}%
ifxchronos@stepfromtempa
deftempa{01}%
ifxchronos@startmonthtempa
ifxchronos@startdaytempa
elsestepcounter{chronos@startyear}%
fi
elsestepcounter{chronos@startyear}%
fi
else
pgfmathsetcounter{chronos@startyear}{chronos@stepfrom}%
fi
deftempa{12}%
deftempb{31}%
ifxchronos@endmonthtempa
ifxchronos@enddaytempb
stepcounter{chronos@endyear}%
fi
fi
ifnumvalue{chronos@endyear}<value{chronos@startyear}setcounter{chronos@endyear}{thechronos@startyear}fi
pgfmathsetmacrochronos@nextstep{int(((thechronos@startyear+chronos@stepyears)>thechronos@endyear) ? thechronos@endyear : (thechronos@startyear+chronos@stepyears))}%
ifchronos@yearzerosetcounter{chronos@tempcnta}{1}elsesetcounter{chronos@tempcnta}{0}fi
foreach b [evaluate=b as i using {((b==0)&&(thechronos@tempcnta==0)) ? 1 : int(b)}, remember=i as ilast (initially pi)] in {thechronos@startyear,chronos@nextstep,...,thechronos@endyear} {%
ifnumi=ilastrelax
else
pgfcalendardatetojulian{{i}-01-01}{c@chronos@yeardate}%
ifchronos@yearzerorelaxelseifnum0<iaddtocounter{chronos@yeardate}{-366}fifi
pgfmathsetmacrochronos@tempa{(thechronos@yeardate-thechronos@startdate)*chronos@unit}%
ifchronos@yearsonline
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year on line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [/chronos/timeline mark on line] (chronos@year@i.south) -- (chronos@year@i |- chronos base);
path [/chronos/timeline mark on line] (chronos@year@i.north) -- (chronos@year@i |- chronos top);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {chronos@timelinefontchronos@ce};
fi
else
node (chronos@year@i) [/chronos/.cd, timeline@years, timeline year off line] at (chronos@tempa pt,0) {chronos@timelinefontchronos@showyear{i}};
ifchronos@marks
path [shorten <=.5*chronos@height, /chronos/timeline mark off line] (chronos@tempa pt, 0) -- (chronos@year@i);
fi
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
fi
}%
else
ifchronos@markeras
path (chronos pre) +(chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@bce};
path (chronos post) +(-chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {chronos@timelinefontchronos@ce};
fi
fi
ifchronos@eventyearsonline
tikzset{%
/chronos/timeline years=on line,
}%
fi
},
chronos set date/.code args={#1:#2:#3:#4}{%
pgfcalendardatetojulian{{#1}-#2-#3}{c@chronos@date}%
setcounter{chronos@#4date}{thechronos@date}%
ifchronos@yearzerorelax
else
setcounter{chronos@tempcnta}{#1}%
ifnum0<value{chronos@tempcnta}%
addtocounter{chronos@#4date}{-366}%
fi
fi
expandafterdefcsname chronos@#4yearendcsname{#1}%
expandafterdefcsname chronos@#4monthendcsname{#2}%
expandafterdefcsname chronos@#4dayendcsname{#3}%
},
chronos date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:thing}%
},
chronos period date/.style args={#1-#2-#3}{%
/tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
timeline config/.code={},
date format/.code={%
chronos@setdateformat{#1}%
},
year format/.code={%
chronos@setyearformat{#1}%
},
step years/.store in=chronos@stepyears,
step from year/.store in=chronos@stepfrom,
start date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
},
},
end date/.style args={#1-#2-#3}{%
/chronos/timeline config/.append code={%
tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
},
},
ce year label/.store in=chronos@yearce,
bce year label/.store in=chronos@yearbce,
timeline ce label/.store in=chronos@ce,
timeline bce label/.store in=chronos@bce,
timeline width/.store in=chronos@width,
timeline height/.store in=chronos@height,
width/.forward to=/chronos/timeline width,
height/.forward to=/chronos/timeline height,
timeline border height/.store in=chronos@borderheight,
timeline border inner colour/.code={colorlet{chronos@borderinner}{#1}},
timeline border outer colour/.code={colorlet{chronos@borderouter}{#1}},
timeline mark eras/.is if=chronos@markeras,
timeline margin/.store in=chronos@timelinemargin,
timeline font/.store in=chronos@timelinefont,
timeline years set/.store in=chronos@timelineyears,
timeline years/.is choice,
timeline years/.forward to=/chronos/timeline years set,
timeline years/above/.code={%
tikzset{%
/chronos/timeline@years/.style={above, anchor=south, yshift=.5*chronos@height},
}%
},
timeline years/below/.code={%
tikzset{%
/chronos/timeline@years/.style={below, anchor=north, yshift=-.5*chronos@height},
}%
},
timeline years/on line/.code={%
chronos@yearsonlinetrue
tikzset{%
/chronos/timeline@years/.style={anchor=center},
}%
},
only years/.code={%
edeftempa{}%
edeftempb{#1}%
ifxtempatempbchronos@setdateformat{!Y}elsechronos@setdateformat{#1}fi
tikzset{%
/tikz/chronos date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:thing}%
},
/tikz/chronos period date/.style={%
/tikz/chronos set date/.expanded={##1:01:01:otherthing}%
},
}%
},
only text/.code={%
tikzset{/chronos/only years}%
chronos@setdateformat{}%
chronos@onlytexttrue
},
year zero/.is if=chronos@yearzero,
background/.code={%
colorlet{chronos@background}{#1}%
},
timeline marks/.is if=chronos@marks,
timeline show years/.is if=chronos@timeline@showyears,
timeline no years/.code={%
tikzset{%
/chronos/timeline show years=false,
}%
},
lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*chronos@height+chronos@borderheight}},
events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=footnotesize},
period/.style={draw},
period event line/.style={/chronos/lines},
period event/.style={/chronos/events},
event line/.style={/chronos/lines},
event/.style={/chronos/events},
event years on line/.is if=chronos@eventyearsonline,
event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
event dates split/.is if=chronos@eventdatessplit,
event date split/.style={/chronos/event},
event distance/.store in=chronos@eventdistance,
special date/.store in=chronos@specialdate,
timeline@line/.style={draw},
timeline line/.chronos too=timeline@line,
timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
timeline mark too/.code={%
tikzset{%
/chronos/.cd,
timeline mark on line/.append style={#1},
timeline mark off line/.append style={#1},
}%
},
timeline year too/.code={%
tikzset{%
/chronos/.cd,
timeline year on line/.append style={#1},
timeline year off line/.append style={#1},
}%
},
timeline mark/.forward to=/chronos/timeline mark too,
timeline year/.forward to=/chronos/timeline year too,
start date=1001-10-01,
end date=1003-06-14,
timeline width=100mm,
timeline height=1pt,
timeline border height=0pt,
chronos date=1850-01-01,
chronos period date=1851-01-01,
step years=1,
timeline years=above,
background=white,
timeline border inner colour=black,
timeline border outer colour=chronos@background,
step from year=none,
special date=none,
ce year label={textsc{ce}},
bce year label={textsc{bce}},
event distance=-10pt,
timeline ce label={CE},
timeline bce label={BCE},
timeline margin=10pt,
timeline font=sffamily,
}
NewDocumentCommand chronosevent { O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2},
}%
pgfmathsetmacrochronos@offset{(#5 < 0pt) ? (#5-.5*chronos@height-chronos@borderheight) : (#5+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#5 < 0pt) ? "north" : "south"}%
scoped[on background layer]{%
ifchronos@eventdatessplit
ifchronos@onlytextrelax
else
pgfmathsetmacrochronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,-chronos@offset pt) node [anchor=chronos@invanchor, /chronos/event date split, #3] {chronos@showdate{thing}};
fi
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {#4};
else
path [postaction={/chronos/event line, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/event, #3] {ifchronos@onlytextrelaxelsechronos@showdate{thing}\fi#4};
fi
}%
ifchronos@eventyearsonline
edeftempa{none}%
edeftempb{chronos@specialdate}%
ifxtempatempbelseletchronos@thingyearchronos@specialdatetikzset{/chronos/special date=none}fi
node [/chronos/.cd, event year on line] at ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) {chronos@thingyear};
fi
}
NewDocumentCommand chronosspecialdate { m }
{%
tikzset{%
/chronos/special date=#1,
}%
}
NewDocumentCommand chronosperiod { O {} m O {} m O {} +m D () { chronos@eventdistance } }
{%
tikzset{%
chronos date/.expanded={#2}, chronos period date/.expanded={#4}
}%
pgfmathsetmacrochronos@offset{(#7 < 0pt) ? (#7-.5*chronos@height-chronos@borderheight) : (#7+.5*chronos@height+chronos@borderheight)}%
pgfmathsetmacrochronos@anchor{(#7 < 0pt) ? "north" : "south"}%
ifchronos@yearsonline
pgfmathsetmacrochronos@borderoffset{(#7 < 0pt) ? (-.5*chronos@height-.5*chronos@borderheight) : (.5*chronos@height+.5*chronos@borderheight)}%
path [postaction={line width=chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},chronos@borderoffset pt);
else
path [postaction={line width=chronos@height, /chronos/period, #1}] ({(thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- ({(thechronos@otherthingdate-thechronos@startdate)*chronos@unit pt},0);
fi
scoped[on background layer]{path [postaction={/chronos/period event line, #3}] ({(.5*thechronos@otherthingdate+.5*thechronos@thingdate-thechronos@startdate)*chronos@unit pt},0) -- +(0,chronos@offset pt) node [anchor=chronos@anchor, /chronos/period event, #5] {ifchronos@onlytextrelaxelsechronos@showdate{thing}--chronos@showdate{otherthing}\fi#6};}
}
makeatother
begin{document}
begin{tikzpicture}
[
chronos={%
timeline width=100mm,
start date=2007-01-01,
end date=2019-01-01,
events/.append style={text width=20mm},
timeline font=footnotesize,
timeline marks,
timeline height=5mm,
only text,
timeline years=on line,
timeline border height=5pt,
},
my box/.style={draw=#1, rounded corners, text=#1, thick},
]
chronosevent[blue]{2007}[my box=blue]{Debate on CEPA Begins}(-5pt)
chronosevent[green!75!black]{2008}[my box=green!75!black]{CEPA Amendments Passed}(-40pt)
chronosevent[magenta]{2009}[text width=30mm, my box=magenta]{begin{itemize}[before=color{magenta}sffamily]
item try
item try
end{itemize}
}(-80pt)
chronosevent[orange]{2011}[my box=orange]{Categorization of DSL}(-5pt)
path [every node/.style={font=largebfseriessffamily}] (chronos start |- current bounding box.north) node (n) [above] {2007} (chronos end |- n) node {2019};
end{tikzpicture}
end{document}
answered 4 mins ago
dozerdozer
42129
42129
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f247210%2fchronosys-printing-measurement-units%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The value of
markdepth
must be a dimen not a number.– Ulrike Fischer
May 27 '15 at 13:59