I have code that generates multiple lists of data in the form of XeLaTeX source. Because the lines of data are very short, I'm presenting it in a multicols
environment. Each list has a few headings in it. Occasionally the list of data is very short – just a single heading and one line of data – and in this case, I'm struggling to prevent the heading and following line from being split across columns. Here's a MWE showing the problem and my attempt to fix it using \needspace
:
\documentclass[a4paper]{article}
\usepackage{multicol}
\usepackage{needspace}
\newcommand{\tblheading}[1]{\needspace{2\baselineskip}\textbf{#1}\newline}
\begin{document}
\begin{multicols}{3}
\tblheading{Heading}
Entry
\end{multicols}
\end{document}
I've tried using \Needspace*
instead of \needspace
, I've also tried adding \raggedcolumns
, increasing the requested space from 2\baselineskip
, and using \par
, \\
or \\*
instead of \newline
, but whatever I try, I cannot prevent these two lines from being split between two columns. Can anyone help?
(I know that in principle I could use a minipage
or perhaps samepage
environment, but I don't think that's possible here because I really need to keep the special handling within the \tblheading
macro due to the way the data is generated.)
\section
,\subsection
, etc., as they're already in use in the document.scrartcl
as class and\minisec{Heading}
.scrartcl
breaks far too much, so that's not an option, though it does fix this particular problem. I've no idea what you mean when you say I can define more commands line\subsection
. Isn't that what I've done? Presumably I've missed something relevant from my definition of\tblheading
, but I don't know what – that's why I've posted the question.