3

I want draw this variable table by tkz-tab package. How to do? https://i.imgur.com/WvxGZvO.png

I can only draw like this. enter image description here I use Google Translate. Thanks.

Here is my code

\documentclass[border=1mm]{standalone}
\usepackage{tikz,tkz-tab}
\begin{document}
\begin{tikzpicture}
\tkzTabInit[espcl=4]
{$x$/1,$f'(x)$/1,$f(x)$/3}
{$-\infty$,$-2$,$0$,$+\infty$}
\tkzTabLine{d,h,d,+,d,-,}
\tkzTabVar{+DH/,-C/$-\infty$,+D+/$+\infty$/1,-/$0$}
\end{tikzpicture}
\end{document}
4
  • Can you show the code of what you have done? Commented Oct 5, 2017 at 14:26
  • @TorbjørnT. I just edit post with my code.
    – StackUser
    Commented Oct 5, 2017 at 14:31
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – dexteritas
    Commented Oct 5, 2017 at 15:42
  • @dexteritas OK. I understand. I have edited post. Can you help me solve this problem?
    – StackUser
    Commented Oct 5, 2017 at 15:58

2 Answers 2

4

First we use the `help' option to find out the names of the nodes.

\documentclass[border=1mm]{standalone}
\usepackage{tkz-tab}
\begin{document}
\begin{tikzpicture}
\tkzTabInit[espcl=4]
{$x$/1,$f'(x)$/1,$f(x)$/3}
{$-\infty$,$-2$,$0$,$+\infty$}
\tkzTabLine{,,d,+,d,-,
\end{tikzpicture}
\end{document}

enter image description here

and then we play with TikZ

\documentclass[border=1mm]{standalone}
\usepackage{tkz-tab}
\begin{document}
\begin{tikzpicture}
\tkzTabInit[espcl=4]
{$x$/1,$f'(x)$/1,$f(x)$/3}
{$-\infty$,$-2$,$0$,$+\infty$}
\tkzTabLine{,,d,+,d,-,}
\fill[pattern  = north west lines] (T13) rectangle (N22);
\draw[double style] (N22) to (N23) (N32) to (N33);
\node[above,fill=white] (n1) at (N23) {$-\infty$};
\node[below left](n2) at (N32) {$+\infty$};
\node[below right](n3) at (N32) {$1$};
\node[above left] (n4) at (N43) {$0$};
\draw[arrow style] (n1) to (n2)  (n3) to (n4);
\end{tikzpicture}
\end{document}

enter image description here

2
  • However, +1! :)
    – CarLaTeX
    Commented Apr 8, 2020 at 22:00
  • @Alain Matthes Exactly. I did the same. I posted this a long time ago. And I forgot to post the solution again.
    – StackUser
    Commented Apr 10, 2020 at 12:20
2

To have more flexibility, you could directly use a tikz matrix:

\documentclass[border=1mm]{standalone}
\usepackage{tikz, tkz-tab} 
\usetikzlibrary{matrix, positioning, patterns, arrows.meta}
\tikzset{
    myarrow/.style={
        thin,
        shorten >=2pt,shorten <=2pt,
        -latex'
        }
    }

\begin{document} 
\begin{tikzpicture} 
\matrix[matrix of math nodes,
    nodes in empty cells,
    draw,
    inner sep=0pt,
    row sep=-\pgflinewidth, 
    column sep=-\pgflinewidth,
    row 1/.style={nodes={minimum height=7ex}},
    row 2/.style={nodes={minimum height=7ex}},
    row 3/.style={nodes={minimum height=20ex}},
    column 1/.style={nodes={text width=5.6em,draw}},
    column 2/.style={nodes={text width=12em}},
    column 3/.style={nodes={text width=12em}},
    column 4/.style={nodes={text width=12em}},
    align=center, text centered,
    nodes={text width=2cm, text height=1.5ex, text depth=.25ex}
    ](mymatr) {
x &&&\\
f'(x) &&+&-\\
f(x)&&&\\
};
\draw (mymatr-1-2.south west) -- 
(mymatr-1-4.south east);
\draw (mymatr-2-2.south west) -- 
(mymatr-2-4.south east);
\draw[double] (mymatr-1-3.south west) -- (mymatr-3-3.south west);
\draw[double] (mymatr-1-4.south west) -- (mymatr-3-4.south west);
\draw[pattern=north west lines] ([shift={(\pgflinewidth,-\pgflinewidth)}]mymatr-2-2.north west) rectangle ([shift={(-4\pgflinewidth,\pgflinewidth)}]mymatr-3-2.south east);
\node[right=2pt of mymatr-1-1] {$-\infty$}; 
\node[xshift=-1pt] at (mymatr-1-2.east) {$-2$}; 
\node[xshift=-1pt] at (mymatr-1-3.east) {$0$}; 
\node[left=4pt of mymatr-1-4.east] {$+\infty$}; 
\node[above=2pt of mymatr-3-2.south east, fill=white] (minusinf) {$-\infty$};
\node[below left =2pt and 4pt of mymatr-3-3.north east] (plusinf) {$+\infty$};
\node[below right =2pt of mymatr-3-4.north west] (one) {$1$};
\node[above left=2pt and 6pt of mymatr-3-4.south east] (zero) {$0$};
\draw[myarrow] (minusinf) -- (plusinf);
\draw[myarrow] (one) -- (zero);
\end{tikzpicture} 
\end{document}

enter image description here

7
  • Thank @CarLaTeX. But if i want only use tikz, i can do that.
    – StackUser
    Commented Oct 7, 2017 at 1:02
  • @AfrendlyLee It's better if you edit your question and explain why tkz-tab is mandatory for you.
    – CarLaTeX
    Commented Oct 7, 2017 at 4:18
  • Because if i use tkz-tab, code is shorter and simpler (if work).
    – StackUser
    Commented Oct 9, 2017 at 4:44
  • more flexibility ? are you sure. If you have a few dozen tables to create, I'm not sure it's nice to redo everything, but in general in my packages I let the user choose to complete the code with TikZ. Here once the frame is obtained, there are the nodes necessary to do what you simply want. Commented Apr 8, 2020 at 21:35
  • @AlainMatthes You can use a style. I think it's a matter of habit, I'm used to TikZ and I find it easier. Maybe it's only because tkz-tab documentation is in French (I don't speak it).
    – CarLaTeX
    Commented Apr 8, 2020 at 21:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .