3

I want to make a scheme similar to this in LaTeX:

Triangular scheme

I can't really find how I can make something similar. I have heard of tikz, but have never used it. I suppose that it would be helpful. Basically I need to align the text, and draw arrows between them. However, I have no idea where to start (can I do this with align and then use tikz to draw over it or do I need to do the alignment in tikz?).

I don't expect code that I can copy-paste, but some pointers to some helpful commands would suffice.

  • Welcome! The TikkZ manual begins with nice tutorials which should get you started. You could at least post an example with the content of the diagram i.e. the text. – cfr Dec 22 '16 at 0:21
  • @cfr actually the text is the same as in the example (it is a scheme to show the computation of the B-spline basis functions). I was hoping that I wouldn't need to read the whole introduction to tikz ;) – Ruben Dec 22 '16 at 13:36
  • 1
    The point is that you could provide the content in a form people could copy-paste rather than making people create it by copying from an image. – cfr Dec 22 '16 at 14:26
  • Ah, point taken. To be honest I didn't really expect such a ready-to-use answer, more something along the lines of: "you can do this with the <...> command in the <...> package". – Ruben Dec 23 '16 at 14:12
  • 1
    Though not exactly the same, it is very similar to this tex.stackexchange.com/questions/247177/… – Maarten Dhondt Dec 28 '16 at 20:15
7

You can obtain this either with pstricks or with tikz-cd:

\documentclass[11pt]{article}

\usepackage{mathtools}
\usepackage{tikz-cd} 
\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\begin{document}
\psset{linewidth=0.6pt, arrowinset=0.12, linecolor=blue, arrows=->, nodesep=2pt}
\[
  \begin{psmatrix}[rowsep=5ex,  colsep=1cm,  mnode=R]
    %%% Nodes
 & & & N_{i, 1}\mathrlap{\equiv 1}\\
  &  &  N_{i-1, 2} &  N_{i, 2}\\
  & N_{i-2, 3} &  N_{i-1, 3} &  N_{i, 3}\\
  N_{i-3, 4}& N_{i-2, 4} &  N_{i-1,4} &  N_{i,4}
%%% Horizontal arrows
    \ncline{1,4}{2,3} \ncline{1,4}{2,4}
    \ncline{2,3}{3,2} \ncline{2,3}{3,3} \ncline{2,4}{3,3}\ncline{2,4}{3,4}
    \ncline{3,2}{4,1} \ncline{3,2}{4,2}\ncline{3,3}{4,2} \ncline{3,3}{4,3}\ncline{3,4}{4,3}\ncline{3,4}{4,4}
  \end{psmatrix} \]


  \vskip 1cm

  \[ \tikzcdset{arrows={-Stealth, blue}}
    \begin{tikzcd}
     & & & N_{i, 1}\mathrlap{\equiv 1}\dlar\dar\\
      &  &  N_{i-1, 2}\dlar\dar &  N_{i, 2}\dlar\dar\\
      & N_{i-2, 3}\dlar\dar &  N_{i-1, 3}\dlar\dar &  N_{i, 3}\dlar\dar\\
      N_{i-3, 4}& N_{i-2, 4} &  N_{i-1,4} &  N_{i,4}
    \end{tikzcd}\]

\end{document} 

enter image description here

  • \mathrlap{{}\equiv1}, in order to get the spacing right – egreg Dec 22 '16 at 7:22
  • Dear @Ruben, if this is the answer you think is the most appropriate, then you should also mark it as an "Accepted answer". – Budo Zindovic Dec 22 '16 at 14:07
  • I wanted to try the answer first (the tikz version works fine, I can't get pstricks to show anything). – Ruben Dec 22 '16 at 14:10
  • @Ruben:To make the pstricks code work with pdflatex, you have to add the parameter --enable-write18 if you're under MiKTeX, or -shell-escape for TeX Live or MacTeX. Alternatively, you can remove auto-pst-pdf and compile with xelatex. – Bernard Dec 22 '16 at 18:22
  • @Bernard I got an error message about enable-write-18. I then followed the accepted answer on tex.stackexchange.com/questions/37489/…. After that, I can compile without errors, but no diagram shows up. – Ruben Dec 22 '16 at 20:05
5

You can also use TikZ graphdrawing to have it all connected and placed automatically. This needs LuaLaTeX.

N.B.: One has to name the node containing the \equiv (here with a). Otherwise one is greeted with a rather cryptic

! Missing \endcsname inserted.
<to be read again> 
\equiv

I chose the tree layout for the graph but other layouts are easily possible.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
  \graph [tree layout, math nodes, edge={blue,-stealth}]
  {
    a / N_{i, 1} \equiv 1 -> {
      N_{i-1, 2} -> {
        N_{i-2, 3} -> { N_{i-3, 4}, N_{i-2, 4} },
        N_{i-1, 3} -> { N_{i-2, 4}, N_{i-1,4} }
      },
      N_{i, 2} -> {
        N_{i-1, 3},
        N_{i, 3} -> { N_{i-1,4}, N_{i,4} }
      }
    }
  };
\end{tikzpicture}
\end{document}

enter image description here

  • Could note that this requires lualatex. (You do get a fairly clear error message if you try with pdflatex, but worth mentioning.) – Torbjørn T. Dec 22 '16 at 12:40
  • @TorbjørnT. Noted. – Henri Menke Dec 22 '16 at 12:44
4

I don't recommend this particularly because it is not a tree, but it can be drawn with Forest more-or-less automatically, if desired.

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{forest}
\usepackage{amsmath}
\usetikzlibrary{arrows.meta}
\begin{document}
\forestset{
  declare count register=thing,
  thing'=0,
}
\begin{forest}
  for tree={
    edge={-Stealth, draw=blue!50!cyan},
    math content,
    tier/.option=level,
  },
  label={right:$=1$},
  where n'=1{
    calign with current edge,
  }{},
  before typesetting nodes={
    for nodewalk={
      r,
      while nodewalk valid={l}{l}
    }{
      content/.process={Ow+nw}{level}{#1+1}{\text{N}_{i,#1}}
    },
    for nodewalk={
      fake=r,
      while nodewalk valid={1}{
        thing'+=1,
        1,
        for tree={
          content/.process={Ow+nRw2}{level}{#1+1}{thing}{\text{N}_{i-#2,#1}}
        },
        for nodewalk={
          while nodewalk valid={l}{
            tikz+/.process={Ow}{edge}{\path [#1] (!next on tier.parent anchor) -- (!l.child anchor);},
            l
          }
        }{}
      }
    }{},
  },
  [
    [
      [
        [
          []
          []
        ]
        [
          []
        ]
      ]
      [
        [
          []
        ]
      ]
    ]
    [
      [
        [
          []
        ]
      ]
    ]
  ]
\end{forest}
\end{document}

Forest solution

Note: code edited to reflect the bugfix for Forest 2.1. The version above works with version 2.1.2. If you have an earlier version of Forest, you will need to update in order to use the above code.

  • 1
    has discovered a Forest bug while working on this solution. while nodewalk valid (and other loops) introduce unnecessary hash doubling. The bug is already fixed: the bugfix release (v2.1.2) will be available on CTAN in the beginning of the next week. – Sašo Živanović Dec 23 '16 at 3:16
  • 1
    @SašoŽivanović Updated. – cfr Jan 9 '17 at 0:07
4

Yet another solution, this time using the Xy-pic package. The advantage of this package is the matrix-like structure of the environment and the few lines to code it.

\documentclass{article}
\usepackage[all]{xy}
\usepackage{color}

\begin{document}

\xymatrix{
% the \ar command stands for "arrow"; the @ is the syntax to put options to the arrows in brackets (in this case, color blue), and the last bracket is the direction: d stands for "down", l for "left", dl for "down left"
    & & & N_{i,1} \equiv 1 \ar@[blue][dl] \ar@[blue][d]\\
    & & N_{i-1,2} \ar@[blue][dl] \ar@[blue][d] & N_{i,2} \ar@[blue][dl] \ar@[blue][d]\\
    & N_{i-2,3} \ar@[blue][dl] \ar@[blue][d] & N_{i-1,3} \ar@[blue][dl] \ar@[blue][d] & N_{i,3} \ar@[blue][dl] \ar@[blue][d]\\
    N_{i-3,4} & N_{i-2,4} & N_{i-1,4} & N_{i,4}
}

\end{document}

triangular scheme

3

Here I use a \Shortstack. EDIT: colored arrows added.

\documentclass{article}
\usepackage{stackengine,graphicx,xcolor}
\stackMath
\newcommand\undarrow{{\color{blue}%
  \kern15pt
  \raisebox{-.5ex}{\rotatebox[origin=bottom]{-45}{\scalebox{1}[1.414]{$\downarrow$}}}
  \kern2pt\downarrow\,}}
\renewcommand\stackalignment{r}
\setstackgap{S}{4pt}
\newcommand\schemeunit[3][-]{\stackunder{N\rlap{$_{i#1#2,#3}$}}{\undarrow}}
\newcommand\schemeUnit[3][-]{%
  \stackunder[0pt]{N\rlap{$_{i#1#2,#3}$}}{\smash{\phantom{\undarrow}}}}
\begin{document}
\Shortstack{%
  \schemeunit[]{}{1}
  \schemeunit{1}{2}\schemeunit[]{}{2}
  \schemeunit{2}{3}\schemeunit{1}{3}\schemeunit[]{}{3}
  \schemeUnit{3}{4}\schemeUnit{2}{4}\schemeUnit{1}{4}\schemeUnit[]{}{4}}
\end{document}

enter image description here

1

Here's a version in Metapost, wrapped up in luamplib. Compile with lualatex.

enter image description here

\RequirePackage{luatex85}
\documentclass[border=10mm]{standalone}
\usepackage{mathtools}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    u = -14mm;
    R = 5;
    path e; e = superellipse(13right,8up,13left,8down,0.78);
    for i=1 upto R:
        for j=1 upto i:
            if (i=1) and (j=1):
                label("$N_{i,1}\mathrlap{{}\equiv1}$", (u,u));
            else:
                label("$N_{i" if j>1: & "-" & decimal (j-1) fi & "," & decimal i & "}$", (j*u, i*u));
            fi
            if i<R:
                drawoptions(withcolor .4[blue,white]);
                drawarrow (j*u,i*u) -- (j*u,   i*u+u) cutbefore e shifted (j*u,i*u) cutafter e shifted (j*u,   i*u+u);
                drawarrow (j*u,i*u) -- (j*u+u, i*u+u) cutbefore e shifted (j*u,i*u) cutafter e shifted (j*u+u, i*u+u);
                drawoptions();
            fi
        endfor
    endfor
endfig;
\end{mplibcode}
\end{document}

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.