4

I am trying to reproduce these arrays which I found in the pdf of a paper. I do not have the .tex file, so I'm not sure how to construct it.

enter image description here

3 Answers 3

4
\documentclass{article}
\usepackage{stackengine}
\begin{document}    
\Longstack{1 1 1 1 1} \
5 \
\Longstack{4 4} \
7 \
\Longstack{3 3 3} \
8 \
\Longstack{5 5} \
7 \
\stackunder[9pt]{\Longstack{2 2 2 2}}{\Shortstack{. . .}} \
7 \
\Longstack{5 5} \
8 \
\Longstack{3 3 3} \
7 \
\Longstack{4 4} \
5 \
\Longstack{1 1 1 1 1}
\end{document}

enter image description here

2

You can let LaTeX create these tables. It is sufficient to specify the first row to let LaTeX figure out the rest.

\documentclass{article}
\usepackage{pgffor}
\makeatletter
\newtoks\@tabtoks% https://tex.stackexchange.com/a/7594/23830 & https://tex.stackexchange.com/a/165646/238301
\newcommand\addtabtokse[1]{\@tabtoks\expandafter{\the\expandafter\@tabtoks#1}}
\newcommand*\resettabtoks{\@tabtoks{}}
\newcommand*\printtabtoks{\the\@tabtoks}
\pgfkeys{summation table/.code={%
\edef\myi{0}%
\edef\mylist{#1}%
\resettabtoks
\pgfkeys{/summation table keys/step/.list={#1}}%
\let\mym\myi
\pgfmathtruncatemacro{\myn}{ln(\mym-1)/ln(2)+1}%\typeout{\myn x\mym}%
\ensuremath{\begin{array}{*{\mym}c}%
\edef\myi{0}%
\pgfkeys{/summation table keys/row/.list={1,...,\the\numexpr\myn+1}}%
\printtabtoks
\end{array}}%
},/summation table keys/.cd,step/.code={\edef\myi{\the\numexpr\myi+1}},
row entry/.code={%
\edef\myj{\the\numexpr\myj+1}%
\ifnum\myi>\myn
 \pgfmathtruncatemacro{\myk}{(\mym+1)/2}%
 \edef\myentry{}%
 \ifnum\myj=\myk
  \addtabtokse{\vdots &}%
 \else
  \ifnum\myj=\mym\relax
   \addtabtokse{\myentry\\}%
  \else
   \addtabtokse{\myentry &}%
  \fi 
 \fi
\else
 \ifnum\myi=1\relax
  \pgfmathtruncatemacro{\myentry}{{\mylist}[\myj-1]}%
 \else
  \pgfmathtruncatemacro{\myentry}{{\mylist}[\myj-1]}%
  \ifnum\myentry=0\relax
   \pgfmathtruncatemacro{\myk}{\myj-pow(2,\myn-\myi)}%
   \ifnum\myk>0\relax
    \pgfmathtruncatemacro{\myentry}{{\mylist}[\myk-1]}%
   \fi
   \pgfmathtruncatemacro{\myk}{\myj+pow(2,\myn-\myi)}%
   \ifnum\myk<\numexpr\mym+1\relax
    \pgfmathtruncatemacro{\myentry}{\myentry+{\mylist}[\myk-1]}%
   \fi
  \fi
 \fi
 \ifnum\myj=\mym\relax
  \edef\mynewlist{\mynewlist\myentry}%
 \else
  \edef\mynewlist{\mynewlist\myentry,}%
 \fi
 \ifnum\myentry=0\relax
  \edef\myentry{}%
 \fi
 \ifnum\myj=\mym\relax
  \addtabtokse{\myentry\\}%
 \else
  \addtabtokse{\myentry &}%
 \fi
\fi
},row/.code={\edef\myi{\the\numexpr\myi+1}%
\edef\myj{0}%
\edef\mynewlist{}%
\pgfkeys{/summation table keys/row entry/.list/.expanded={\mylist}}%
\let\mylist\mynewlist
}}
\makeatother

\begin{document}
\[\pgfkeys{summation table={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}\]

\[\pgfkeys{summation table={0,0,0,0,0,0,0,1,0,0,0,0,0,0,0}}\]

\end{document}

enter image description here

1

I think the following provides an intuitive interface - separating column elements with (say) , and stacks with ;, all of which are replaced with the appropriate array commands through patching with etoolbox:

enter image description here

\documentclass{article}

\usepackage{etoolbox}

\newcommand{\arraystackcols}{\patchcmd{\arraystackdata}{,}{\\}{\arraystackcols}{}}
\newcommand{\arraystackrows}{\patchcmd{\arraystackdata}{;}{\end{array}\begin{array}[b]{c}}{\arraystackrows}{}}
\newcommand{\arraystack}[1]{%
  \def\arraystackdata{#1}%
  \arraystackcols
  \arraystackrows
  \begin{array}[b]{c} \arraystackdata \end{array}
}

\begin{document}

\[
  \begin{array}{c}
    \arraystack{
      1, 1, 1, 1, 1;
      5;
      4, 4;
      7;
      3, 3, 3;
      8;
      5, 5;
      7;
      2, 2, 2, 2;
      7;
      5, 5;
      8;
      3, 3, 3;
      7;
      4, 4;
      5;
      1, 1, 1, 1, 1
    } \\
    \vdots
  \end{array}
\]

\end{document}

You must log in to answer this question.

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