有没有一种简单/基本的方法来获得“制表”?
请注意,行数和列数基本上是变量或取决于循环。
\documentclass[a4paper]{article}
\usepackage{tikz}
\newcounter{rowno}
\setcounter{rowno}{-1}
%\stepcounter{rowno}
%\therowww
\begin{document}
\def\Rows{7}
\foreach \n in {1,...,\Rows}{%%
%\noindent\n,~
\foreach \col in {1,...,\Rows}{%
\pgfmathsetmacro\filled{\col<=\n ? 1 : 0}
\pgfmathsetmacro\first{\col==\n ? 1 : 0}
\noindent\ifnum\filled=1 \stepcounter{rowno}%
\ifnum\first=1 \col f, \therowno%
\else \col,\therowno\fi%
~~~ \else x\fi
}\\%
}%%
\end{document}
答案1
是的。该tabto
包可以提供帮助。这里,\tabstart
定义表格的左边距,长度\tabinc
给出列间距增量。
\documentclass[a4paper]{article}
\usepackage{tikz,tabto}
\newlength\currtab
\newlength\tabinc
\setlength\tabinc{30pt}
\def\tabstart{0pt}
\newcounter{rowno}
\setcounter{rowno}{-1}
%\stepcounter{rowno}
%\therowww
\begin{document}
\def\Rows{7}
\foreach \n in {1,...,\Rows}{%%
\noindent
\setlength{\currtab}{\tabstart}%
\tabto{\currtab}%
%\noindent\n,~
\foreach \col in {1,...,\Rows}{%
\pgfmathsetmacro\filled{\col<=\n ? 1 : 0}%
\pgfmathsetmacro\first{\col==\n ? 1 : 0}%
\noindent\ifnum\filled=1 \stepcounter{rowno}%
\ifnum\first=1 \col f, \therowno%
\else \col,\therowno\fi%
\else x\fi
\global\addtolength{\currtab}{\tabinc}%
\tabto{\currtab}%
}%
}%%
\end{document}
答案2
\documentclass[a4paper]{article}
\begin{document}
\def\Rows{7 }
\newcount\rrr \rrr=1
\newcount\ccc \ccc=1
\newcount\ttt \ttt=0
\loop
{%
\loop
\makebox[3em][l]{%
\ifnum\rrr<\ccc
x%
\else
\the\ccc
\ifnum\rrr=\ccc f\fi
,\the\ttt
\global\advance\ttt1
\fi
}
\ifnum\ccc<\Rows
\advance\ccc1
\repeat
}
\par
\ifnum\rrr<\Rows
\advance\rrr1
\repeat
\end{document}
答案3
\documentclass[margin=5mm, varwidth]{standalone}
\usepackage{tikz}
\begin{document}
\section{Normal Tabbing}
\begin{tabbing}
Left \= Middle \= Right \kill
1 \> 2 \> 3 \\
\end{tabbing}
\section{Foreach Tabbing}
\newcommand\tabrow[1]{%
\setlength{\topsep}{2pt}%
\setlength{\partopsep}{0pt}%
\begin{tabbing}
Left \= Middle \= Right \kill% tabhead
%1 \> 2 \> 3 %\\
#1 %\\
\end{tabbing}}
%Test: \tabrow{1 \> 2 \> 3}
\foreach \m in {0,1,...,7}{
\ifnum\m=0 \tabrow{$m$ \> $m^2$ \> $m+1$}%
\else%
\pgfmathsetmacro\mI{\m*\m}
\pgfmathsetmacro\mII{\m+1}
\tabrow{\m \> \mI \> \mII}
\fi}