6

I was trying to emphasize text with \textbf, \textit and \underline commands. But the text will not automatically wrap to the next line. I also tried the ulem package, and it did not work too. Does anybody know how to have italic, bold, underline and linebreaks for some text?

  • Could you please post a Minimum Working Example demonstrating the problem? It is much easier for people to help if you provide some code they can just copy-paste-and-compile to reproduce the problem you are seeing. – cfr Jan 06 '14 at 02:42
  • \usepackage{soul} and then \ul{\textbf{\textit{your text here}}}. – jon Jan 06 '14 at 02:42
  • 4
    You are not really doing all three at the same time, are you? That may draw attention to the text but it will also render it extremely difficult to read, as well as looking rather ugly. – cfr Jan 06 '14 at 02:46
  • I am working on some special documentations requiring all the three together. I must find a way to work it out. :( – Zhou Wang Jan 06 '14 at 03:24

2 Answers2

9

Do the following self explanatory combinations work for you? (Leaving aside aesthetic issues.)

\documentclass{article}

\usepackage{ulem}

\begin{document}

I think computer \uline{viruses should count as life. I think it says
something about human nature} that the only form of life we have
created so far is purely destructive. We've created life in our own
image. 

I think computer \uline{viruses should \textit{count as life. I think
    it} says something about human nature} that the only form of life
we have created so far is purely destructive. We've created life in
our own image.

I think computer \uline{\textit{viruses should count as life. I think
    it} says something about human nature} that the only form of life
we have created so far is purely destructive. We've created life in
our own image.

I think computer \uline{\textit{viruses should count \textbf{as
      life. I think} it} says something \textbf{about human} nature}
that the only form of life we have created so far is purely
destructive. We've created life in our own image.


\textit{\textbf{\uline{I think computer viruses should count as
      life. I think it says something about human nature that the only
      form of life we have created so far is purely destructive. We've
      created life in our own image.}}}


\end{document}
\documentclass{article}

\usepackage{ulem}

enter image description here


Tips

Always make \uline the last one to be applied when you need multiple effects on a complete paragraph. It behaves badly (no line wraps) when other font commands are applied after it.

Masroor
  • 17,842
  • Will that work if all three 'characteristics' span multiple lines? – jon Jan 06 '14 at 03:04
  • @jon Why not? See the updated example where all three have been applied to the last paragraph. – Masroor Jan 06 '14 at 03:12
  • @ZhouWang See the updated example, the last case. Always make \uline the last one to be applied. It behaves badly (no wraps) when other font commands are applied after it. This is what is happening in the above example in your comment. – Masroor Jan 06 '14 at 03:15
  • Yes, I got it. Thanks very much NMA. The problem is that I make the \uline the first one!!! Once I make the \uline the last one, it works perfect!!! – Zhou Wang Jan 06 '14 at 03:20
  • Indeed! I had never tried before and didn't realize ulem had such constraints about the order of usage. – jon Jan 06 '14 at 03:35
  • @jon Neither did I know about this constraint. Though I have been using ulem for more than ten years. – Masroor Jan 06 '14 at 03:38
3

It is probably better to stick with ulem if you are already using it. However, if I had to mix and match underline, bold, and italics, I'd be inclined to use soul instead. It does not need as much care about how you nest all these ways of emphasis.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{soul}
\parskip10pt
\parindent0pt
\begin{document}

% all at once:
\ul{\textbf{\textit{I was trying to emphasize text with textbf, textit
      and underline commands. But the text will not automatically wrap
      to the next line. I also tried the {ulem} package, and it did
      not work too. Does anybody know how to have italic, bold,
      underline and linebreaks for some text?}}}

% underline, then \emph, then bold
I think computer \ul{viruses \emph{should count \textbf{as life. I
      think it says something about human nature that the only form of
      life we have created so far is purely destructive. We've created
      life in} our} own} image.

% underline, bold, emph
I think computer \ul{viruses \textbf{should count \emph{as life. I
      think it says something about human nature that the only form of
      life we have created so far is purely destructive. We've created
      life in} our} own} image.

% bold, emph, underline
I think computer \textbf{viruses \emph{should count \ul{as life. I
      think it says something about human nature that the only form of
      life we have created so far is purely destructive. We've created
      life in} our} own} image.

% emph, bold, underline
I think computer \emph{viruses \textbf{should count \ul{as life. I
      think it says something about human nature that the only form of
      life we have created so far is purely destructive. We've created
      life in} our} own} image.

% bold, underline, emph
I think computer \textbf{viruses \ul{should count \emph{as life. I
      think it says something about human nature that the only form of
      life we have created so far is purely destructive. We've created
      life in} our} own} image.

% emph, underline, bold
I think computer \emph{viruses \ul{should count \textbf{as life. I
      think it says something about human nature that the only form of
      life we have created so far is purely destructive. We've created
      life in} our} own} image.

\end{document}
jon
  • 22,325