Introduction
How to draw beautiful tables of signs and variations for math publications using Latex and the powerful tkz-tab package ?
Once we understand the mechanism of the three main macros to know (tkzTabInit
, tkzTabLine
,
tkzTabVar
), a table of signs and variations is built in few minutes.
Table skeleton, tkzTabInit
Import the tkz-tab package in the Latex document :
\usepackage{tkz-tab}
To initialize a table, use \tkzTabInit
, command to be placed into a tkzpicture
environment.
\documentclass[tikz]{standalone}
\usepackage{amsmath,amssymb}
\usepackage{tkz-tab}
\begin{document}
\begin{tikzpicture}
\tkzTabInit[lgt=3,espcl=1.5]
{$x$ / 1 , $f'(x)=-\sin(x)$ / 1, $f(x)=cos(x)$ / 2 }
{$0$, $\dfrac{\pi}{2}$, $\pi$, $\dfrac{3\pi}{2}$, $2\pi$}
\end{tikzpicture}
\end{document}
The \tkzTabInit
command global syntax is :
\tkzTabinit[local options]{e(1)/h(1),...,e(p)/h(p)}{a(1),...,a(n)}
2 mandatory lists and facultative options.
{e(1)/h(1),...,e(p)/h(p)}
: left column data. 1 elemente(p)
\( \implies \) 1 row, so the number of elements define the number of rows of the table. Heights (h(p)
) are in centimeters.{a(1),...,a(n)}
: header values. Define the number of columns of the table after the first left column.
In the above example, 2 options applied :
lgt
resizes the first column width (in centimeters).espcl
resizes the space between 2 values in the header (in centimeters).
The minimal code for a table tkzTab
is the following:
\tkzTabInit{ / 1}{ , }
Use braces to escape "," for numbers :
\tkzTabInit{$x$ / 1, $x^2$ / 1}{ $0$, ${0,5}$, $1$ }
tkz-tab program structure
When the table skeleton is ready using \tkzTabInit
, the global program structure is then the following :
\begin{tikzpicture}
\tkzTabInit{…}{…}
command for line 1
command for line 2
…
\end{tikzpicture}
Commands are (exhaustive list) :
\tkzTabLine
: creates a signs line\tkzTabVar
: creates a variations line\tkzTabIma
,\tkzTabVal
: adds intermediate values\tkzTabSlope
: adds derivatives values in signs line\tkzTabTan
,\tkzTabTan
: adds horizontal tangents
The first 2 commands are the most important.
Signs line, tkzTabLine
The argument of the \tkzTabLine
command to create a signs line is a list. For \(n\) values in the header of the table,
\tkzTabLine
expects a list of \(2n - 1\) elements : \(n\) elements placed below the values and \(n - 1\) elements placed
between the values :
\begin{tikzpicture}
\tkzTabInit[lgt=3,espcl=1.5]
{$x$ / 1 , $f'(x)=-\sin(x)$ / 1, $f(x)=cos(x)$ / 2 }
{$0$, $\dfrac{\pi}{2}$, $\pi$, $\dfrac{3\pi}{2}$, $2\pi$}
\tkzTabLine
{ , , - , , , , + , , }
\end{tikzpicture}
Symbols allowed below values are :
z
: zero centered on a vertical dotted linet
: vertical dotted lined
: vertical double bar
Notice : they are not allowed between 2 values.
\begin{tikzpicture}
\tkzTabInit[lgt=3,espcl=1.5]
{$x$ / 1 , $f'(x)=-\sin(x)$ / 1, $f(x)=cos(x)$ / 2 }
{$0$, $\dfrac{\pi}{2}$, $\pi$, $\dfrac{3\pi}{2}$, $2\pi$}
\tkzTabLine
{z, , - , , z, , + , ,z}
\end{tikzpicture}
The symbol h
draws a forbidden zone (function not defined) : the interval is hatched. Obviously, the symbol
h
can only be applied for an element in the list between 2 values.
\begin{tikzpicture}
\tkzTabInit[lgt=3]
{$x$ / 1 , $f'(x)$ / 1, $f(x)=\sqrt{\dfrac{x-1}{x+1}}$ / 2 }
{$-\infty$, $-1$, $1$, $+\infty$}
\tkzTabLine
{ , + , d , h , d, +, }
\end{tikzpicture}
Variations line, tkzTabVar
The \tkTabVar
macro builds a variation line. The argument is a list like \tkTabLine
.
For \(n\) header values, the list will contain \(n\) groups.
- \( \pm / e \) to position an element below a value : \(+\) at the top, \(-\) at the bottom of the variation line.
/R
if there is nothing to do for a value.
\begin{tikzpicture}
\tkzTabInit[lgt=3]
{$x$ / 1 , $f'(x)=-\sin(x)$ / 1, $f(x)=cos(x)$ / 2 }
{$0$, $\dfrac{\pi}{2}$, $\pi$, $\dfrac{3\pi}{2}$, $2\pi$}
\tkzTabLine
{z, , - , , z, , + , ,z}
\tkzTabVar
{ +/$1$, R/ , -/$-1$, R/, +/$1$}
\end{tikzpicture}
About continuity, discontinuity and forbidden zones, symbols are :
- Vertical double bar and continuity :
-C/x
,+C/x
- Vertical double bar and discontinuity :
-D/x
,+D/x
,D-/x
,D+/x
- Forbidden zone :
-H/x
,+H/x
- Combinations:
-CH/x
,+CH/x
,-DH/x
,+DH/x
Concrete examples are better than very long explanations about C/D/H symbols :
\begin{tikzpicture}
\tkzTabInit[lgt=3,espcl=1.5]
{$x$ / 1 , $f'(x)$ / 1, $f(x)=\sqrt{\dfrac{x-1}{x+1}}$ / 2 }
{$-\infty$, $-1$, $1$, $+\infty$}
\tkzTabLine
{ , + , d , h , d, +, }
\tkzTabVar
{ -/1 , +DH/$+\infty$, -C/0, +/1}
\end{tikzpicture}
\begin{tikzpicture}
\tkzTabInit[lgt=2.75]
{ $x$/1 , $f'(x)$/1 , $f(x) = tan(x)$/2 }
{ $0$, $\dfrac{\pi}{2}$, $\pi$}
\tkzTabLine
{ , + , d , + , }
\tkzTabVar
{ -/$0$ , +D-/$+\infty$/$-\infty$ , +/$0$}
\end{tikzpicture}
Intermediate values in variations lines, tkzTabIma, tkzTabVal
tkzTabIma
To add values in arrows of variations for existing header values defined with \tkzTabInit
, use \tkzTabIma
after \tkzTabVar
.
\tkzTabIma {start arrow position}{end arrow position}{header value position}{value to set on line}
\begin{tikzpicture}
\tkzTabInit[lgt=3,espcl=1.5]
{$x$ / 1 , $f'(x)=-\sin(x)$ / 1, $f(x)=cos(x)$ / 2 }
{$0$, $\dfrac{\pi}{2}$, $\pi$, $\dfrac{3\pi}{2}$, $2\pi$}
\tkzTabLine
{z, , - , , z, , + , ,z}
\tkzTabVar
{ +/$1$, R/ , -/$-1$, R/, +/$1$}
\tkzTabIma{1}{3}{2}{0}
\tkzTabIma{3}{5}{4}{0}
\end{tikzpicture}
tkzTabVal
In a previous section, a table of signs and variations has been built for the function \(f(x) = tan(x)\).
Usually, remarkable values are displayed on variations lines. In the above example, we want to display the value of \(tan(x)\) for \(\dfrac{\pi}{4}\) and \(\dfrac{3\pi}{4}\).
Without redefining \tkzTabInit
, \tkzTabLine
, \tkzTabVar
in order to add \(\dfrac{\pi}{4}\) and \(\dfrac{3\pi}{4}\), values headers and
associated values on variation lines can be added using \tkzTabVal
. Like \tkzTabIma
, \tkzTabVal
is called after
\tkzTabVar
.
\tkzTabVal {start arrow position}{end arrow position}{relative position between start and end [0-1]}{header value}{value to set on line}
\begin{tikzpicture}
\tkzTabInit[lgt=2.60]
{ $x$/1 , $f'(x)$/1 , $f(x) = tan(x)$/2.5 }
{ $0$, $\dfrac{\pi}{2}$, $\pi$}
\tkzTabLine
{ , + , d , + , }
\tkzTabVar
{ -/$0$ , +D-/$+\infty$/$-\infty$ , +/$0$}
\tkzTabVal {1}{2}{0.5}{$\dfrac{\pi}{4}$}{$1$}
\tkzTabVal {2}{3}{0.5}{$\dfrac{3\pi}{4}$}{$1$}
\end{tikzpicture}
The example in this paper which builds the table for the cosinus function in the domain \([0,2\pi]\)
is then more easily coded using \tkzTabVal
: \(\dfrac{\pi}{2}\) and \(\dfrac{3\pi}{2}\) are indeed no more explicitely defined in \tkzTabInit
, \tkzTabLine
and \tkzTabVal
macros.
\begin{tikzpicture}
\tkzTabInit[lgt=3,espcl=2.5]
{$x$ / 1 , $f'(x)=-\sin(x)$ / 1, $f(x)=cos(x)$ / 2 }
{$0$, $\pi$, $2\pi$}
\tkzTabLine
{z, - , z , + , z}
\tkzTabVar
{ +/$1$ , -/$-1$ , +/$1$}
\tkzTabVal {1}{2}{0.5}{$\dfrac{\pi}{2}$}{$0$}
\tkzTabVal {2}{3}{0.5}{$\dfrac{3\pi}{2}$}{$0$}
\end{tikzpicture}
In the 2 previous examples, positioning is easy, intermediate values to add are exactly in the middle of the arrow {0.5}
.
In the below example, an intermediate value is added on the arrow starting position #1 and ending position #3. The position is qualitatively set to 0.4 to respect the scale.
\begin{tikzpicture}
\tkzTabInit[espcl=6]
{$x$/1 , $f'(x)$/1 , $f(x)$/2}
{$0$ , $\sqrt{e}$ , $+\infty$}
\tkzTabLine{d,+,0,+,}
\tkzTabVar{D- / $-\infty$ , R/ , + / $0$ }
\tkzTabVal[draw]{1}{3}{0.4}{$1$}{$-e$}
\end{tikzpicture}
Notice the draw
option added to the tkTabVal
macro for ease of reading : a vertical dotted line is displayed between
the header value and the intermediate value in the variation line.
Derivatives values, tkzTabSlope
To add derivatives values in the signs line, use tkzTabSlope
after tkzTabLine
command.
\tkTabSlope { position/left value/right value, position/left value/right value, … }
\begin{tikzpicture}
\tkzTabInit[lgt=2.70]
{ $x$/1 , $f'(x)=\dfrac{1}{\cos^2x}$/2 , $f(x) = tan(x)$/2.5 }
{ $0$, $\dfrac{\pi}{2}$, $\pi$}
\tkzTabLine
{ , + , d , + , }
\tkzTabSlope { 1//$1$, 2/+\infty/+\infty, 3/1/ }
\tkzTabVar
{ -/$0$ , +D-/$+\infty$/$-\infty$ , +/$0$}
\tkzTabVal {1}{2}{0.5}{$\dfrac{\pi}{4}$}{$1$}
\tkzTabVal {2}{3}{0.5}{$\dfrac{3\pi}{4}$}{$1$}
\end{tikzpicture}
Horizontal Tangents, tkzTabTan
Use tkzTabTan
to draw horizontal tangents which show more accurately in the variations extrema, convexity, concavity, inflexion points… :
\tkTabTan { start arrow position, end arrow position , header value position, value to set on tangent }
\begin{tikzpicture}
\tkzTabInit[lgt=3]
{$x$ / 1 , $f'(x)=2x$ / 1, $f(x)=x^2$ / 2 }
{$-\infty$, $0$, $+\infty$}
\tkzTabLine
{ , - , z , + , }
\tkzTabSlope
{ 1//-\infty , 3/+\infty/ }
\tkzTabVar
{ +/$+\infty$, -/ , +/$+\infty$ }
\tkzTabTan
{1}{2}{2}{$0$}
\end{tikzpicture}
About styles
Default style is usually enough, but it is possible to apply custom styles (colors, background colors,…) on many tables elements using tikzset
:
- Arrows
- Nodes
- Double bars
- Vertical bars
- …
Style options are numerous and it is not the goal of this paper.
In the below example, a custom style is applied for forbidden zones, the default one is somehow "awful".
\begin{tikzpicture}
\tikzset{h style/.style = {pattern = north west lines,
pattern color = red!30}}
\tkzTabInit[lgt=3]
{$x$ / 1 , $f'(x)$ / 1, $f(x)=\sqrt{\dfrac{x-1}{x+1}}$ / 2 }
{$-\infty$, $-1$, $1$, $+\infty$}
\tkzTabLine
{ , + , d , h , d, +, }
\tkzTabVar
{ -/1 , +DH/$+\infty$, -C/0, +/1}
\end{tikzpicture}