3

First of all, full disclosure: this is my first question on this site, so apologizes in advance.

The Problem: I would like to have a Latex command that accepts two documents and presents them in the following way. The two pieces of text should proceed side by side (in a two-column fashion) and then switch to one column again for whichever of the two comes out to be longer. Note that the two texts can be quite long and indeed span multiple pages. I have access to the two input documents, but I would like to modify them as little as possible, ideally the solution should not alter them at all.

Incredibly realistic sketch of the solution.

+-----------------+
|   Shared Title  |
+--------+--------+
|        |        |
|        |        |
|  Left  |  Right |
|  Text  |  Text  |
|        |        |
|        |        |
|        |        |
+--------+--------+
    ~pagebreak~ 
+--------+--------+
|  Left  |  Right |
|  Text  |  Text  |
|        +--------|
|                 |
|  Trailing End   |
|  of Left Text   |
+--------+--------+

What I got so far: Thanks to questions such as this one I was able to position the two texts side by side with the following code.

\newcommand{\sidebyside}[2]
{
    \begin{paracol}{2}
    \begin{tcolorbox}[blanker, breakable, width=\linewidth]
        #1
    \end{tcolorbox}
    \switchcolumn
    \begin{tcolorbox}[blanker, breakable, width=\linewidth]
        #2
    \end{tcolorbox}
    \end{paracol}   
}

That I can later use in the document with a call such as:

\sidebyside{\input{left_text}}{\input{right_text}}

However with this setup whichever text comes up the longer will just keep going in its own column, while I would like it to break the two-column layout and proceed using the whole page. The idea I had was to modify the previous command to only print part of one of the two inputs to match its length to the shortest, like the following:

\newcommand{\sidebyside}[2]
{
    % Somehow measure which of #1 and #2 is longer
    \begin{paracol}{2}
    \begin{tcolorbox}[blanker, breakable, width=\linewidth]
        % Part of #1 with length matched to #2
    \end{tcolorbox}
    \switchcolumn
    \begin{tcolorbox}[blanker, breakable, width=\linewidth]
        % Part of #2 with length matched to #1
    \end{tcolorbox}
    \end{paracol}
% Put here the remaining trail of either #1 and #2

}

The main sub-problems that I am facing are: "How to measure which of the two inputs is longer?", "How to print only part of and input given its target length?".

The approach I depicted above may be doomed to fail, so I am open to any solution. I am using Overleaf as part of online collaboration.

myscience
  • 31
  • 1
  • 1
    getting wider at the end makes it quite a bit harder, especially if you want to do it in one pass. Also it's a lot harder if you want the width to change mid-paragraph, is that a requirement or can you finish the longer column at teh end of a paragraph? – David Carlisle Jan 02 '22 at 11:34
  • I think finishing the longer column at the end of a paragraph works just fine. In case of a too-long-a-paragraph I can for example edit the longer text and insert manually a paragraph break if needed. – myscience Jan 02 '22 at 11:39
  • If you only need this a few times, maybe splitting the larger input file manually and inserting the rest separately might be the easiest solution. – marv Jan 02 '22 at 11:48

0 Answers0