我有一张宽表,有 15 列。每 3 列应分组并一起查看,因此我有 5 个组。第一个组应固定并随时查看。
是否可以制作一个仅显示 2 个组的可折叠桌子?第一组和另外四个的可选组。
我的用户不喜欢翻转表格。打印生成的 PDF 时除了默认组外,还会有第一个组。
我是不是在做白日梦?这个折叠桌能实现吗?
答案1
在这里,我展示了usepartition
使用 4 个独立分区对相同的 15 列输入进行操作的环境。
\documentclass{article}
\usepackage{environ,listofitems}
\newtoks\tabtoks
\NewEnviron{usepartion}[1]{%
\tabtoks{}%
\setsepchar{\\/&}%
\readlist\mytab{\BODY}%
\foreachitem\x\in\mytab{%
\ifnum1=#1\relax%
\edef\tmp{\mytab[\xcnt,1]&\mytab[\xcnt,2]&\mytab[\xcnt,3]&%
\mytab[\xcnt,4]&\mytab[\xcnt,5]&\mytab[\xcnt,6]}%
\else
\ifnum2=#1\relax%
\edef\tmp{\mytab[\xcnt,1]&\mytab[\xcnt,2]&\mytab[\xcnt,3]&%
\mytab[\xcnt,7]&\mytab[\xcnt,8]&\mytab[\xcnt,9]}%
\else
\ifnum3=#1\relax%
\edef\tmp{\mytab[\xcnt,1]&\mytab[\xcnt,2]&\mytab[\xcnt,3]&%
\mytab[\xcnt,10]&\mytab[\xcnt,11]&\mytab[\xcnt,12]}%
\else
\ifnum4=#1\relax%
\edef\tmp{\mytab[\xcnt,1]&\mytab[\xcnt,2]&\mytab[\xcnt,3]&%
\mytab[\xcnt,13]&\mytab[\xcnt,14]&\mytab[\xcnt,15]}%
\fi\fi\fi\fi%
\expandafter\tabtoks\expandafter\expandafter\expandafter{%
\expandafter\the\expandafter\tabtoks\tmp\\}
}%
\begin{tabular}{|ccc|ccc|}
\the\tabtoks
\end{tabular}%
}
\begin{document}
\begin{usepartion}{1}
1& 2& 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14& 15\\
a& bb& ccc & d & ee & ff & ggg & hh & ii & j & k & lll & mm & nnn& o
\end{usepartion}
\begin{usepartion}{2}
1& 2& 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14& 15\\
a& bb& ccc & d & ee & ff & ggg & hh & ii & j & k & lll & mm & nnn& o
\end{usepartion}
\begin{usepartion}{3}
1& 2& 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14& 15\\
a& bb& ccc & d & ee & ff & ggg & hh & ii & j & k & lll & mm & nnn& o
\end{usepartion}
\begin{usepartion}{4}
1& 2& 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14& 15\\
a& bb& ccc & d & ee & ff & ggg & hh & ii & j & k & lll & mm & nnn& o
\end{usepartion}
\end{document}
更精简的代码,但需要牺牲一个额外的包:
\documentclass{article}
\usepackage{environ,listofitems,pgffor}
\newtoks\tabtoks
\newcounter{offset}
\NewEnviron{usepartion}[1]{%
\tabtoks{}%
\setcounter{offset}{0}%
\setsepchar{\\/&}%
\readlist\mytab{\BODY}%
\foreach\y in {1,...,#1}{%
\addtocounter{offset}{3}% 3 IS THE SIZE OF THE PARTITION GROUP
}%
\foreachitem\x\in\mytab{%
\edef\tmp{\mytab[\xcnt,1]&\mytab[\xcnt,2]&\mytab[\xcnt,3]&% COMMON PARTITION
\mytab[\xcnt,\numexpr\theoffset+1]&%
\mytab[\xcnt,\numexpr\theoffset+2]&%
\mytab[\xcnt,\numexpr\theoffset+3]}% SPECIFIED PARTITION
\expandafter\tabtoks\expandafter\expandafter\expandafter{%
\expandafter\the\expandafter\tabtoks\tmp\\}% BUILD UP THE TOKEN LIST
}%
\begin{tabular}{|ccc|ccc|}
\the\tabtoks
\end{tabular}%
}
\begin{document}
\def\mydata{1& 2& 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14& 15\\
a& bb& ccc & d & ee & ff & ggg & hh & ii & j & k & lll & mm & nnn& o}
\begin{usepartion}{1}\mydata\end{usepartion}\par
\begin{usepartion}{2}\mydata\end{usepartion}\par
\begin{usepartion}{3}\mydata\end{usepartion}\par
\begin{usepartion}{4}\mydata\end{usepartion}\par
\end{document}
答案2
经过几次尝试,我找到了一个不错的解决方案:
\documentclass{article}
\pagestyle{empty}
\usepackage{amsmath,amssymb}
\usepackage{animate}
\usepackage{xcolor}
\begin{document}
\begin{animateinline}[controls]{1}
\begin{tabular}{|ccc|ccc|}\hline
1& 2& 3& 4& 5& 6 \\\hline
a& b& c& d& e& f \\\hline
\end{tabular}
\newframe
\begin{tabular}{|ccc|ccc|}\hline
1& 2& 3& 7& 8& 9 \\\hline
a& b& c& g& h& i \\\hline
\end{tabular}
\newframe
\begin{tabular}{|ccc|ccc|}\hline
1& 2& 3& 10& 11& 12 \\\hline
a& b& c& j& k& l \\\hline
\end{tabular}
\newframe
\begin{tabular}{|ccc|ccc|}\hline
1& 2& 3& 13& 14& 15 \\\hline
a& b& c& m& n& o \\\hline
\end{tabular}
\end{animateinline}
\end{document}
这添加了动画控制以滚动宽表,前三列固定不变。仍需要一些增强功能来减少代码大小。