我在 Beamer 中绘制了许多幻灯片,如下所示。但是我希望所有元素都有固定大小。我该如何以实际的方式做到这一点,比如定义 \vet{1,2,3,4} 命令?
资料来源:
\documentclass{beamer}
\usepackage{tikz}
\usepackage{color}
\newcommand{\vet}[1]{\foreach \num in {#1}{\el{\num}}}
\newcommand{\el}[1]{\fbox{#1}\hspace*{.01em}}
\newcommand{\bl}{\color{blue}}
\newcommand{\gr}{\color{gray}}
\newcommand{\re}{\color{red}}
\begin{document}
\begin{frame}[fragile]\frametitle{Merge}
\begin{tabular}{cc}
copy value from aux & into sorted array\\
\vet{\re $1^i$,\re 3,\re 5,\re 6, \bl $0^j$,\bl 2,\bl 4,\bl 9,\bl 10} &
\vet{\bl 0, \#, \#, \#, \#, \#, \#, \#,\#}\\ \\
\vet{\re $1^i$,\re 3,\re 5,\re 6, \gr 0, \bl $2^j$,\bl 4,\bl 9,\bl 10} &
\vet{\gr 0, \re 1, \#, \#, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \re $3^i$,\re 5,\re 6, \gr 0, \bl $2^j$,\bl 4,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \bl 2, \#, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \re $3^i$,\re 5,\re 6, \gr 0, \gr 2,\bl $4^j$,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \re 3, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\re $5^i$,\re 6, \gr 0, \gr 2,\bl $4^j$,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \bl 4, \#, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\re $5^i$,\re 6, \gr 0, \gr 2,\gr 4,\bl $9^j$,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \re 5, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\gr 5,\re $6^i$,\gr 0, \gr 2,\gr 4,\bl $9^j$,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \gr 5, \re 6,\#, \#}\\
\vet{\gr 1, \gr 3,\gr 5,\gr $6^i$,\gr 0, \gr 2,\gr 4,\bl $9^j$,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \gr 5, \gr 6, \bl 9,\bl 10}\\
\end{tabular}
\end{frame}
\end{document}
答案1
我相信 Ti 也能做到这一点钾Z。
您可以添加可选参数来integerarrays
声明单元格的不同大小(默认为 1.5em)。
\documentclass{article}
\usepackage{xparse}
\usepackage{xcolor}
\ExplSyntaxOn
% user level commands
\NewDocumentEnvironment{integerarrays}{O{1.5em}mm+b}
{
\renewcommand{\arraystretch}{0}
\dim_set:Nn \l_kees_array_width_dim { #1 }
\kees_array_table:nnn { #2 } { #3 } { #4 }
}{}
\NewDocumentCommand{\vet}{O{}m}
{
\group_begin:
\dim_compare:nT { \l_kees_array_width_dim = 0pt }
{% we're inline
\dim_set:Nn \l_kees_array_width_dim { 1.5em }
}
\keys_set:nn { kees/array } { #1 }
\kees_array_vet:n { #2 }
\group_end:
}
% keys
\keys_define:nn { kees/array }
{
width .dim_set:N = \l_kees_array_width_dim,
font .tl_set:N = \l_kees_array_font_tl,
}
% variables
%\dim_new:N \l_kees_array_width_dim
\seq_new:N \l_kees_array_body_seq
\seq_new:N \l_kees_array_vet_in_seq
\seq_new:N \l_kees_array_vet_out_seq
% internal functions
\cs_new_protected:Nn \kees_array_table:nnn
{
% split the body at \\
\seq_set_split:Nnn \l_kees_array_body_seq { \\ } { #3 }
% check for a trailing \\
\seq_pop_right:NN \l_kees_array_body_seq \l__kees_array_last_tl
\tl_if_blank:VF \l__kees_array_last_tl
{% there was no trailing \\, reinstate the last item
\seq_put_right:NV \l_kees_array_body_seq \l__kees_array_last_tl
}
\begin{tabular}{@{}cc@{}}
#1 & #2 \\[1ex]
% use the body with a bit of backing up to hide the double rule
\seq_use:Nn \l_kees_array_body_seq { \\[-\fboxrule] }
\end{tabular}
}
\cs_new_protected:Nn \kees_array_vet:n
{
% split the input at commas
\seq_set_split:Nnn \l_kees_array_vet_in_seq { , } { #1 }
% make each item the argument to the boxing macro
\seq_set_map:NNn \l_kees_array_vet_out_seq \l_kees_array_vet_in_seq
{
\kees_array_box:n { \exp_not:n { ##1 } }
}
% use the sequence backing up a bit to hide the double rule
\seq_use:Nn \l_kees_array_vet_out_seq { \hspace{-\fboxrule} }
}
\cs_new_protected:Nn \kees_array_box:n
{
\group_begin:
\setlength{\fboxsep}{0pt}
\framebox[\l_kees_array_width_dim]
{
\l_kees_array_font_tl
\rule[-0.3\l_kees_array_width_dim]{0pt}{\l_kees_array_width_dim}$#1$
}
\group_end:
}
\ExplSyntaxOff
\newcommand{\bl}{\color{blue}}
\newcommand{\gr}{\color{gray}}
\newcommand{\re}{\color{red}}
\begin{document}
\begin{integerarrays}{copy value from aux}{into sorted array}
\vet{\re 1^i,\re 3,\re 5,\re 6, \bl 0^j,\bl 2,\bl 4,\bl 9,\bl 10} &
\vet{\bl 0, \#, \#, \#, \#, \#, \#, \#,\#}\\
\vet{\re 1^i,\re 3,\re 5,\re 6, \gr 0, \bl 2^j,\bl 4,\bl 9,\bl 10} &
\vet{\gr 0, \re 1, \#, \#, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \re 3^i,\re 5,\re 6, \gr 0, \bl 2^j,\bl 4,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \bl 2, \#, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \re 3^i,\re 5,\re 6, \gr 0, \gr 2,\bl 4^j,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \re 3, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\re 5^i,\re 6, \gr 0, \gr 2,\bl 4^j,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \bl 4, \#, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\re 5^i,\re 6, \gr 0, \gr 2,\gr 4,\bl 9^j,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \re 5, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\gr 5,\re 6^i,\gr 0, \gr 2,\gr 4,\bl 9^j,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \gr 5, \re 6,\#, \#}\\
\vet{\gr 1, \gr 3,\gr 5,\gr 6^i,\gr 0, \gr 2,\gr 4,\bl 9^j,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \gr 5, \gr 6, \bl 9,\bl 10}
\end{integerarrays}
\bigskip
\begin{integerarrays}[2em]{copy value from aux}{into sorted array}
\vet{\re 1^i,\re 3,\re 5,\re 6, \bl 0^j,\bl 2,\bl 4,\bl 9,\bl 10} &
\vet{\bl 0, \#, \#, \#, \#, \#, \#, \#,\#}\\
\vet{\re 1^i,\re 3,\re 5,\re 6, \gr 0, \bl 2^j,\bl 4,\bl 9,\bl 10} &
\vet{\gr 0, \re 1, \#, \#, \#, \#, \#, \#,\#}\\
\end{integerarrays}
\bigskip
\vet{1,2,3,4,5}
\bigskip
\vet[width=1em,font=\scriptsize]{\re 1^i,\re 3,\re 5,\re 6, \bl 0^j,\bl 2,\bl 4,\bl 9,\bl 10}
\end{document}
答案2
将命令的内容替换\el
为 TikZ 节点!这样您就可以确定固定的最小尺寸。
\documentclass{beamer}
\usepackage{tikz}
\usepackage{color}
\newcommand{\vet}[1]{\foreach \num in {#1}{\el{\num}}}
\newcommand{\el}[1]{\tikz{\node[font=\footnotesize, minimum size=16pt, draw]{#1}}}
\newcommand{\bl}{\color{blue}}
\newcommand{\gr}{\color{gray}}
\newcommand{\re}{\color{red}}
\begin{document}
\begin{frame}[fragile]\frametitle{Merge}
\begin{tabular}{cc}
copy value from aux & into sorted array\\
\vet{\re $1^i$,\re 3,\re 5,\re 6, \bl $0^j$,\bl 2,\bl 4,\bl 9,\bl 10} &
\vet{\bl 0, \#, \#, \#, \#, \#, \#, \#,\#}\\ \\
\vet{\re $1^i$,\re 3,\re 5,\re 6, \gr 0, \bl $2^j$,\bl 4,\bl 9,\bl 10} &
\vet{\gr 0, \re 1, \#, \#, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \re $3^i$,\re 5,\re 6, \gr 0, \bl $2^j$,\bl 4,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \bl 2, \#, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \re $3^i$,\re 5,\re 6, \gr 0, \gr 2,\bl $4^j$,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \re 3, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\re $5^i$,\re 6, \gr 0, \gr 2,\bl $4^j$,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \bl 4, \#, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\re $5^i$,\re 6, \gr 0, \gr 2,\gr 4,\bl $9^j$,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \re 5, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\gr 5,\re $6^i$,\gr 0, \gr 2,\gr 4,\bl $9^j$,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \gr 5, \re 6,\#, \#}\\
\vet{\gr 1, \gr 3,\gr 5,\gr $6^i$,\gr 0, \gr 2,\gr 4,\bl $9^j$,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \gr 5, \gr 6, \bl 9,\bl 10}\\
\end{tabular}
\end{frame}
\end{document}
答案3
像这样:
\documentclass{beamer}
\usepackage{tikz}
\usepackage{color}
\newcommand{\vet}[1]{\foreach \num in {#1}{\el{\num}}}
\newcommand{\el}[1]{\fbox{\parbox[t][2ex][c]{1.1em}{#1}}}
\newcommand{\bl}{\color{blue}}
\newcommand{\gr}{\color{gray}}
\newcommand{\re}{\color{red}}
\begin{document}
\begin{frame}[fragile]
\frametitle{Merge}
\footnotesize
\setlength\tabcolsep{3pt}
\renewcommand\arraystretch{0.9}
\begin{tabular}{@{} ll @{}}
copy value from aux & into sorted array\\
\vet{\re $1^i$,\re 3,\re 5,\re 6, \bl $0^j$,\bl 2,\bl 4,\bl 9,\bl 10} &
\vet{\bl 0, \#, \#, \#, \#, \#, \#, \#,\#}\\
\vet{\re $1^i$,\re 3,\re 5,\re 6, \gr 0, \bl $2^j$,\bl 4,\bl 9,\bl 10} &
\vet{\gr 0, \re 1, \#, \#, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \re $3^i$,\re 5,\re 6, \gr 0, \bl $2^j$,\bl 4,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \bl 2, \#, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \re $3^i$,\re 5,\re 6, \gr 0, \gr 2,\bl $4^j$,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \re 3, \#, \#, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\re $5^i$,\re 6, \gr 0, \gr 2,\bl $4^j$,\bl 9,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \bl 4, \#, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\re $5^i$,\re 6, \gr 0, \gr 2,\gr 4,\bl $9^j$,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \re 5, \#, \#,\#}\\
\vet{\gr 1, \gr 3,\gr 5,\re $6^i$,\gr 0, \gr 2,\gr 4,\bl $9^j$,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \gr 5, \re 6,\#, \#}\\
\vet{\gr 1, \gr 3,\gr 5,\gr $6^i$,\gr 0, \gr 2,\gr 4,\bl $9^j$,\bl 10} &
\vet{\gr 0, \gr 1, \gr 2, \gr 3, \gr 4, \gr 5, \gr 6, \bl 9,\bl 10}\\
\end{tabular}
\end{frame}
\end{document}