6

I want to recreate the following table on latex

enter image description here

Here is my MWE

\documentclass{article} 
\usepackage{colortbl}

\begin{document}
\begin{table}[h]
 \begin{tabular}{|>{\columncolor[gray]{.8}}c|m{1cm}|m{1cm}|m{1cm}|m{1cm}|m{1cm}|m{1cm}|m{1cm}|}
   \hline
  \footnotesize{ $x$ } & 0.900 & 0.990 & 0.999 & 1.000 & 1.001 & 1.010 & 1.100 \\ \hline
  \footnotesize{ $f(x)$} & 1.810 & 1.980 & 1.998 & 2.000 & 2.002 & 2.020 & 2.210 \\ \hline
 \end{tabular}
 \end{table}
\end{document} 
10

You can draw with TikZ.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
% put a row of 8 elements
\newcommand{\putrow}[9]{
\path (0,#1) node{#2}
++(0:1) node{#3} ++(0:1) node{#4}
++(0:1) node{#5} ++(0:1) node{#6} 
++(0:1) node{#7} ++(0:1) node{#8} ++(0:1) node{#9};
}

\begin{document}
\begin{tikzpicture}[xscale=1.4,yscale=.6]
\begin{scope}[shift={(-.5,.5)}]
\fill[cyan!30] (0,0) rectangle +(1,-2);
\draw (0,0) grid (8,-2);
\end{scope}
\begin{scope}[-stealth,magenta,shorten >=.5pt,
every node/.style={midway,scale=.8}]
\draw[shift={(90:1)}] (1,0)--(4,0)    node[above]{$x$ approaches $1$};
\draw[shift={(90:1)}] (7,0)--(4,0)    node[above]{$x$ approaches $1$};
\draw[shift={(-90:2)}] (1,0)--(4,0)   node[below]{$f(x)$ approaches $2$};
\draw[shift={(-90:2)}] (7,0)--(4,0)   node[below]{$f(x)$ approaches $2$};
\end{scope}

\putrow{0}{$x$}{0.900}{0.990}{0.999}{1.000}{1.001}{1.010}{1.100}
\putrow{-1}{$f(x)$}{1.810}{1.980}{1.998}{2.000}{2.002}{2.020}{2.210}
\end{tikzpicture}
\end{document}
7

Also with tikz, but now with use of the matrix library. For arrows, edge labels are employed arrows.meta and quoted libraries:

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{arrows.meta,
                matrix,
                quotes
                }

\begin{document}
    \begin{tikzpicture}[
every edge/.style = {draw, purple, -{Straight Barb[angle=60:2pt 3]}, semithick}, shorten >=1pt,
every edge quoetes/.style = {font=\footnotesize}
                        ]
\matrix (m) [matrix of math nodes,
             nodes = {draw, minimum height=4ex, minimum width=3.3em, 
                      inner sep=0pt, outer sep=0pt, anchor=center},
             column sep=-\pgflinewidth,
             row sep=-\pgflinewidth,
             column 1/.append style = {nodes={fill=cyan!30}}
            ]
{
 x   & 0.900 & 0.990 & 0.999 & 1.000 & 1.001 & 1.010 & 1.100    \\ 
f(x) & 1.810 & 1.980 & 1.998 & 2.000 & 2.002 & 2.020 & 2.210    \\
};
\draw   (m-1-2.north |- m.north) edge["$x$ approaches $1$"] (m-1-5.north |- m.north)
        (m-1-8.north |- m.north) edge["$f(x)$ approaches $1$" '] (m-1-5.north |- m.north)
        (m-1-2.south |- m.south) edge["$x$ approaches $2$" '] (m-1-5.north |- m.south)
        (m-1-8.south |- m.south) edge["$f(x)$ approaches $2$"] (m-1-5.north |- m.south);
    \end{tikzpicture}
\end{document}

enter image description here

1

I wrote two macros that automatically place the arrow above the path and the text above the arrow or below depending on whether the path goes from left to right or not: \valeur and \fromto.

How does it work?

This is done without any positioning tests, but using the properties of the rotations This avoids using 4 options that are de facto useless:

  • 2 for the placement of the arrows (up or down)
  • as well as 2 options for the placement of the text relative to these arrows (above and below).

Rotations

In geometry, a positive angle is an anti-clockwise rotation. A negative angle is a clockwise rotation.

angles

From LEFT to RIGHT

When the path goes from left to right (i.e. from point A to point B), the points located 5mm from each other are rotated as shown in this figure. This builds a new path 5 mm higher.

higher path

From RIGHT to LEFT

When the path goes from right to left (i.e. from point B to point A), the same is done as shown in this figure. This builds a new path 5 mm lower. lower path

In each case, the first rotation is positive and the second negative. These rotations are performed with the calc library. To place the text, I use the auto=left option which allows me to always place the text on the same side of a path.

The two macros:

  1. The first called valeur place is a TikZ node centered on the number from which you want to start or arrive the arrow;

    \newcommand{\valeur}[2]{
        \tikz[remember picture] \node[inner sep=0pt,anchor=center](#1){#2};}

    It has two arguments:

    • the first #1 is the name we give to the node
    • the second #2 is the value of this node.
  2. the second one called \fromto draw an arrow above or below the path:

    • if the arrow is placed above the path, the text is also placed above the arrow;
    • otherwise, if the arrow is placed below the path, the text is placed below the arrow.

The principle is the following: if the path goes from left to right, the arrow and the text are placed above the path, otherwise it is placed below.

This macro has 4 arguments:

  • the first one #1 is optional and allows to transmit options to the path < options>
  • the second #2 is the starting point < from>
  • the third #3 is the arrival point < to>
  • the fourth #4 is the text to be positioned < text>

    \newcommand{\fromto}4{
    \tikz[remember picture,overlay,auto=left,>={Stealth[length=5pt, inset=1pt,sep]}]
        \path[draw=myviolet,thick,#1]
        ($(#2.center)!5mm!90:(#3.center)$)--($(#3.center)!5mm!-90:(#2.center)$)node[midway,myviolet,font=\bf]{#4};}

For example:

example

\documentclass{article} 
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta}

\newcommand{\valeur}[2]{
    \tikz[remember picture] \node[inner sep=0pt,anchor=center](#1){#2};}
\newcommand{\fromto}[4][]{
\tikz[remember picture,overlay,auto=left,>={Stealth[length=5pt, inset=1pt,sep]}]
    \path[draw,thick,#1]($(#2.center)!5mm!90:(#3.center)$)--($(#3.center)!5mm!-90:(#2.center)$)node[midway]{#4};}

\begin{document}

 \begin{tikzpicture}[remember picture]
 \node[] (A)at(0,0){A};
 \node[] (B) at (8,0){B};
 \draw[densely dotted](A)--(B)node[midway,fill=white]{path from A to B};
 \end{tikzpicture}

\fromto[align=center,dashed,->,blue] {A}{B}{from A to B:\\ the arrow is \textbf{above} the path A--B \\ the text is \textbf{above} the arrow}
\fromto[align=center,dashed,->,red] {B}{A}{from B to A:\\ line arrow is \textbf{below} the path A--B,\\ the text is \textbf{below} the arrow}

\end{document}

Code and result (to be compile twice):

screenshot

\documentclass{article} 
\usepackage{colortbl}
\usepackage{tikz}
\definecolor{myviolet}{RGB}{243,29,143}
\usetikzlibrary{calc,arrows.meta}

\newcommand{\valeur}[2]{
    \tikz[remember picture] \node[inner sep=0pt,anchor=center](#1){#2};}
\newcommand{\fromto}[4][]{
\tikz[remember picture,overlay,auto=left,>={Stealth[length=5pt, inset=1pt,sep]}]
    \path[draw=myviolet,thick,#1]
    ($(#2.center)!5mm!90:(#3.center)$)--($(#3.center)!5mm!-90:(#2.center)$)node[midway,myviolet,font=\bf]{#4};}

\begin{document}
\begin{table}[h]
 \begin{tabular}{|>{\columncolor[gray]{.8}}c|m{1cm}|m{1cm}|m{1cm}|m{1cm}|m{1cm}|m{1cm}|m{1cm}|}
   \hline
  \footnotesize{ $x$ } & \valeur{a1}{0.900} & 0.990 & 0.999 & \valeur{b1}{1.000} & 1.001 & 1.010 & \valeur{c1}{1.100} \\ \hline
  \footnotesize{ $f(x)$} & \valeur{a2}{1.810} & 1.980 & 1.998 & \valeur{b2}{2.000} & 2.002 & 2.020 & \valeur{c2}{2.210} \\ \hline
 \end{tabular}
 \end{table}

\fromto[->] {a1}{b1}{$x$ approaches 1.}
\fromto[<-] {b1}{c1}{$x$ approaches 1.}
\fromto[<-] {b2}{a2}{$f(x)$ approaches 2.}
\fromto[->] {c2}{b2}{$f(x)$ approaches 2.}

\end{document}

Translated with www.DeepL.com/Translator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.