0

in my article template a part of the text is set in twocolumn mode. I'm using multicol package with the starred environment (to fill up one column after antoher).

The twocolumn article part consists of different sections of which some can be very short. E.g. the \listoffigues and the author names and adresses shall be printed there.

Since most of the content is predefined in the praeambel or within the structure of the article, be it through the number of figures used or the number of authors of an article, I want to automate the typesetting process.

Therefore, i need following behaviour:

  • If the content of the first section (let say the list of figures) is only a few lines, maximum up to the middle of the page, the following section should be placed directly afterwards in the same column. (first page of image below)
  • But if the content of the first section stretches over the middle of the page, the following section should start at the next column. (second page of image below)

enter image description here

Of course, if I typeset any article individual I can get this result in inserting a \newcolumn after the each short section manually.

But I would like to automise this step. Is there a possibility to create, for example, an if-condition which says something like:

if "previous section" starts at topline and is shorter than \textheight; then
    insert \newcolumn

I would prefer an expl3 solution and have already skimmed over the interface3 manual, but, so far, couldn't find a fitting solution. This may be due to my lack of experience with Latex if-conditions and expl3. But I'm very willing to learn.

Here my MWE:

\documentclass[%
twoside,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{noto}

\usepackage{geometry} \geometry{% inner=20mm, outer=60mm, top=15mm, bottom=20mm, marginparwidth=40.5mm, marginparsep=4.5mm, showframe % to show the margins }

\usepackage{multicol}

% Put a line in the middle of text height for testing \usepackage{atbegshi,picture} \AtBeginShipout{% \AtBeginShipoutUpperLeft{% \put(0,\dimexpr-\topmargin-1in % -\headheight-\headsep -.5\textheight\relax){% \line(1,0){\paperwidth}% }% }% }

\usepackage{blindtext}

\begin{document} \section{Section} \blindtext[5] \newpage \begin{multicols*}{2} \section{Section}
\blindtext[2] \section{Section} \blindtext[3]

    \newpage
    \section{Section}       
    \blindtext[1]
    \section{Section}
    \blindtext[2]

    \newpage
    \section{Section}       
    \blindtext[2]
    \newcolumn
    \section{Section}
    \blindtext[2]
\end{multicols*}

\end{document}

Thanks

lukeflo
  • 1,555

1 Answers1

0

After some more reading, since I had a day off, I figured out a solution. Which is working quite fine.

It uses a parbox to measure the height of the wanted text area and compares it with half the textheight. If the measured text is longer than half the textheight, a \newcolumn will be inserted to push the following text to the next column:

\documentclass[%
twoside,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{noto}

\usepackage{geometry} \geometry{% inner=20mm, outer=37.5mm, top=15mm, bottom=20mm, marginparwidth=18mm, marginparsep=4.5mm, showframe % to show the margins }

\usepackage{multicol}

% Put a line in the middle of text height for testing \usepackage{atbegshi,picture} \AtBeginShipout{% \AtBeginShipoutUpperLeft{% \put(0,\dimexpr-\topmargin-1in % -\headheight-\headsep -.5\textheight\relax){% \line(1,0){\paperwidth}% }% }% }

\usepackage{blindtext}

\newlength{\metaheight}

\newcommand{\testheight}[1]{% \settoheight{\metaheight}{% \parbox[b]{\linewidth}{\selectfont\noindent#1}}% #1\par \the\metaheight% } \ExplSyntaxOn \NewDocumentCommand{\columntest}{}{% \int_compare:nNnTF {\int_to_arabic:n {\metaheight}} < {\int_to_arabic:n {\textheight/2}} {} {\newcolumn} } \NewDocumentCommand{\sectiontest}{m}{% \testheight{#1}\par \columntest } \ExplSyntaxOff

\setlength\parindent{0pt} \begin{document} \blindtext \newpage \begin{multicols*}{2}

    \section{Section}       
    \sectiontest{\blindtext[1]}

    \section{Section}
    \blindtext[3]

    \newpage

    \section{Section}       
    \sectiontest{\blindtext[2]}

    \section{Section}
    \blindtext[2]

\end{multicols*}

\end{document}

I tested it with different kinds of text, and so far, it works very good.

Of course, if some of the veterans have any idea to improve it, I will be glad to hear it.

lukeflo
  • 1,555