[Tex/LaTex] Create n minipages side by side on the same line, fail informatively if there’s a minipage “spill”

minipage

I'm trying to create n minipages side by side on the same line. In the following example n is 6.

In the example below, the line below the section title is supposed to be displayed, roughly as

Column A    Column B     Column C     Column D    Column E    Column F

but instead it is displayed as

Column A    Column B     Column C     Column D    Column E
                         Column F

with the minipage containing Column F spilling over to the next line. I set each minipage's width to \xfp{0.99/6.0}, figuring that this would give me a "safety margin" in case 1.0/6.0 as a floating point converted to decimal is slightly bigger than 1/6.

So I have a few questions:

  • Why is the Column F minipage spilling over to the next line?
  • Is there a way to fix it so that the minipages are all on the same line?
  • Is there a way of expressing something kind of like a "constraint" where, in the event that a document with all the minipages on the same line cannot be produced, the document will fail to render with an error message?

Here is the full document.

% !TEX TS-program = lualatex

\documentclass[11pt]{article}

\usepackage[utf8]{inputenc}

\usepackage{geometry}
\geometry{a4paper}

\usepackage{graphicx}

\usepackage{calc}

\usepackage{xfp}

\title{Foo}
\author{Bar}

\begin{document}
\maketitle

\section{6 Minipages Spanning One Line}

\noindent\centering{
\begin{minipage}[t]{\fpeval{0.99 / 6.0} \linewidth}
Column A
\end{minipage} %
%
\begin{minipage}[t]{\fpeval{0.99 / 6.0} \linewidth}
Column B
\end{minipage} %
%
\begin{minipage}[t]{\fpeval{0.99 / 6.0} \linewidth}
Column C
\end{minipage} %
%
\begin{minipage}[t]{\fpeval{0.99 / 6.0} \linewidth}
Column D
\end{minipage} %
%
\begin{minipage}[t]{\fpeval{0.99 / 6.0} \linewidth}
Column E
\end{minipage} %
%
\begin{minipage}[t]{\fpeval{0.99 / 6.0} \linewidth}
Column F
\end{minipage} %
%
}
\end{document}

As far as I can tell the suggestions in the related questions (given below) mostly have to do with stray newlines between tables (which are commented out in my example) or involve non-trivial objects like tables or lists inside each of the minipages. Neither question talks about having your document fail to render in an informative way instead of having a table spill onto the next line.

I've also tried adding lines consisting only of \hfill % after each \end{minipage}, but without any success

Best Answer

This is not an answer to your question but an alternative proposal for side by side minipages. You can build them with a tcbraster or tcbitemize from tcolorbox.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{booktabs}

\newcommand{\mytab}[1][A]{\begin{tabular}{cc}
\toprule
\multicolumn{2}{c}{Column #1}\\
\midrule 
a & b\\ c & d\\
\bottomrule
\end{tabular}}

\begin{document}
\begin{tcbitemize}[enhanced, empty, size=tight, raster columns=6]
\tcbitem \mytab
\tcbitem \mytab[B]
\tcbitem \mytab[C]
\tcbitem \mytab[D]
\tcbitem \mytab[E]
\tcbitem \mytab[F]
\end{tcbitemize}
\end{document}

enter image description here