1

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}
5
  • Did you try without the \raggedright command? – leandriis Jan 1 '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 1 '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 2 '20 at 3: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 2 '20 at 13:18
  • @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 2 '20 at 18:10
1

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}
1
  • 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 1 '20 at 19:39
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

4
  • That looks nice and simple, thanks (and of course I recognise that this isn’t best pratice). – Roly Jan 1 '20 at 19:32
  • 3
    And it avoids an overfull hbox warning that you get with \mbox. – user194703 Jan 1 '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 2 '20 at 15:36
  • +1: And thanks for the help with the other question. – Dr. Manuel Kuehner Jan 4 '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

5
  • Thanks. Could you say something about what \textls actually does? – Roly Jan 1 '20 at 19:35
  • @Roly Is te extended answer enough for you? – Przemysław Scherwentke Jan 1 '20 at 19:43
  • Ah. That looks useful, but I don’t think it answers the question, which explicitly ruled out changing the letter spacing. – Roly Jan 1 '20 at 19:54
  • Incidentally, it looks like letter spacing also doesn’t work with XeTeX at the moment. – Roly Jan 1 '20 at 19:56
  • 1
    @Roly Only changing the font size or squizzing the text was prohibited. :-) – Przemysław Scherwentke Jan 1 '20 at 19:57

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.