3

I've google a bit about this topic but I've found no result.

I'm trying to write some notes for my University course. The topic is "numerical interpolation methods". More precisely I have to build a table of "finite differences" (here a description, about at mid page you can see a table of values which are "triangular", that's what I have to do) which is pretty easy to do with the \multirow{n}*{text} command.

What I need though is to add a line that "links", say, the first cell in the first column with the second cell in the second column. How would I do that?

Here's an example, you can see lines going from one cell to another.

An example

4
  • 2
    Which package provides the command \multiline? Can you provide a minimal example? Commented Oct 23, 2011 at 11:27
  • 1
    With "links", do you mean you want to draw a line from one cell to another cell? Could you maybe make an example using a drawing program, so people get an idea what exactly your desired result looks like?
    – Jake
    Commented Oct 23, 2011 at 11:28
  • 1
    Sorry, I made a mistake, it was \multirow, provided by the package multirow. I'll make a drawing to explain better. I cannot provide a MWE because I don't know how to do it, that's what I'm asking help for. :P
    – mmassaro
    Commented Oct 23, 2011 at 11:50
  • Try \searrow and \nearrow.
    – yannisl
    Commented Oct 23, 2011 at 14:56

4 Answers 4

3

Here is an example using pst-node (from the pstricks bundle) and array (for the m{<len>} column type). Nodes are marked via \pnode(<x>,<y>){<name>} and lines are drawn using \psline(<node1>)(<node2>).

enter image description here

\documentclass{article}
\usepackage{pst-node}% http://ctan.org/pkg/pstricks
\usepackage{array}% http://ctan.org/pkg/array
\begin{document}
\newcolumntype{L}{@{}l@{}}%
\[
  \begin{array}{*{5}{m{4em}}}
    $x$ & 
    $f$ & 
    I~diff. & 
    II~diff. & 
    III~diff. \\[\jot]
    $\begin{array}{L}
      x_0 \\ x_1 \\ x_3
    \end{array}$ &
    $\begin{array}{L}
      f(x_0)\pnode(0.5ex,0.6ex){fx0} \\ f(x_2) \\ f(x_3)\pnode(0.5ex,0.6ex){fx3}
    \end{array}$ &
    $\begin{array}{L}
      \pnode(-0.5ex,0.6ex){fx1L}f(x_1)\pnode(0.5ex,0.6ex){fx1R} \\ \pnode(-0.5ex,0.6ex){fx2L}f(x_2)\pnode(0.5ex,0.6ex){fx2R}
    \end{array}$ &
    $\begin{array}{L}
      \pnode(-0.5ex,0.6ex){fx0L}f(x_0)\pnode(0.5ex,0.6ex){fx0R} \\ \pnode(-0.5ex,0.6ex){fx12L}f(x_1)\pnode(0.5ex,0.6ex){fx12R}
    \end{array}$ &
    \pnode(-0.5ex,0.6ex){ans}$0.0333$
  \end{array}
\]
\psline(fx0)(fx1L)
\psline(fx3)(fx2L)
\psline(fx1R)(fx0L)
\psline(fx2R)(fx12L)
\psline(fx0R)(ans)
\psline(fx12R)(ans)
\end{document}

Alterations to line style and arrows are also possible. Compilation via latex -> dvips -> ps2pdf or directly using xelatex is required.

0
6

a solution with \rnode:

\documentclass{article}
\usepackage{pst-node,amsmath}
\begin{document}
\[
  \begin{psmatrix}[rowsep=-2pt,colsep=1cm]
x   & f & \text{I~diff.} & \text{II~diff.} & \text{III~diff.} \\[3mm]
x_0 & f(x_0)                             \\
    &        & f(x_1) & f(x_0)           \\
x_1 & f(x_2) &        &        & 0.0333  \\
    &        & f(x_2) & f(x_1)           \\
x_3 & f(x_3)                             \\
\end{psmatrix}
\]
\psset{arrows=->,nodesep=2pt,linecolor=red}
\ncline{2,2}{3,3} \ncline{6,2}{5,3} \ncline{3,3}{3,4}
\ncline{5,3}{5,4} \ncline{3,4}{4,5}\ncline{5,4}{4,5}
\end{document}

enter image description here

5

no tikz solution yet? Lucky me (in plain-tex format):

\input tikz
\usetikzlibrary{matrix,chains,scopes,arrows}
\tikzpicture[every on chain/.style={join={by <<-o,blue!60}}]
  \matrix[matrix of math nodes,column sep=2em,row sep=-2ex] (mx) {
    % "mx" is now the name of our matrix, to which we can refer to later
    x   & f      & \hbox{I diff.} & \hbox{II diff.} & \hbox{III diff.} \\[2ex]
    x_0 & f(x_0) \\
        &        & f(x_1)         & f(x_0) \\
    x_1 & f(x_2) &                &                 & 0.0333 \\
        &        & f(x_2)         & f(x_1) \\
    x_2 & f(x_3) \\
  };
  {[start chain]
    \chainin (mx-4-5);
    {[start branch] \chainin (mx-3-4); \chainin (mx-3-3); \chainin (mx-2-2); }
    {[start branch] \chainin (mx-5-4); \chainin (mx-5-3); \chainin (mx-6-2); }
  }
\endtikzpicture
\bye

Looks like:
enter image description here

2
  • I needed the same code but after modifying it I could not join x_{i} and f(x_{i}) by horizontal red arrows. Is that possible too?
    – bkarpuz
    Commented Mar 10, 2013 at 13:18
  • 1
    @bkarpuz: Sure is possible; for example between x_0 and f(x_0) would be: \draw[red,->] (mx-2-1) -- (mx-2-2);; that reads: mx is the name of the matrix, 2 is the row number, and the last number is the column number.
    – morbusg
    Commented Mar 22, 2013 at 12:00
3

Since a MWE was not provided, the following answer is aimed at getting the desired output. I used PSTricks to do positioning and to get line segments.

\documentclass[12pt]{report}
\usepackage{graphicx}
\usepackage{pstricks}

\begin{document}

\begin{pspicture*}(0,0)(15,-5)
\rput[tl](0,0){$x$}
\rput[tl](3,0){$f$}
\rput[tl](6,0){I diff}
\rput[tl](9,0){II diff}
\rput[tl](12,0){III diff}

\rput[tl](0,-1.1){$x_0$}
\rput[tl](3,-1){$f(x_0)$}

\rput[tl](0,-2.1){$x_1$}
\rput[tl](3,-2){$f(x_2)$}

\rput[tl](0,-3.1){$x_3$}
\rput[tl](3,-3){$f(x_3)$}

\rput[tl](6,-1.5){$f(x_1)-f(x_0)$}
\rput[tl](6,-2.5){$f(x_2)-f(x_1)$}

\rput[tl](9,-2){$0.0333$}

\psline[linecolor=blue](4,-1.3)(6,-1.7)
\psline[linecolor=blue](4,-3.3)(6,-2.7)

\psline[linecolor=blue](8.5,-1.8)(8.9,-2.2)
\psline[linecolor=blue](8.5,-2.8)(8.9,-2.2)
\end{pspicture*}

\end{document}

enter image description here

You must log in to answer this question.

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