LaTeX: Prevent line break in a span of text

后端 未结 5 1358
离开以前
离开以前 2021-01-30 06:07

How can I prevent LaTeX from inserting linebreaks in my \\texttt{...} or \\url{...} text regions? There\'s no spaces inside I can replace with ~

相关标签:
5条回答
  • 2021-01-30 06:21

    Use \nolinebreak

    \nolinebreak[number]

    The \nolinebreak command prevents LaTeX from breaking the current line at the point of the command. With the optional argument, number, you can convert the \nolinebreak command from a demand to a request. The number must be a number from 0 to 4. The higher the number, the more insistent the request is.

    Source: http://www.personal.ceu.hu/tex/breaking.htm#nolinebreak

    0 讨论(0)
  • 2021-01-30 06:31

    Surround it with an \mbox{}

    0 讨论(0)
  • 2021-01-30 06:32

    Define myurl command:

    
    \def\myurl{\hfil\penalty 100 \hfilneg \hbox}
    
    I don't want to cause line overflows, 
    I'd just rather LaTeX insert linebreaks before 
    \myurl{\tt http://stackoverflow.com/questions/1012799/} 
    regions rather than inside them.
    
    
    0 讨论(0)
  • 2021-01-30 06:38

    \mbox is the simplest answer. Regarding the update:

    TeX prefers overlong lines to adding too much space between words on a line; I think the idea is that you will notice the lines that extend into the margin (and the black boxes it inserts after such lines), and will have a chance to revise the contents, whereas if there was too much space, you might not notice it.

    Use \sloppy or \begin{sloppypar}...\end{sloppypar} to adjust this behavior, at least a little. Another possibility is \raggedright (or \begin{raggedright}...\end{raggedright}).

    0 讨论(0)
  • 2021-01-30 06:38

    Also, if you have two subsequent words in regular text and you want to avoid a line break between them, you can use the ~ character.

    For example:

    As we can see in Fig.~\ref{BlaBla}, there is nothing interesting to see. A~better place..
    

    This can ensure that you don't have a line starting with a figure number (without the Fig. part) or with an uppercase A.

    0 讨论(0)
提交回复
热议问题