Dealing with widows in a multicol environment - latex

I have problems with dealing with widows within a multicols environment, that is, I have not managed to instruct LaTeX to remove the them.
This PDF document shows an example of the problem. At the top of the second page, I get a widow from the last paragraph of the first page. I have tried a couple of approaches, without luck:
setting both \widowpenalty and \clubpenalty to high values
switching between \raggedcolumns and \flushcolumns
adjusting the collectmore and unbalance counters
I've also read through the documentation for multicol but have not found anything useful.
Is there anything else I could try?
(The complete LaTeX document for the above example)

{\obeyspaces\gdef\nomorebreak{\beginnomorebreak\let \nobreakspace}}
\def\beginnomorebreak{\begingroup
\def\par{\endgraf\endgroup\par\penalty 9999 }\obeyspaces
\brokenpenalty 10000 \widowpenalty 10000 \clubpenalty 10000 }
\def\nobreakspace{\vadjust{\nobreak} \removespaces}
\def\removespaces{\futurelet\next\checkspace}
\def\checkspace{\ifx\next\nobreakspace\expandafter\removesinglespace\fi}
\def\removesinglespace#1{\removespaces}
Insert \nomorebreak at any place of your paragraph. Page breaks will be prohibited after this macro until the end of the paragraph.

It seems that the TeX FAQ item Controlling widows and orphans has some options you did not try yet.
Getting rid of a widow can be more tricky. Options are
If the previous page contains a long paragraph with a short last line, it may be possible to set it “tight”: write \looseness=-1
immediately after the last word of the paragraph.
If that doesn’t work, adjusting the page size, using \enlargethispage{\baselineskip} to “add a line” to the page, which
may have the effect of getting the whole paragraph on one page.
Reducing the size of the page by \enlargethispage{-\baselineskip} may produce a (more-or-less) acceptable “two-line widow”.

Related

Auto page break in libHaru PDF

I'd like to add an automatic page break to a libHaru PDF in iOS.
I do have several text fields in the app which contain the user filled data. when i generate the pdf i first measure the expected size of the text-rect going to be created. if it exceeds the remaining space i trigger a hpdf_new_page event and put the text on an new page. i'd like to have this just in part automatically. so if the text exceeds the space on the current page it should split and continue on a new page without me checking or doing anything.
unfortunately i can't find anything like this in the documentation.
Line counting using fgets() may help. When your print program opens a file to print, each line can be copied to the pdf file and checked for a form feed character
or
if the line count has reached a limit.
Another possible solution is to use a character count limit with "while(getc(file) != EOF)".
This link uses libharu to print basic text files with PCL commands to change the font.
https://github.com/DaDaDadeo/GetCycle/blob/master/pcl_to_pdf.c
The form feed character '\f' (ascii 12) and 61 lines will trigger a new page. There are other conditions in the program to restrict a new page but the general idea is illustrated.
The results are the same as a printer using telnet raw 9100 protocol. The pcl commands are limited to just a couple of font changes so it is not too complicated.
Libharu is rather low-level library, and I could not even expect of appearing such automatic page splitting in newer versions due to number of reasons. Hereafter I state two of them:
There is no good, preferred strategy how to place remaining of non-fitting text on the next page. In some cases it could be even impossible at all.
There is no good, preferred strategy for text splitting.
Why?
Consider your font is extremely large, and just one letter (for instance, wide one as "W") does not fit into the page. Where we are supposed to place it? On the next page? Ok, we add new page... oops, it does not fit this page too - as soon as all our pages have the same size. Dead-end without any good, straightforward way out.
In other words, there should be a user-defined strategy for these cases. Almosy every naive implementation will have such a corner cases.
libharu does not know where it should split your text automatically. It does not know hyphenation rules of your language, it does not know whether it should respect spaces or not (wrap whole words only or not), and so on. It's up to you to specify these rules.
So, you should call HPDF_Font_MeasureText for some part of your text string, decide if it fits into your page (excluding margins, footers - which also out of libharu's internal knowledge) and render it. And note that there is no simple formula for text size depending on its length. String "wwww" is more than twice wider than "iiii", of course if your font is not mono-spaced.

Last-page column equalization for latex IEEEtran class?

In the documentation for the IEEEtran LaTeX class, it's mentioned that the two columns on the last page need to be manually adjusted in order to be balanced (have the same length).
I see that \newpage will allow me to break the first column so the rest of the content is on the second column. This allows for paragraph-level equalization, and looks good, but I'm having trouble with line-level equalization, that is, breaking the column by lines instead of by paragraphs.
When I insert \newpage in the middle of a paragraph (instead of between paragraphs), LaTeX effectively splits the paragraph in two. The second part goes to the top of the second column (as desired) and the first part remains in the first column. There are two issues I've found with this, and I've only solved one of them.
The first issue is that the partial paragraph on the top of the second column is treated by LaTeX as a new paragraph, so it's indented. I fixed this by adding \noindent after \newpage so that it's not indented.
The second issue is that for the partial paragraph in the first column, the paragraph is justified (as expected), but the last line is ragged (no justification). Is there a way to force justification of this last line? LaTeX has environments and commands to disable justification, but I can't find anything to fully justify a paragraph, including the last line.
Two possibilities:
Ending a line with \linebreak will force the line to be justified, no matter how empty it is.
To do what you are trying to do you could replace \newpage \noindent with \linebreak \newpage \noindent.
Note this will create a blank line before the end of the page, which may or may not be a problem. In certain cases it could create an empty page between your pages.
Another option would be \pagebreak. It tells LaTeX to start a new page when you get to the end of the current line. You don't have control of the exact word where the page break occurs.
What about making the last page (column) shorter using
\enlargethispage{-50mm}
and maybe forcing LaTeX to split after the appropriate line? Of course the amount of shortening should be guessed by trial and error, and re-guessed after changing the text. (Just an idea, may be impossible to implement in your case.)
(Posting for the googlers landing here)
The quickest solution is
\usepackage{pbalance}
(Package documentation at https://ctan.org/pkg/pbalance?lang=de)
In case that does not work, one can try the special command \IEEEtriggeratref{10}, which adds a column break before reference 10. Replace 10 by the actual number of the reference. See the documentation of IEEEtran, section "XIV. Last Page Column Equalization" for more details).
You can adjust the following lengths to make LaTeX fill the last line of a paragraph. Put this in your preamble:
\newcommand{\filllastline}[1]{
\setlength\leftskip{0pt}
\setlength\rightskip{0pt}
\setlength\parfillskip{0pt}
#1}
Then in your document do this:
\filllastline{The text for your partial para in 1st col goes here...}
(For future LaTeX questions you should probable post to https://tex.stackexchange.com/)

How to manually equalize columns in an IEEE paper if using BibTex?

IEEE conference publications in two-column format require authors to manually equalize the lengths of the columns on the last page of the final submission. I have typically done this by inserting a \newpage where necessary -- which usually ends up being somewhere amidst my (manually entered) references.
However, I have recently begun using BibTeX to manage references, and have now run into a problem: my last page contains only a few (generated) references, and I can't figure out how to manually equalize the columns.
The last page is the tail end of what is generated by:
\bibliographystyle{IEEEtran}
\bibliography{IEEEabrv,library}
Any ideas on how I can equalize the columns while continuing to use BibTeX?
I have submitted to both ACM and IEEE conferences and the easiest thing for me has been using:
\usepackage{flushend}
I've heard it doesn't always work well, but it's been great for me
http://www.ctan.org/pkg/flushend
I went back to RTFM again, and it turns out this is addressed right in "How to Use the IEEEtran LaTeX Class" by Michael Shell (maintainer). Section XIV notes that IEEEtran helpfully provides the \IEEEtriggeratref{} command for just this purpose. By default, it fires a \newline at the given BibTeX reference number. You can even change the command to fire with \IEEEtriggercmd{}.
It can also be done by using the balance package. You simply include the balance package in the preamble (\usepackage{balance}) and insert \balance some place on the last page of your document (for instance right in front of the references). However, I'm not sure if it's working if the last page (both columns) is completely full of references...
IEEE requires authors to equalize the lengths of the columns on the last page.
ACM makes us do this too. I just wind up inserting \vfill\break by hand either in the main text or somewhere in the .bbl file, wherever it makes the columns balance. By the time camera-ready copy goes to ACM, they want the .bbl file inlined by hand anyway, so tinkering by hand does not present an additional hardship.
The reference-number trick might be nice except I never use numbered references :-)
The multicols environment works only if you're luck and your last page comes out exactly as bibliography.
It would be extremely good (and not so difficult) if some enterprising hacker would build the "balance the two columns in the last page" functionality straight into LateX's \output routine. The flexibility is there in the underlying engine, and it would make a lot of people happy.
Not sure if multicol conflicts with bibtex at all, and I don't have time to check, sorry. But try this:
use the multicol package:
\usepackage{multicol} in your preamble, then:
\begin{multicols}{2}
\bibliographystyle{IEEEtran}
\bibliography{IEEEabrv,library}
\end{multicols}
Multicol automatically balances columns. I would recomend using it through out your document, instead of using the .cls or .sty's twocolumn option.

Why does LaTeX "Table of Contents" leave gaps for missing items?

I have set tocdepth to a lower number, so that other subsections are not included in the list. But instead of just removing these items, LaTeX leaves a gap. How does it happen? How could it be prevented?
We need details, including the document class, the exact tocdepth number, and the set of section headings actually used in your document. Two hypotheses:
You have not run LaTeX enough times for the TOC to stablize—possible but unlikely.
You have set the tocdepth to 1, and the document class you are using deliberately puts extra space between level 1 headings (\sections)—slightly more likely.
The table of contents may include a stretchable space in between each of the entries. If the style allows it, put a \vfill after the \tableofcontents but before any \newpages, and see if that makes a difference.
Usually I recommend one of the titletoc or tocloft packages to format ToC entries.
I can heartily recommend the memoir document class, which I use for everything from poetry to business cards. I'm very, very happy with the investment I made to learn it, even though it wasn't negligible.
In particular, to tinker at your TOC entry formatting, search for \cftbeforeKskip in memman.pdf.
The final solution will probably look something like this:
\setlength{\cftbeforechapterskip}{0pt}
or
\setlength{\cftbeforesectionskip}{0pt}
etc... (depending on which level of entry you want to adjust)

Is there a way to prevent LaTeX from splitting long footnotes across multiple column/pages?

I am using LaTeX and in some cases have multiline footnotes.
When I use a two-column format and especially when the reference to a footnote is low in the column, LaTeX will often split the footnote in half: it starts in the original column, but then continues under another column (sometimes in another page), which is very distracting.
Is there a way to force LaTeX to never split footnotes and allocate enough space for them?
Use \interfootnotelinepenalty=10000 to totally disallow this. But be prepared for other layout artifacts... Setting the penalty lower than 10000 will give TeX some flexibility in deciding when the side effects are too bad to bear.
For a detailed discussion see the TeX FAQ item Why does LaTeX split footnotes across pages?
I've found that it's best to get the style sheet from where you're trying to publish, and just use their format (I'm assuming you're trying to publish somewhere, if you're using a double-column format). The editors can then handle wacky footnoting. If it's for a thesis, I don't know about your committee, but mine has told me that a single column, double-spaced is the way to go, which should avoid your problem in the first place.

Resources