12

How can I draw this picture in LaTeX, with those skew lines? Any hints?

enter image description here

  • 9
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – user31729 May 4 '15 at 11:02
  • @ChristianHupfer, You're absolutely right, actually it's not hard for me to create the triangle, the main problem I had was the skew line. Now thanks to you guys I learned it. I'll be appreciate if someone introduce some good sources to learn these kind of stuffs. – Woria May 4 '15 at 19:51
  • I accept the (Maarten Dhondt)'s answer because of it's short and clever use of (tikz), but I learned other things from other answers too. I'm new at these things so there is a lot to learn. – Woria May 4 '15 at 20:03
21

EDIT: changed \ifthenelse to \ifnum as suggested by percusse and Heiko.

\documentclass[tikz,border=2mm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \foreach \n in {0,...,6} {
            \foreach \k in {0,...,\n} {
                \node (\n\k) at (\k,-\n) {${\n \choose \k}$};
                \pgfmathtruncatemacro{\x}{(\n+1)/2}
                \pgfmathtruncatemacro{\y}{\n/2}
                \ifnum\k=0 \draw (\n\k.south west) -- (\x\y.north east);\fi
            }
        }
    \end{tikzpicture}
\end{document}

EDIT 2: Eliminated if statement as suggested by Misch:

\documentclass[tikz,border=2mm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \foreach \n in {0,...,6} {
            \foreach \k in {0,...,\n} {
                \node (\n\k) at (\k,-\n) {${\n \choose \k}$};
            }
            \pgfmathtruncatemacro{\x}{(\n+1)/2}
            \pgfmathtruncatemacro{\y}{\n/2}
            \draw (\n0.south west) -- (\x\y.north east);
        }
    \end{tikzpicture}
\end{document}

enter image description here

  • 1
    Wow, this is better than my solution, of course;-) I should really learn tikz (+1) – user31729 May 4 '15 at 12:11
  • +1 You beat me to it! :P I was this close earlier but then I had to get lunch. :P – Alenanno May 4 '15 at 12:17
  • 1
    You can remove the package with \ifnum\k=0\draw (\n\k.south west) -- (\x\y.north east);\fi – percusse May 4 '15 at 12:42
  • 2
    I would add a space after the zero: \ifnum\k=0 \draw. Otherwise TeX unnecessarily expands \draw in the search for digits. – Heiko Oberdiek May 4 '15 at 13:01
  • 2
    You don't even need the if construct. You can just move the last three lines of the inner loop out of the inner loop, and replace \n\k with \n0 – Misch May 5 '15 at 11:28
6

This isn't precisely what the OP requests, I think, but it's similar...

\documentclass{book}
\usepackage{mathtools}
\usepackage{cancel}


\begin{document}
\LARGE \boldmath
% horizontal loop
\foreach \x in {0,...,6} {%
% vertical loop

\foreach \y in {0,...,\x} {%
$\cancel{\binom{\x}{\y}}$
}

}

\end{document}

enter image description here

  • 1
    +1, but I'm curious about why you're using \boldmath. – Henri Menke May 4 '15 at 13:11
  • @HenriMenke: To exaggerate only ;-) – user31729 May 4 '15 at 13:12
6
\documentclass{article}
\usepackage{cancel,mathtools,stackengine}
\stackMath
\def\CBN#1#2{%
  \cancel{\addstackgap[6pt]{\kern6pt\displaystyle\binom{#1}{#2}\kern6pt}}%
  }
\def\BN#1#2{%
  \addstackgap[6pt]{\kern6pt\displaystyle\binom{#1}{#2}\kern6pt}%
  }
\begin{document}
\[
\def\stackalignment{l}
\setstackgap{S}{-5.2pt}
\setstackEOL{\cr}
\Shortstack{
\CBN{0}{0}\cr
\CBN{1}{0}\CBN{1}{1}\cr
\CBN{2}{0}\CBN{2}{1}\CBN{2}{2}\cr
\CBN{3}{0}\CBN{3}{1}\CBN{3}{2}\CBN{3}{3}\cr
\CBN{4}{0}\CBN{4}{1}\CBN{4}{2}\BN{4}{3}\BN{4}{4}\cr
\CBN{5}{0}\CBN{5}{1}\BN{5}{2}\BN{5}{3}\BN{5}{4}\BN{5}{5}\cr
\CBN{6}{0}\BN{6}{1}\BN{6}{2}\BN{6}{3}\BN{6}{4}\BN{6}{5}\BN{6}{6}
}
\]
\end{document}

enter image description here

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.