2

How do I stop the following title wrapping, so that it extends slightly into the margin instead? I don’t want to change the font size or squeeze the text.enter image description here

\documentclass{article}
\usepackage{lipsum}

\begin{document}
\section*{\raggedright A rather long title that I would prefer on one line}
\lipsum[2]
\end{document}
Roly
  • 4,221
  • 4
  • 26
  • 56
  • Did you try without the \raggedright command? – leandriis Jan 01 '20 at 19:24
  • Yes, I did. I used \raggedright in the MWE because proportional spacing doesn’t really make sense if I plan to ignore the right margin. – Roly Jan 01 '20 at 19:31
  • Reduce the verbosity level of title (e.g., "A rather long title."). The smaller text under the title is just to explain its meaning, so this practice is almost always less painful than destroy the layout of the document. – Fran Jan 02 '20 at 03:27
  • @Fran Changing the title of a document to fit the formatting sounds unlikely to be good advice. And I'm not sure what you're referring to when you say "the smaller text under the title". – Roly Jan 02 '20 at 13:18
  • 1
    @Roly I am referring, of course, to the content of the section :). Often the titles of whatever are ridiculously and unnecessarily long, but a good title must be brief, no self-explanatory. As the content must explain the title, when is possible choose a shorter version, most probably that will be is the best version. My advice is not to fit the content to a desired format , but the universal rule of thumb of "The good, if brief, is twice as good". – Fran Jan 02 '20 at 18:10

3 Answers3

4

I don't advise this, but you can make TeX think that the heading has 0pt width and everything else sticks out to the right using \rlap:

\documentclass{article}
\usepackage{lipsum}

\begin{document}
\section*{\rlap{A rather long title that I would prefer on one line}}
\lipsum[2]
\end{document}

enter image description here

Skillmon
  • 60,462
  • That looks nice and simple, thanks (and of course I recognise that this isn’t best pratice). – Roly Jan 01 '20 at 19:32
  • 3
    And it avoids an overfull hbox warning that you get with \mbox. –  Jan 01 '20 at 19:38
  • 2
    @Roly if you want to stick to more LaTeX-like syntax, instead of \rlap{<your title>} you could also use \makebox[0pt][l]{<your title>}, which would look the same and won't throw an overfull warning, too. – Skillmon Jan 02 '20 at 15:36
  • +1: And thanks for the help with the other question. – Dr. Manuel Kuehner Jan 04 '20 at 15:00
3

If pdftex may be used:

\documentclass{article}
\usepackage{lipsum}
\usepackage{microtype}

\begin{document}
\section*{\textls[-10]{A rather long title that I would prefer on one line}}
\lipsum[2]
\end{document}

Microtype's \textls sets letter-spacing correction. It has an optional argument. In our case, we use some negative value. In this case, contrary to two other solutions, our line is not too long.

enter image description here

3

You could place the argument of \section* in an \mbox:

enter image description here

Speaking for myself, I don't think that suppressing a line break is a good idea here. In its stead, I'd recommend re-writing (i.e., shortening) the argument of \section*.

\documentclass{article}
\begin{document}
\hrule % just to illustrate width of textblock
\section*{\mbox{A rather long title that I would prefer on one line}}
\hrule
\end{document}
Mico
  • 506,678
  • 1
    Thanks. Both \mbox and \rlap seem to do the trick, but \mbox feels slightly more idiomatic, so I’ve accepted this answer. – Roly Jan 01 '20 at 19:39