1

I have en environment that fails if I add any of these calls to the preamble:

  • \usepackage{pgfornament}
  • \usepackage{tikzsymbols}
  • \usepackage{xcolor}
  • \usepackage{tikz}
  • \hypersetup{colorlinks={true}}

It results in:

  • Missing } inserted. \begin{myenvironment}
  • Extra }. or forgotten \endgroup. \end{myenvironment}
  • weird spacing

Question Is there a way to make the environments compatible with the calls above?

Question Would you give me some background on this error and how to approach it?


Example

The environment is meant to balance tabular data in multiple columns.

See,

And,

enter image description here enter image description here

\documentclass[]{book}
\usepackage[T1]{fontenc}
\usepackage{longtable}
\usepackage{xparse}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage[%
showframe,%
twoside,%
top=0.75in,%
bottom=0.75in,%
marginparsep=3ex,%
marginparwidth=0.8in,%
inner=0.75in,%
outer=1.25in,%
]{geometry}
\geometry{
    papersize={6in,4in}
}
\usepackage{hyperref}    % must be the last package
\hypersetup{%
    pdfauthor            = {MyAuthor},
    pdftitle             = {MyTitle},
    pdfsubject           = {MySubject},
    pdfkeywords          = {MyKeyword},
    linkcolor            = {magenta},
    urlcolor             = {blue},
    citecolor            = {cyan},
    filecolor            = {black},
%   colorlinks           = {true},  % causes Missing } inserted in myenvironment
}

% I was hoping to use these...
%\usepackage{pgfornament}        % causes Missing } inserted in myenvironment
%\usepackage{tikzsymbols}        % causes Missing } inserted in myenvironment

% I Don't really need these but they also break it
%\usepackage{xcolor}             % causes Missing } inserted in myenvironment
%\usepackage{tikz}               % causes Missing } inserted in myenvironment


% helpers for the test
\def\shortlipsum{\par Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.\par}
\newcounter{entryno}
\setcounter{entryno}{1}
\def\tabline{Test & \the\value{entryno} & Description\addtocounter{entryno}{1}\\}
\def\tablines{\tabline\tabline\tabline\tabline\tabline\tabline\tabline\tabline\tabline}


% box for a multi column long table
% SEE https://tex.stackexchange.com/questions/161827/balanced-longtables-multicol-and-page-breaks
\makeatletter
\newsavebox\ltmcbox
\newsavebox\xxbox
\newenvironment{multicolslongtable}[1]{
    \setbox\ltmcbox\vbox\bgroup
    \col@number\@ne
    \begin{longtable}{#1}
}
{
    \end{longtable}
    \unskip
    \unpenalty
    \unpenalty
    \egroup
    \unvbox\ltmcbox
}
\makeatother


% environment to accept table input and produce multicol
\NewDocumentEnvironment{myenvironment}{O{2}}
{
    \savebox\xxbox
    \bgroup
    \begin{minipage}{\textwidth}
    \begin{multicols}{#1}
    \begin{multicolslongtable}{| l | l | l |}
}
{
    \end{multicolslongtable}
    \end{multicols}
    \end{minipage}
    \egroup
    \begin{multicols}{#1}
        \centering
        \usebox\xxbox
    \end{multicols}
}


% patch multicols to allow for one column
% SEE https://tex.stackexchange.com/questions/233866/one-column-multicol-environment
\let\multicolmulticols\multicols
\let\endmulticolmulticols\endmulticols
\RenewDocumentEnvironment{multicols}{mO{}}
{%
    \ifnum#1=1
    #2%
    \else % More than 1 column
    \multicolmulticols{#1}[#2]
    \fi
}
{%
    \ifnum#1=1
    \else % More than 1 column
    \endmulticolmulticols
    \fi
}


\begin{document}

\section{without `pgfornament` etc.}
\shortlipsum
\begin{myenvironment}
    \tablines
\end{myenvironment}
\shortlipsum

\end{document}

attempt 1: \bgroup --> \begingroup

Swapping out \bgroup --> \begingroup and \egroup --> \endgroup, results in a loss of output (Extra }, improper \prevdepth and many more)


attempt 2: try balanced longtables, multicol and page breaks again

This potential solution is compatible with the packages but I still can't refactor it into an environment.

Question Is there a way to refactor this into an environment properly?

It works when I copy / paste it (the first two tabulars) but I'd like to avoid that.

The environment produces

  • Undefined control sequence \begin{myenvironment}
  • Package longtable Error: longtable not in 1-column mode.
  • misaligned rows
  • @numberne added where a row should be

enter image description here

\documentclass[]{book}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{longtable}
\usepackage{xparse}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage[%
showframe,%
twoside,%
top=0.75in,%
bottom=0.75in,%
marginparsep=3ex,%
marginparwidth=0.8in,%
inner=0.75in,%
outer=1.25in,%
]{geometry}
\geometry{
    papersize={6in,7in}
}
\usepackage{hyperref}    % must be the last package
\hypersetup{%
    pdfauthor            = {MyAuthor},
    pdftitle             = {MyTitle},
    pdfsubject           = {MySubject},
    pdfkeywords          = {MyKeyword},
    linkcolor            = {magenta},
    urlcolor             = {blue},
    citecolor            = {cyan},
    filecolor            = {black},
    colorlinks           = {true},  % no longer causes Missing } inserted
}

% no longer causes Missing } inserted
\usepackage{pgfornament}
\usepackage{tikzsymbols}
\usepackage{xcolor}
\usepackage{tikz}

% for testing
\def\shortlipsum{\par Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.\par}
\newcounter{entryno}
\setcounter{entryno}{1}
\def\tabline{Test & \the\value{entryno} & Description\addtocounter{entryno}{1}\\}
\def\tablines{\tabline\tabline\tabline\tabline}


% patch multicols to allow for one column
% SEE https://tex.stackexchange.com/questions/233866/one-column-multicol-environment
\let\multicolmulticols\multicols
\let\endmulticolmulticols\endmulticols
\RenewDocumentEnvironment{multicols}{mO{}}
{%
    \ifnum#1=1
    #2%
    \else % More than 1 column
    \multicolmulticols{#1}[#2]
    \fi
}
{%
    \ifnum#1=1
    \else % More than 1 column
    \endmulticolmulticols
    \fi
}

% temporary box for multicols
\newsavebox\ltmcbox

% copy the working commands below into an environment
\NewDocumentEnvironment{myenvironment}{O{2}}
{
    \begin{multicols}{#1}
    \setbox\ltmcbox\vbox\bgroup
    \makeatletter\col@number\@ne
    \begin{longtable}{|l|l|l|}
}
{
    \end{longtable}
    \unskip
    \unpenalty
    \unpenalty
    \egroup
    \unvbox\ltmcbox
    \end{multicols}
}


\begin{document}

\shortlipsum

\begin{multicols}{2}
    \setbox\ltmcbox\vbox{
        \makeatletter\col@number\@ne
        \begin{longtable}{|l|l|l|}
            \tablines\tablines
        \end{longtable}
        \unskip
        \unpenalty
        \unpenalty
    }
    \unvbox\ltmcbox
\end{multicols}

\shortlipsum

\begin{multicols}{1}
    \setbox\ltmcbox\vbox{
        \makeatletter\col@number\@ne
        \begin{longtable}{|l|l|l|}
            \tablines\tablines
        \end{longtable}
        \unskip
        \unpenalty
        \unpenalty
    }
    \unvbox\ltmcbox
\end{multicols}

\shortlipsum

\begin{myenvironment}
    \tablines\tablines
\end{myenvironment}

\shortlipsum

\end{document}

other considerations

supertabular

this answer multicolumn-long-table-or-enumeration tricks a supertabular into working in a multicol but I would like the tabular-like data to be on one page, in between text

tabbing

might work but

  • my tests so far don't balance well per row or center it horizontally
  • I was looking to have formatting per colum like in a tabular
  • I was looking for the column widths to be calculated by LaTeX

enter image description here

\documentclass[]{book}
\usepackage{xparse}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage[%
showframe,%
twoside,%
top=0.5in,%
bottom=0.5in,%
marginparsep=3ex,%
marginparwidth=0.8in,%
inner=0.5in,%
outer=1.25in,%
]{geometry}
\geometry{
    papersize={6in,3in}
}

\def\shortlipsum{\par Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.\par}

\def\entry{9000 \> Watt \> Power\\}

\usepackage{pgfornament}
\usepackage{tikzsymbols}
\usepackage{xcolor}
\usepackage{tikz}

\NewDocumentEnvironment{myenvironment}{O{2}}
{
\centering
\begin{multicols}{2}
\begin{tabbing}
\hskip4em \= \hskip4em \= \hskip16em \kill
}
{
\end{tabbing}
\end{multicols}
\par
}


\begin{document}

\shortlipsum

\begin{myenvironment}
\entry
\entry
\entry
\entry
\entry
\entry
\entry
\entry
\end{myenvironment}

\shortlipsum

\end{document}

list

A list might work

  • but I wanted more than two columns
  • my experiments so far don't align it well

enter image description here

\documentclass[]{book}
\usepackage{xparse}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage[%
showframe,%
twoside,%
top=0.5in,%
bottom=0.5in,%
marginparsep=3ex,%
marginparwidth=0.8in,%
inner=0.5in,%
outer=1.25in,%
]{geometry}
\geometry{
    papersize={6in,3in}
}

\def\shortlipsum{\par Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.\par}


\usepackage{pgfornament}
\usepackage{tikzsymbols}
\usepackage{xcolor}
\usepackage{tikz}


\begin{document}
    
    \shortlipsum
    
    
    \newcommand{\entry}[2]{
        \item[#1] #2
    }
    
    \begin{multicols}{2}
        \centering
        \begin{description}
            \entry{1}{2}
            \entry{1}{2}
            \entry{1}{2}
            \entry{1}{2}
            \entry{1}{2}
            \entry{1}{2}
            \entry{1}{2}
        \end{description}
    \end{multicols}
    
    \shortlipsum
    
\end{document}

0

You must log in to answer this question.

Browse other questions tagged .