3

I have a table with 102 rows (102 = 17 x 6).
How can I put that into a multicolumn-environment with 6 columns which have 17 rows each?
With other words: How can I enforce a column break after each 17th row?

Hint: The table content itself should not be splitted, because there is much higlighting-stuff later (with pgfplotstable).
Hint: The table-rows have a content like in the picture.

enter image description here

MWE:

 \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}

cis
  • 8,073
  • 1
  • 16
  • 45

3 Answers3

4

I wouldn't use a tabular but output the data simply in boxes:

\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}

enter image description here

Ulrike Fischer
  • 327,261
  • Aha, ok. I think that will work.
    And that the multicols became larger than the content is a multicol.sty "feature", I guess?
    – cis Feb 02 '22 at 16:38
  • Seems that this method kills other keys. I can't use %\usepackage{colotbl} every row no 5/.style={ before row=\rowcolor{yellow}}, – cis Feb 02 '22 at 17:02
  • well sure you no longer have a tabular. Use simply \color{yellow}. Or \colorbox or whatever. – Ulrike Fischer Feb 02 '22 at 17:17
  • Ah, I think I understand: this creates a table-look-like. Puh, but that's not so good. I fera, I can't use that solution. – cis Feb 02 '22 at 17:24
  • why not? you can do everything you can do with a table also without a table and with much less interference to multicol. – Ulrike Fischer Feb 02 '22 at 17:57
  • The first problem is that the method ruins the look of the document since the multicols span the whole page, not just the filled area.

    Otherwise I can't use practically anything from pgfplotstable (e.g. skip rows etc.)

    – cis Feb 02 '22 at 18:00
  • the multicol behaviour is quite unrelated as you could easily check by creating a simple multicol. – Ulrike Fischer Feb 02 '22 at 18:08
  • This is certainly a true statement and the method may be technically correct somewhere, but the solution is practically inapplicable. – cis Feb 02 '22 at 18:12
  • the problem with multicol is that there is a \newcolumn too much (at the end), so you will have to tell somehow pgfplotstable not to insert it at the end. – Ulrike Fischer Feb 02 '22 at 18:23
3

Based on my answer here for integrating a longtable inside 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}

I have added some highlighting to show that that works. No \columnbreaks are necessary, as multicols does the balancing itself.

enter image description here

  • This is a very professional solution that is amazingly simple if one knows the commands. Helps me good! – cis Feb 03 '22 at 18:44
3

Here is a solution with tabularray package:

\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}

enter image description here

L.J.R.
  • 10,932
  • I did not realize in the documentation that tabularray articulate itself super well with pgfplottable!! – JeT Feb 22 '22 at 12:37
  • 1
    @Jet In fact, pgfplotstable is flexible and works well with other table packages. Anyway, It would be better to add more contents in this topic to tabularray documentation. – L.J.R. Feb 22 '22 at 14:09