3

This is not something I have encountered before and not sure which is the recommended way to hyphenate words with hyphens in them.

The MWE below yields two different results based on how the text is typeset. Note the beginning of the second line in each output:

enter image description here

Question:

  1. Main question is how do I make these two methods of typesetting text be consistent?
  2. Since we are on the topic, which is the "correct" output?

Code:

\documentclass{article}
\usepackage{enumitem}
\usepackage{tikz}

\usepackage{caption}
\captionsetup{margin=0pt,labelfont=sl}

\newlist{MyList*}{enumerate*}{1}%
\setlist[MyList*,1]{%
    label={\slshape Figure \arabic*:}, 
}%

\newcommand*{\TextWidth}{27.0em}

\newcommand*{\MyText}{%
    Some text to test hyphenation in words such as 
    left-and-right that already have dashes in them.%
}%

\begin{document}
\begin{tikzpicture}
    \node [draw=red, thick, align=justify, text width=\TextWidth] 
        {%
            \begin{MyList*}
                \item \MyText%
            \end{MyList*}%
        };
\end{tikzpicture}%

\fboxsep=1pt
\fbox{%
\begin{minipage}{\TextWidth}
    \captionof{figure}{\MyText}%
\end{minipage}%
}%
\end{document}
3
  • I've learned to divide hyphenated words at the hyphen, with this remaining in the first line. See also english.stackexchange.com/q/351806. The second version is therefore in my (non-native speaker!) opinion the correct one.
    – campa
    Nov 5, 2019 at 7:12
  • This is an artifact of enumerate* which does “boxing and unboxing".
    – egreg
    Nov 5, 2019 at 13:05
  • You can replicate it with \sbox0{x left-and-right}\begin{minipage}{0pt}\unhbox0\end{minipage}
    – egreg
    Nov 5, 2019 at 13:11

1 Answer 1

5

As pointed out by @egreg, the problem is enumerate*, and it's the result of two (IMO) misfeatures. The first one is the way TeX treats discretionaries when boxing text; the second one is enumitem sets mode=boxed by default. Two solutions, then.

  1. Either use luatex, which fixes how discretionaries behave in boxes.

  2. Or set mode=unboxed:

\setlist[MyList*,1]{%
  mode=unboxed,
  label={\slshape Figure \arabic*:}, 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.