如何制作数字数组?

如何制作数字数组?

我正在尝试重现我在一篇论文的 pdf 中找到的这些数组。我没有该文件.tex,所以我不知道如何构建它。

在此处输入图片描述

答案1

\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}

在此处输入图片描述

答案2

您可以让 LaTeX 创建这些表格。只需指定第一行,LaTeX 便可计算出其余部分。

\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}

在此处输入图片描述

答案3

我认为以下内容提供了一个直观的界面 - 用(例如)分隔列元素,并用 堆叠;,所有这些都array通过使用 进行修补替换为适当的命令etoolbox

在此处输入图片描述

\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}

相关内容