16

I want to underline consecutive sentences each with a different color within an italic text. So far, I have tried the soul package and can change the underline properties. However, I am having difficulties changing the underline color in consecutive sentences within an italic text.

Consider the following: I want each of the \ul's have a different color.

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{color,soul}

    \begin{document}

    \setul{0.5ex}{0.3ex}
    \definecolor{Green}{rgb}{0,1,0}
    \setulcolor{Green}

    \setul{0.5ex}{0.3ex}
    \definecolor{Red}{rgb}{1,0.0,0.0}
    \setulcolor{Red}

    \setul{0.5ex}{0.3ex}
    \definecolor{Blue}{rgb}{0,0.0,1}
    \setulcolor{Blue}

    \Large
    \textit{
      Ham followed now ecstatic use speaking exercise may repeated.
      \ul{Himself he evident oh greatly my on inhabit general concern}. 
      \ul{It earnest amongst he showing females so improve in picture. 
      Mrs can hundred its greater account}. 
      \ul{Distrusts daughters certainly suspected convinced our 
      perpetual him yet.} Words did noise taken right state are since.
    }

    \end{document}

This is my desired output:

enter image description here

2 Answers 2

14

Similar to using \ul to set the underline, you can also change the colour using \setulcolor{<colour>} within \textit:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{color,soul}

\setul{0.5ex}{0.3ex}
\setulcolor{blue}

\begin{document}

\Large
\textit{
Ham followed now ecstatic use speaking exercise may repeated.
\ul{Himself he evident oh greatly my on inhabit general concern}. 
\setulcolor{red} 
\ul{It earnest amongst he showing females so improve in picture. 
Mrs can hundred its greater account}. 
\setulcolor{green}
\ul{Distrusts daughters certainly suspected convinced our 
perpetual him yet.} Words did noise taken right state are since.
}

\end{document}
3
  • 5
    Nice answer thanks. Now setulcolor must be incompatible with some packages, as your template worked for me but not when inserted in a larger project. However, I didn't need the color, so I'm not going to investigate. Just mentioning it in passing.
    – PatrickT
    Commented Oct 10, 2017 at 21:12
  • To use with beamer, check tex.stackexchange.com/questions/41683 Commented Mar 13, 2021 at 13:53
  • 2
    @PatrickT I had the same problem when using it setulcolor with a given external documentclass. My workaround was {\color{red} \underline{\color{blue} test}}.
    – Karlo
    Commented Apr 1, 2023 at 23:47
2
\documentclass[a4paper,12pt]{article}

\usepackage[utf8]{inputenc}

\usepackage{soul}

\usepackage[dvipsnames]{xcolor} % for expanded colour set

\setul{0.5ex}{0.3ex}

\newcommand{\ulcolor}[2][Red]{\setulcolor{#1}\ul{#2}}

%opening

\title{Underlining in several colours}

\author{LaTex Dude}

\begin{document}

\Large

\textit{
Ham followed now ecstatic use speaking exercise may repeated.
\ulcolor[Blue]{Himself he evident oh greatly my on inhabit general concern}.  
\ulcolor{It earnest amongst he showing females so improve in picture. 
Mrs can hundred its greater account}. 
\ulcolor[Green]{Distrusts daughters certainly suspected convinced our 
perpetual him yet.} Words did noise taken right state are since.
}

I would like to underline this \ulcolor{in red} and this \ulcolor[Blue]{in blue} and this \ulcolor[Green]{in green}. 
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .