我有一张有 102 行 (102 = 17 x 6) 的表格。
我怎样才能将其放入一个有 6 列、每列有 17 行的多列环境中?
换句话说:我怎样才能在每 17 行之后强制分列?
提示:表格内容本身应该不分裂,因为稍后会有很多突出显示的内容(使用 pgfplotstable)。
提示:表格行具有与图片中类似的内容。
梅威瑟:
\documentclass[a4paper, landscape]{article}
\usepackage[margin=5mm]{geometry}
\usepackage{multicol}
\setlength\columnseprule{.4pt}
\usepackage{pgfplotstable}
%\usepackage{longtable}% Does not work in multicol
\usepackage{supertabular}% Does work in multicol
\begin{document}
% Create an example table ====================
\def\OutFilename{\jobname-meta.txt}
\newwrite\MyFile
\immediate\openout\MyFile=\OutFilename
\foreach \n in {1,...,102}{%%
\immediate\write\MyFile{(\n), AAA, BBB }
}%%
\immediate\closeout\MyFile
%Test: \input{\OutFilename}
%===================================
\begin{multicols}{6}
\pgfplotstabletypeset[string type, col sep=comma,
column type={}, % seems to be needed 1/2
begin table={\begin{supertabular}{ l l l }},% column types defined here 2/2
end table=\end{supertabular},
% Does not work:
%every nth row={17}{after row={\vfill\null\columnbreak} },
%every row no 3/.style={before row=\vfill\null \columnbreak}},
]{\OutFilename}
\end{multicols}
\end{document}
答案1
根据我的回答这里用于集成longtable
内部multicols
:
\documentclass[a4paper, landscape]{article}
\usepackage[margin=5mm]{geometry}
\usepackage[table]{xcolor}
\usepackage{multicol}
\setlength\columnseprule{.4pt}
\usepackage{pgfplotstable}
\usepackage{longtable}% Does not work in multicol
%\usepackage{supertabular}% Does work in multicol
\newsavebox\ltmcbox
\newlength\mysavecolroom
\begin{document}
% Create an example table ====================
\def\OutFilename{\jobname-meta.txt}
\newwrite\MyFile
\immediate\openout\MyFile=\OutFilename
\foreach \n in {1,...,102}{%%
\immediate\write\MyFile{(\n), AAA, BBB }
}%%
\immediate\closeout\MyFile
%Test: \input{\OutFilename}
%===================================
\begin{multicols}{6}
\makeatletter\mysavecolroom=\@colroom\makeatother
\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne\makeatother
\pgfplotstabletypeset[string type, col sep=comma,
column type={}, % seems to be needed 1/2
begin table={\begin{longtable}{ l l l }},% column types defined here 2/2
end table=\end{longtable},
% Does not work:
every nth row={8}{before row={\rowcolor{yellow}} },
]{\OutFilename}
\unskip
\unpenalty
\unpenalty}
\makeatletter\@colroom=\mysavecolroom\makeatother
\unvbox\ltmcbox
\end{multicols}
\end{document}
我添加了一些突出显示来表明这是有效的。不需要\columnbreak
s,multicols
平衡本身也不需要。
答案2
我不会使用表格,而是简单地在框中输出数据:
\documentclass[a4paper, landscape]{article}
\usepackage[margin=5mm]{geometry}
\usepackage{multicol}
\setlength\columnseprule{.4pt}
\usepackage{pgfplotstable}
%
\begin{document}
% Create an example table ====================
\def\OutFilename{\jobname-meta.txt}
\newwrite\MyFile
\immediate\openout\MyFile=\OutFilename
\foreach \n in {1,...,102}{%%
\immediate\write\MyFile{(\n), AAA, BBB }
}%%
\immediate\closeout\MyFile
%Test: \input{\OutFilename}
%===================================
\makeatletter
\begin{multicols}{6}
\pgfplotstabletypeset[string type, col sep=comma,
header=false,
every head row/.style={output empty row},
column type={}, % seems to be needed 1/2
begin table={},% column types defined here 2/2
end table={},
every nth row={17[-2]}{after row={\columnbreak} },
every nth row={102[-2]}{after row={}},
/pgfplots/table/typeset cell/.code={%
\ifnum\c@pgfplotstable@colindex=\c@pgfplotstable@numcols\relax
\pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\\}%
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\noindent\makebox[3em][l]{#1}\quad}%
\fi
}
]{\OutFilename}
\end{multicols}
\end{document}
答案3
这是一个解决方案tabularray
包裹:
\documentclass[a4paper,landscape]{article}
\usepackage[margin=5mm]{geometry}
\usepackage{multicol}
\setlength\columnseprule{0.4pt}
\usepackage{pgfplotstable}
\usepackage{tabularray}
\SetTblrTemplate{head,foot}{empty}
\begin{document}
\def\OutFilename{\jobname-meta.txt}
\newwrite\MyFile
\immediate\openout\MyFile=\OutFilename
\foreach \n in {1,...,102}{%
\immediate\write\MyFile{(\n), AAA, BBB}%
}%
\immediate\closeout\MyFile
\begin{multicols}{6}
\let\newpage=\par
\pgfplotstabletypeset[
string type,
col sep = comma,
skip coltypes,
begin table={\begin{longtblr}[
halign = l,
headsep = 0pt,
footsep = 0pt,
presep = 0pt,
postsep = 0pt,
]{
colspec = lll,
}},
end table = \end{longtblr},
header = false,
every head row/.style = {output empty row},
every nth row = {17}{before row=\pagebreak},
every nth row = {7}{before row=\SetRow{yellow7}},
]{\OutFilename}
\end{multicols}
\end{document}