4

I have some captions in the margin with very short lines and I don't like the way LaTeX hyphenation algorithm breaks them. Here is an example of the outcome I get letting LaTeX do the job (of course I set babel to use the Italian hyphen rules):

enter image description here

And here is an outcome closer to what I would like to obtain:

enter image description here

(which I obtained by manually introducing breaks, boxes and space reductions).

Here is a MWE producing the output:

\documentclass[10pt,a4paper]{minimal}
\usepackage[italian]{babel}
\begin{document}

\begin{minipage}{2.95cm}\sffamily\itshape
\textbf{fig. 13.3.} Il flusso dei pagamenti nelle tre fasi di produzione, vendita all'ingrosso e al dettaglio
\end{minipage}

\vspace{1cm}

\begin{minipage}{2.95cm}\sffamily\itshape
\textbf{fig. 13.3.} Il flusso dei \mbox{pagamenti nelle} tre fasi di produzio\-ne, vendita all'in\-grosso e al dettaglio
\end{minipage}

\vspace{1cm}

\begin{minipage}{2.95cm}\sffamily\itshape
\textbf{fig.\,13.3.\!} Il\! \mbox{flusso\! dei} pagamenti nelle tre fasi di pro\-duzione, vendita all'in\-grosso e al dettaglio
\end{minipage}

\end{document}

My question: Is there a way to instruct LaTeX to allow more breaks, and possibly narrow inter-word space when necessary, in order to avoid too much space between words?

5
  • 6
    Not without a more detailed example…
    – egreg
    Commented Feb 9, 2023 at 14:41
  • Sorry I did not provide a MWE, but my questions is simple and general: is there a way to set a penalty for word spacing that balances the penalty for (too many, possibly consecutive) hyphenation breaks?
    – Massimo
    Commented Feb 9, 2023 at 14:51
  • 4
    No MWE, no answer, sorry. The details are important.
    – egreg
    Commented Feb 9, 2023 at 15:17
  • Ok, I put a MWE, which is not the same as my document but produces the same results
    – Massimo
    Commented Feb 9, 2023 at 15:35
  • 1
    if you use lualatex you can us custom patterns with more breakpoints, for other engines you would need a new language, or you scan at the macro layer and add breakpoints, as you would for long strings eg dna sequences or url Commented Feb 9, 2023 at 16:12

3 Answers 3

8

Rather than add more hyphenation points you could let spaces be tighter and more variable, and use microtype.

enter image description here

\documentclass[10pt,a4paper]{article}
\usepackage[italian]{babel}
\usepackage{microtype}
\begin{document}

\begin{minipage}{2.95cm}\sffamily\itshape
\spaceskip.25em plus .3em minus .1em
\xspaceskip.3em plus .3em minus .2em
\textbf{fig. 13.3.} Il flusso dei pagamenti nelle tre fasi di produzione, vendita all'ingrosso e al dettaglio
\end{minipage}

\end{document}
5

The label fig. 13.3 should be boxed and the space in it should not be allowed to stretch.

If I do this, TeX is perfectly happy to use several hyphenations in sequence.

It would be best if also the space after the label is not allowed to stretch, but this depends on the text; here there are three short words and the last one cannot be hyphenated.

I get underfull boxes in any case, but that's normal when typesetting in narrow columns.

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}

\begin{document}

% original
\begin{minipage}{2.95cm}\sffamily\itshape
\textbf{fig. 13.3.} Il flusso dei pagamenti nelle tre fasi di produzione, 
vendita all'ingrosso e al dettaglio
\end{minipage}

\vspace{1cm}

% better version
\begin{minipage}{2.95cm}\sffamily\itshape
\mbox{\textbf{fig.~13.3.}} Il flusso dei pagamenti nelle tre fasi di 
produzione, vendita all'ingrosso e al dettaglio
\end{minipage}

\vspace{1cm}

% not so good :-(
\begin{minipage}{2.95cm}\sffamily\itshape
\mbox{\textbf{fig.~13.3.} }Il flusso dei pagamenti nelle tre fasi di 
produzione, vendita all'ingrosso e al dettaglio
\end{minipage}

\end{document}

enter image description here

I'd use microtype anyway. Here's the same code as before with \usepackage{microtype} (the badnesses are reduced).

enter image description here

Please, don't use the minimal class. It's not meant for examples of typesetting.

3
  • Thank you, In my main document (actually, a 600+ pages book with a very long style file) I use microtype and the label of caption is boxed, but still there are many cases where hyphenation is totally unsatisfactory. Sure it may depend on something else in my setup, but still I would like to know if there is way to tell LaTeX not to enlarge interword spaces so much when it can break words.
    – Massimo
    Commented Feb 9, 2023 at 16:25
  • 2
    @Massimo If it does, then it can't solve the issue with hyphenation. Such margin captions should, in my opinion, be in smaller type size and ragged right.
    – egreg
    Commented Feb 9, 2023 at 16:30
  • I agree, but I have to obey the publisher's guidelines (especially after I declared that with LaTeX I can replicate their format in all its aspects)
    – Massimo
    Commented Feb 10, 2023 at 0:49
3

When width of text is narrow, it's probably better to justify the text only on the left side. It's obtained with the \raggedright command. But \raggedright don't hyphenate words (see the second example). So we use \RaggedRight from the ragged2e package.

As noted by egreg on his answer, I have replaced your minimal document class by the article document class.

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage{ragged2e}
%\usepackage{microtype} % optional but can give better results on some cases.

\begin{document}

\begin{minipage}{2.95cm}\sffamily\itshape
\textbf{Fig. 13.3.} Il flusso dei pagamenti nelle tre fasi di produzione, 
vendita all'ingrosso e al dettaglio
\end{minipage}

\vspace{1cm}

% With \raggedright, but no hyphenation
\begin{minipage}{2.95cm}\sffamily\itshape\raggedright
\textbf{Fig. 13.3.} Il flusso dei pagamenti nelle tre fasi di produzione, 
vendita all'ingrosso e al dettaglio
\end{minipage}

\vspace{1cm}

% With \RaggedRight from ragged2e
\begin{minipage}{2.95cm}\sffamily\itshape\RaggedRight
\textbf{Fig. 13.3.} Il flusso dei pagamenti nelle tre fasi di produzione, 
vendita all'ingrosso e al dettaglio
\end{minipage}
\end{document}

Result:

enter image description here

1
  • Thank you. I agree with you (and egreg) that a ragged paragraph is much better in this case, but unfortunately I don't have full control on this issue, I have to stick to the publisher's guidelines.
    – Massimo
    Commented Feb 10, 2023 at 0:45

You must log in to answer this question.

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