如何用tkz-tab绘制这个变量表?

如何用tkz-tab绘制这个变量表?

我想用 tkz-tab 包绘制这个变量表。该怎么办? https://i.imgur.com/WvxGZvO.png

我只能画成这样了。 在此处输入图片描述 我使用谷歌翻译。谢谢。

这是我的代码

\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}

答案1

首先,我们使用“help”选项来找出节点的名称。

\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}

在此处输入图片描述

然后我们玩 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}

在此处输入图片描述

答案2

为了获得更大的灵活性,您可以直接使用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}

在此处输入图片描述

相关内容