如何在 LaTeX 中最好地显示最终周期序列

如何在 LaTeX 中最好地显示最终周期序列

我想证明,在计算了一些值之后,我的序列似乎最终是周期性的。这两个序列分别在前 34 个和 48 个值之后都是周期性的,并且周期为 34 和 48。

我试图通过为每个表格显示一个表格来实现这一点,比如说有 4 行和 34/48 列,其中除第一行外其他行都相同。我认为将第一行到第二行的数字以粗体显示也不错。

显然 34/48 列确实很大,所以我不确定如何将其放入行宽内,以便仍然可读且看起来不错。有人对如何实现这一点有什么建议吗?或者有更好的建议来显示周期序列?

答案1

如果您在逗号周围留出一点空间,它将适合默认article文本宽度。b不要使用bx粗体字体,这样可以保留对齐。

在此处输入图片描述

\documentclass{article}

\def\,{\kern-.1pt,\kern-.4pt}
\def\!#1{{\fontseries{b}\selectfont#1}}
\begin{document}

\noindent X\dotfill X

\begin{flushleft}
\!0\,1\,1\,0\,2\,1\,3\,0\,1\,1\,3\,2\,2\,3\,4\,\!1\,5\,\!3\,2\,2\,3\,1\,1\,0\,3\,1\,2\,0\,1\,1\,4\,4\,\!2\,\\
4\,1\,1\,0\,2\,1\,3\,0\,1\,1\,3\,2\,2\,3\,4\,4\,5\,7\,2\,2\,3\,1\,1\,0\,3\,1\,2\,0\,1\,1\,4\,4\,3\,\\
4\,1\,1\,0\,2\,1\,3\,0\,1\,1\,3\,2\,2\,3\,4\,4\,5\,7\,2\,2\,3\,1\,1\,0\,3\,1\,2\,0\,1\,1\,4\,4\,3
\end{flushleft}

\noindent X\dotfill X

\begin{flushleft}
0\,1\,\!1\,1\,0\,2\,\!2\,\!1\,3\,4\,0\,1\,\!1\,1\,3\,2\,\!2\,2\,3\,4\,0\,1\,\!5\,4\,3\,2\,\!2\,2\,3\,1\,0\,1\,0\,4\,3\,\!2\,2\,2\,0\,1\,0\,1\,0\,4\,3\,2\,\!5\,\\
0\,1\,0\,1\,0\,2\,3\,2\,3\,4\,0\,1\,0\,1\,3\,2\,3\,2\,3\,4\,0\,1\,0\,4\,3\,2\,3\,2\,3\,1\,0\,1\,0\,4\,3\,2\,3\,2\,0\,1\,0\,1\,0\,4\,3\,2\,3\,\\
0\,1\,0\,1\,0\,2\,3\,2\,3\,4\,0\,1\,0\,1\,3\,2\,3\,2\,3\,4\,0\,1\,0\,4\,3\,2\,3\,2\,3\,1\,0\,1\,0\,4\,3\,2\,3\,2\,0\,1\,0\,1\,0\,4\,3\,2\,3
\end{flushleft}

\noindent X\dotfill X

\end{document}

答案2

\rules以下是将该方法与相结合的方法tikz。这可能在指示周期性影响时有所帮助,如下所示:

在此处输入图片描述

新的:

  • textcolor为了\rule
  • 将条形图文本嵌入tikz-node
  • tikzpicture在via中添加相同的行和文本\draw

取消注释help lines以调整所绘制的线条。

\documentclass[10pt]{article}
\usepackage{calc}% to calculate rule-heights
\usepackage{datatool}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{color}

% ~~~ data ~~~~~~~~~~~~~~~~~~~~~~~~~
\newcommand\A[0]{%
 0,1,1,0,2,1,3,0,1,1,3,2,2,3,4,1,5,3,2,2,3,1,1,0,3,1,2,0,1,1,4,4,2, 4,1,1,0,2,1,3,0,1,1,3,2,2,3,4,4,5,7,2,2,3,1,1,0,3,1,2,0,1,1,4,4,3, 4,1,1,0,2,1,3,0,1,1,3,2,2,3,4,4,5,7,2,2,3,1,1,0,3,1,2,0,1,1,4,4,3}
 
\newcommand\B[0]{%
0,1,1,1,0,2,2,1,3,4,0,1,1,1,3,2,2,2,3,4,0,1,5,4,3,2,2,2,3,1,0,1,0,4,3,2,2,2,0,1,0,1,0,4,3,2,5, 0,1,0,1,0,2,3,2,3,4,0,1,0,1,3,2,3,2,3,4,0,1,0,4,3,2,3,2,3,1,0,1,0,4,3,2,3,2,0,1,0,1,0,4,3,2,3, 0,1,0,1,0,2,3,2,3,4,0,1,0,1,3,2,3,2,3,4,0,1,0,4,3,2,3,2,3,1,0,1,0,4,3,2,3,2,0,1,0,1,0,4,3,2,3}
 
 
% ~~~ what the datatool (DTL) shall print ~~~~~~~~~~~~~~ 
\renewcommand{\DTLlistformatsep}{}% no commas printed
\renewcommand{\DTLlistformatlastsep}{}% no spacing between last two items
\renewcommand{\DTLandname}{}% no "and", "&" etc. between last two items
\renewcommand{\DTLlistformatitem}[1]{\textcolor{blue}{\rule{2.2pt}{1cm*#1}}}% bars=rule

% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}

\begin{tikzpicture}
%   \draw [help lines] (-3,-3) grid (3,3);
    \node {\DTLformatlist{\A}};
    \draw [dashed,red] (-1,-3) -- (-1,4);% indicator
\end{tikzpicture}
\bigskip
  
\begin{tikzpicture}
%   \draw [help lines] (-3,-3) grid (3,3);
    \node {\DTLformatlist{\B}};
    \draw [dashed,red]  (-1.8 ,-3) -- (-1.8 ,3);% indicator
    \draw [dashed,red]  ( 1.85,-3) -- ( 1.85,3);% indicator
    \draw [{Stealth}-{Stealth},red!70]  (-1.8,2.6) -- node [yshift=1em] {periodic} ( 1.85,2.6);
\end{tikzpicture}

\end{document}

答案3

您只需输入前两行即可自动突出显示更改的项目。

\documentclass{article}
\usepackage{amsmath}

\ExplSyntaxOn

% eventually periodic
\NewDocumentCommand{\ep}{O{}mm}
 {% #1 = font size, #2 = first row, #3 = further rows
  \mbox { #1 \max_ep:nn { #2 } { #3 } }
 }

\seq_new:N \l__max_ep_first_in_seq
\seq_new:N \l__max_ep_first_out_seq
\seq_new:N \l__max_ep_second_seq

\cs_new_protected:Nn \max_ep:nn
 {
  \seq_set_from_clist:Nn \l__max_ep_first_in_seq { #1 }
  \seq_set_from_clist:Nn \l__max_ep_second_seq { #2 }
  \seq_clear:N \l__max_ep_first_out_seq
  \seq_mapthread_function:NNN \l__max_ep_first_in_seq \l__max_ep_second_seq \__max_ep_diff:nn
  \begin{tabular}{@{}l@{}}
  \seq_use:Nn \l__max_ep_first_out_seq { , } , \\
  \seq_use:Nn \l__max_ep_second_seq { , } , \\
  \seq_use:Nn \l__max_ep_second_seq { , } , \\
  \dots
  \end{tabular}
 }

\cs_new_protected:Nn \__max_ep_diff:nn
 {
  \str_if_eq:nnTF { #1 } { #2 }
   {% items are equal
    \seq_put_right:Nn \l__max_ep_first_out_seq { #1 }
   }
   {% items differ
    \seq_put_right:Nn \l__max_ep_first_out_seq
     { \makebox[\fontcharwd\font`0]{\fontseries{b}\selectfont #1} }
   }
 }

\ExplSyntaxOff

\begin{document}

\noindent X\dotfill X

\begin{flushleft}
\ep{
  0,1,1,0,2,1,3,0,1,1,3,2,2,3,4,1,5,3,2,2,3,1,1,0,3,1,2,0,1,1,4,4,2
}{
  4,1,1,0,2,1,3,0,1,1,3,2,2,3,4,4,5,7,2,2,3,1,1,0,3,1,2,0,1,1,4,4,3
}
\end{flushleft}

\noindent X\dotfill X

\begin{flushleft}
\ep[\small]{
  0,1,1,1,0,2,2,1,3,4,0,1,1,1,3,2,2,2,3,4,0,1,5,4,3,2,2,2,3,1,0,1,0,4,3,2,2,2,0,1,0,1,0,4,3,2,5
}{
  0,1,0,1,0,2,3,2,3,4,0,1,0,1,3,2,3,2,3,4,0,1,0,4,3,2,3,2,3,1,0,1,0,4,3,2,3,2,0,1,0,1,0,4,3,2,3
}
\end{flushleft}

\noindent X\dotfill X

\end{document}

这个想法是用给定的参数填充两个序列。将第一个序列与第二个序列逐项进行比较,如果没有变化则按原样添加该项,否则选择粗体。

接下来使用序列制作表格,并重新插入逗号。

如果序列太长,可以使用字体大小选择的可选参数。

好奇

\makebox[\fontcharwd\font`0]{\fontseries{b}\selectfont #1}

是因为粗体在 Computer Modern 中不是光学缩放的,所以我将不同的数字设置在与正常数字一样宽的框中。

在此处输入图片描述

在以下版本中,*第一个参数表示空白。

\documentclass{article}
\usepackage{amsmath}

\ExplSyntaxOn

% eventually periodic
\NewDocumentCommand{\ep}{O{}mm}
 {% #1 = font size, #2 = first row, #3 = further rows
  \mbox { #1 \max_ep:nn { #2 } { #3 } }
 }

\seq_new:N \l__max_ep_first_in_seq
\seq_new:N \l__max_ep_first_out_seq
\seq_new:N \l__max_ep_second_seq

\cs_new_protected:Nn \max_ep:nn
 {
  \seq_set_from_clist:Nn \l__max_ep_first_in_seq { #1 }
  \seq_set_from_clist:Nn \l__max_ep_second_seq { #2 }
  \seq_clear:N \l__max_ep_first_out_seq
  \seq_mapthread_function:NNN \l__max_ep_first_in_seq \l__max_ep_second_seq \__max_ep_diff:nn
  \begin{tabular}{@{}l@{}}
  \seq_use:Nn \l__max_ep_first_out_seq { } \\
  \seq_use:Nn \l__max_ep_second_seq { , } , \\
  \seq_use:Nn \l__max_ep_second_seq { , } , \\
  \dots
  \end{tabular}
 }



\cs_new_protected:Nn \__max_ep_diff:nn
 {
  \str_if_eq:nnTF { #1 } { * }
   {% blank
    \seq_put_right:Nn \l__max_ep_first_out_seq { \mbox{\phantom{0,}} }
   }
   {% non blank
    \str_if_eq:nnTF { #1 } { #2 }
     {% items are equal
      \seq_put_right:Nn \l__max_ep_first_out_seq { #1, }
     }
     {% items differ
      \seq_put_right:Nn \l__max_ep_first_out_seq
       { \makebox[\fontcharwd\font`0]{\fontseries{b}\selectfont #1}, }
     }
   }
 }

\ExplSyntaxOff

\begin{document}

\noindent X\dotfill X

\begin{flushleft}
\ep{
  0,1,1,0,2,1,3,0,1,1,3,2,2,3,4,1,5,3,2,2,3,1,1,0,3,1,2,0,1,1,4,4,2
}{
  4,1,1,0,2,1,3,0,1,1,3,2,2,3,4,4,5,7,2,2,3,1,1,0,3,1,2,0,1,1,4,4,3
}
\end{flushleft}

\noindent X\dotfill X

\begin{flushleft}
\ep[\small]{
  0,1,1,1,0,2,2,1,3,4,0,1,1,1,3,2,2,2,3,4,0,1,5,4,3,2,2,2,3,1,0,1,0,4,3,2,2,2,0,1,0,1,0,4,3,2,5
}{
  0,1,0,1,0,2,3,2,3,4,0,1,0,1,3,2,3,2,3,4,0,1,0,4,3,2,3,2,3,1,0,1,0,4,3,2,3,2,0,1,0,1,0,4,3,2,3
}
\end{flushleft}

\noindent X\dotfill X

\begin{flushleft}
\ep{
  *,1,2,3,4,5,6
}{
  0,0,2,3,4,5,6
}
\end{flushleft}

\end{document}

在此处输入图片描述

答案4

这是一种直观的方法。

主要步骤:

  • \A\B提供数据
  • datatool (\DTL...)允许访问个人数据
  • 定义\renewcommand如何打印数据
  • 一个简单的\rule{}{}创建条形图的图表
  • 在那里改变宽度和高度
  • 如果你愿意的话,可以引入规则的文本颜色

结果

\documentclass[10pt]{article}
\usepackage{calc}% to calculate rule-heights
\usepackage{datatool}

% ~~~ data ~~~~~~~~~~~~~~~~~~~~~~~~~
\newcommand\A[0]{%
 0,1,1,0,2,1,3,0,1,1,3,2,2,3,4,1,5,3,2,2,3,1,1,0,3,1,2,0,1,1,4,4,2, 4,1,1,0,2,1,3,0,1,1,3,2,2,3,4,4,5,7,2,2,3,1,1,0,3,1,2,0,1,1,4,4,3, 4,1,1,0,2,1,3,0,1,1,3,2,2,3,4,4,5,7,2,2,3,1,1,0,3,1,2,0,1,1,4,4,3}
 
\newcommand\B[0]{%
0,1,1,1,0,2,2,1,3,4,0,1,1,1,3,2,2,2,3,4,0,1,5,4,3,2,2,2,3,1,0,1,0,4,3,2,2,2,0,1,0,1,0,4,3,2,5, 0,1,0,1,0,2,3,2,3,4,0,1,0,1,3,2,3,2,3,4,0,1,0,4,3,2,3,2,3,1,0,1,0,4,3,2,3,2,0,1,0,1,0,4,3,2,3, 0,1,0,1,0,2,3,2,3,4,0,1,0,1,3,2,3,2,3,4,0,1,0,4,3,2,3,2,3,1,0,1,0,4,3,2,3,2,0,1,0,1,0,4,3,2,3}
 
 
% ~~~ what the datatool (DTL) shall print ~~~~~~~~~~~~~~ 
\renewcommand{\DTLlistformatsep}{}% no commas printed
\renewcommand{\DTLlistformatlastsep}{}% no spacing between last two items
\renewcommand{\DTLandname}{}% no "and", "&" etc. between last two items
\renewcommand{\DTLlistformatitem}[1]{\rule{2.2pt}{1cm*#1}}% bars=rule

% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
    Sequence A, with \DTLnumitemsinlist{\A}{\listnum}\listnum \ data:
    
    \fbox{\DTLformatlist{\A}}
    \bigskip    
    
    Sequence B, with \DTLnumitemsinlist{\B}{\listnum}\listnum \ data:

    \fbox{\DTLformatlist{\B}}
    \bigskip
    
    Both sequences are periodic after about $30$ \% of data, measured from the start.

\end{document}

相关内容