0

In the file with two columns by twocolumn options, the last page can't be balanced by balance package if lineno package works.

\documentclass[twocolumn]{book}
\usepackage{lipsum,balance}
\usepackage[switch]{lineno}
\begin{document}    
\twocolumn[

\begin{@twocolumnfalse}
\chapter{the first}
\end{@twocolumnfalse}
]
\linenumbers
\lipsum[1-8]
balabala
\balance
\end{document}

produces:

enter image description here

Obvious, the last page is not balanced. So, how to balance the last page based on lineno working.


As pbalance would work in sometime, but when there are figures with figure* parameter, pbalance would be very difficult to be adjusted well.

\documentclass[twocolumn]{book}
\usepackage{lipsum,pbalance,stfloats,graphicx}
\usepackage[switch]{lineno}

%\shrinkLastPage{2.2in}

\begin{document}    
\twocolumn[

\begin{@twocolumnfalse}
\chapter{the first}
\end{@twocolumnfalse}
]
\linenumbers
\lipsum[1]
\par
\begin{figure*}[b]  
\centering
\includegraphics[width=0.4\textwidth]{example-image-a}
\end{figure*}
\lipsum[2-8]
balabala
\end{document}

produces:

enter image description here

11
  • Mittelbach's answer to this other question basically applies here too. For \balance to work it needs to install a new output routine; lineno also does its numbering by changing the output routine. The two are incompatible. You can see this immediately by thinking about the question of "where should the line number appear?" For lineno to decide whether to put the number on the left or on the right, it needs to know whether the text is in the left or the right column. But balance needs to set the text first before deciding ... Commented Jun 12, 2023 at 13:53
  • @WillieWong So, how to add line numbers outside the margin with balanced? Is there a way to do so?
    – Y. zeng
    Commented Jun 12, 2023 at 14:00
  • ... where to insert the column switch. A key problem being that lineno attaches the line numbers as they are set. So you end up with either lack of balancing, or what happens when you try to combine lineno and multicol (where the line numbers always show up on the same side). // So the answer is: "they can't work together, unless someone puts in the effort to write some code to make balance work with lineno explicitly." Commented Jun 12, 2023 at 14:01
  • @WillieWong No other packages can do this?
    – Y. zeng
    Commented Jun 12, 2023 at 14:07
  • Well, one way is to do it without any packages: in a "real" document, you can always typeset it first, count the number of lines, and insert an appropriate \newpage to force a column switch. I don't know about any "automatic" solutions to this problem. Commented Jun 12, 2023 at 14:13

1 Answer 1

3

You may want to try the pbalance package. Caveat: the author states that it is hackish and of beta quality, so it doesn't always work and sometimes the package would just give up; but it at least sort-of works on a test document.

Try 1

We begin by trying to follow the documentation and just loading pbalance, this gives us the test document

\documentclass[twocolumn]{book}
\usepackage{lipsum,pbalance}
\usepackage[switch]{lineno}
\begin{document}    
\twocolumn[

\begin{@twocolumnfalse}
\chapter{the first}
\end{@twocolumnfalse}
]
\linenumbers
\lipsum[1-8]
balabala
\end{document}

The output goes in the correct direction:

enter image description here

Try 2

The first try almost worked, but it looks like we can move another line from the left column to the right. According to the documentation, we can manually adjust this via \shrinkLastPage. So let's try eyeballing where the break should be. After some trial and error, I settled on 4.1in

\documentclass[twocolumn]{book}
\usepackage{lipsum,pbalance}
\usepackage[switch]{lineno}

\shrinkLastPage{4.1in}

\begin{document}    
\twocolumn[

\begin{@twocolumnfalse}
\chapter{the first}
\end{@twocolumnfalse}
]
\linenumbers
\lipsum[1-8]
balabala
\end{document}

And this time it is almost completely balanced.

enter image description here

Additional Caveats

Since you used the book document class, I am assuming eventually you want to use this to balance the last page of each individual chapter. As it currently stands, the pbalance package cannot do that.

However, the trick that it uses can be implemented manually, and may be easier to do than using \newpage as my comment suggested. Basically: after the content of the document has stabilized, compile your document first. Then issue \enlargethispage{<len>} where you would've put \balance (in the first column of the final page), with a negative length that you determine manually to get the two columns to balance. Repeat for each chapter.

3
  • Manually dealing with this is too difficult for me now. I am not so experienced to adjust these in LaTeX. As for your answers, I found another question, so I updated my question. If you have time, may you check that.
    – Y. zeng
    Commented Jun 12, 2023 at 14:44
  • Sorry, I don't think I can help more. Looking at the existing packages for balancing two column or multicolumn text, it is apparent that the problem is quite difficult programmatically. Commented Jun 12, 2023 at 14:53
  • Thanks a lot. You help me so much! I don't think it is quite difficult as it should be easier than tabularray. It is just not so important and essential that no one has thought deeply about this.
    – Y. zeng
    Commented Jun 12, 2023 at 14:56

Not the answer you're looking for? Browse other questions tagged .