If you load xcolor
, you can use \colorbox
. This uses a regular "framed box", so you can set the values of \fboxsep
to decrease the border.
In most cases, text-related formatting of this sort also transfers to math-related content. However, a verbatim switch is sometimes required since boxing reverts back to text mode. As such, use
\colorbox{<color>}{$<math content>$}
and not
$\colorbox{<color>}{<math content>}$
Here's a small example in LaTeX illustrating the use of \colorbox
together with a modification of \fboxsep
:
![enter image description here](https://i.stack.imgur.com/Oeaqa.png)
\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
Here is \colorbox{blue!50}{coloured text} with a coloured \colorbox{green!30}{$f(x)$} function. \par \bigskip
\setlength{\fboxsep}{2pt}% No "border" around coloured box
Here is \colorbox{blue!50}{coloured text} with a coloured \colorbox{green!30}{$f(x)$} function. \par
\end{document}
Current version of chronos is available at:
https://tex.stackexchange.com/a/342699/ (2016-12-06)
Here's a basic version. Essentially, the style chronos
sets up the basic timeline. chronos date
can then be used to get the appropriate point on that timeline from which to drop the lines to the event nodes. Information from chronos date
can also be used in the node itself. Here it is used to print the date before the node content.
I've used a loop to add events, but this is just to save typing. They could be added one by one if preferred.
The basic timeline schema should be laid out like this:
\begin{tikzpicture}
[
chronos={%
<options>
},
]
<events and such on the timeline specified in the usual way>
\end{tikzpicture}
The options for chronos
are as follows:
width=<dimension>
,
height=<dimension>
,
start date=YYYY-MM-DD
,
end date=YYYY-MM-DD
,
By default the timeline is 1pt
high and 100mm
wide and the start and end dates are at the beginning of the last millennium.
chronos date=YYYY-MM-DD
can then be used in the picture to help place things on the timeline. For example, I use it below in a loop as follows where \i
holds the date for the current iteration, \j
holds the text and \k
holds the distance to offset the node below the timeline.
\path [postaction={draw=gray, -{Triangle[width=1.5pt,reversed,length=.75pt,fill=gray]}}, chronos date/.expanded={\i}] ({(\thechronosthingdate-\thechronosstartdate)*\chronosunit pt},0) -- +(0,-\k) node [anchor=north, fill opacity=.75, fill=gray!25, draw=gray, rounded corners, font=\footnotesize\sffamily] {\chronosthingday/\chronosthingmonth/\chronosthingyear\\\j};
chronos date
is fed \i
i.e. the date and this sets both \thechronosthingdate
and each of \chronosthingyear
, \chronosthingmonth
and \chronosthingday
. The first is a number which can be used to calculate how far along the timeline to place the event. This should be at
({(\thechronosthingdate-\thechronosstartdate)*\chronosunit pt},0)
\thechronosstartdate
holds a number corresponding to the start date of the timeline and \chronosunit
holds the length in points allowed for each day. This is calculated when chronos
is used from the start and end dates and the width. An offset of 10pt is allowed at each end so that the first date isn't right at the start nor the last date right at the end.
\chronosthingday
, \chronosthingmonth
and \chronosthingyear
hold the day, month and year set by chronos date
respectively and can be used in the content of nodes or labels, if desired.
Feeding our loop the following set of triples (\i/\j/\k
)
{1001-11-05}/{No fireworks}/10pt
{1002-07-04}/{No fireworks}/80pt
{1002-05-01}/{May Day}/50pt
{1002-06-21}/{Summer Solstice}/10pt
thus yields
![chronos](https://i.stack.imgur.com/eTazs.png)
Complete code:
\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{datenumber}
\usetikzlibrary{arrows.meta}
\newcounter{chronosstartdate}
\newcounter{chronosenddate}
\newcounter{chronosstartyear}
\newcounter{chronosendyear}
\newcounter{chronosyeardate}
\newcounter{chronosthingdate}
\pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
\tikzset{
chronos/.code={% https://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
\tikzset{%
align=center,
anchor=mid,
/chronos/.cd,
#1
}%
\setstartyear{\chronosstartyear}%
\setmydatenumber{chronosstartdate}{\chronosstartyear}{\chronosstartmonth}{\chronosstartday}%
\setmydatenumber{chronosenddate}{\chronosendyear}{\chronosendmonth}{\chronosendday}%
\pgfmathsetmacro\chronosunit{(\chronoswidth-20pt)/(\thechronosenddate-\thechronosstartdate)}%
\draw [line width=\chronosheight] (-10pt,0) coordinate (chronos pre) -- +(\chronoswidth,0) coordinate (chronos post);
\coordinate (chronos start) at (0,0);
\coordinate (chronos end) at ([xshift=-10pt]chronos post);
\setcounter{chronosstartyear}{\chronosstartyear}%
\setcounter{chronosendyear}{\chronosendyear}%
\def\tempa{01}%
\ifx\chronosstartmonth\tempa
\ifx\chronosstartday\tempa
\else\stepcounter{chronosstartyear}%
\fi
\else\stepcounter{chronosstartyear}%
\fi
\def\tempa{12}%
\def\tempb{31}%
\ifx\chronosendmonth\tempa
\ifx\chronosendday\tempb
\stepcounter{chronosendyear}%
\fi
\fi
\foreach \i in {\thechronosstartyear,...,\thechronosendyear} {%
\setmydatenumber{chronosyeardate}{\i}{01}{01}%
\node [above, anchor=south] at ({(\thechronosyeardate-\thechronosstartdate)*\chronosunit pt},0) {\i}; }
},
chronos date/.code args={#1-#2-#3}{%
\tikzset{%
/chronos/.cd,
thing year={#1},
thing month={#2},
thing day={#3},
}%
\setmydatenumber{chronosthingdate}{\chronosthingyear}{\chronosthingmonth}{\chronosthingday}%
},
/chronos/.search also={/tikz},
/chronos/.cd,
start year/.store in=\chronosstartyear,
start month/.store in=\chronosstartmonth,
start day/.store in=\chronosstartday,
end year/.store in=\chronosendyear,
end month/.store in=\chronosendmonth,
end day/.store in=\chronosendday,
thing year/.store in=\chronosthingyear,
thing month/.store in=\chronosthingmonth,
thing day/.store in=\chronosthingday,
start date/.style args={#1-#2-#3}{%
start year={#1},
start month={#2},
start day={#3},
},
end date/.style args={#1-#2-#3}{%
end year={#1},
end month={#2},
end day={#3},
},
width/.store in=\chronoswidth,
height/.store in=\chronosheight,
start date=1001-10-01,
end date=1003-06-14,
width=100mm,
height=1pt,
chronos date=1850-01-01,
}
\begin{document}
\begin{tikzpicture}
[chronos]
\foreach \i/\j/\k in {{1001-11-05}/{No fireworks}/10pt,{1002-07-04}/{No fireworks}/80pt,{1002-05-01}/{May Day}/50pt,{1002-06-21}/{Summer Solstice}/10pt}
{%
\path [postaction={draw=gray, -{Triangle[width=1.5pt,reversed,length=.75pt,fill=gray]}}, chronos date/.expanded={\i}] ({(\thechronosthingdate-\thechronosstartdate)*\chronosunit pt},0) -- +(0,-\k) node [anchor=north, fill opacity=.75, fill=gray!25, draw=gray, rounded corners, font=\footnotesize\sffamily] {\chronosthingday/\chronosthingmonth/\chronosthingyear\\\j};
}
\end{tikzpicture}
\end{document}
Best Answer
Here is a possible solution for simple cases using
blend mode
(logo.png
is your first B&W logo):