8

I'm trying to create a new command that will give blue underline under black text. My mwe is

\documentclass[a4paper,12pt]{report}
\usepackage[table,hyperref,dvipsnames]{xcolor}
\usepackage{ulem}
\newcommand{\coline}{\subsection{\textcolor{blue!80!black}\uline}} 
\begin{document}

\coline{the cat sat on the mat}
\end{document}

but its failing saying

! Argument of \UL@on has an extra }.
<inserted text> 
                \par 
l.11 \coline
            {the cat sat on the mat}
? 

I'm using xelatex to process it. How can I get it working please?

I've just tried this, but its still not working.

\newcommand{\coline}{\textcolor{blue!80!black}\uline{\subsection}} 
0

4 Answers 4

9

It is \textcolor{color}{argument} and also \uline{argument} Here you have none of the arguments so the macros are picking up whatever they can find as arguments.

\documentclass[a4paper,12pt]{report}
\usepackage[table,hyperref,dvipsnames]{xcolor}
\usepackage{ulem}
\newcommand{\coline}[1]{\subsection{\textcolor{blue!80!black}{\uline{#1}}}}
\begin{document}
\chapter{}
\section{}

\coline{the cat sat on the mat}
\end{document}

enter image description here

2
  • Nearly there, except I'm wanting a blue underline under black text. Thanks.
    – boudiccas
    Commented Mar 17, 2015 at 19:32
  • @boudiccas Check the manual of ulem for coloring the underline or the check the definition of \reduline
    – percusse
    Commented Mar 17, 2015 at 19:35
3

For fun, here is a censor alternative, with a little hack.

\documentclass{article}
\usepackage{censor,xcolor}
%%%%%%%%%%%
\censorruleheight=.1ex %THICKNESS OF CENSOR RULE
\newlength\nextcharwidth
\makeatletter
\renewcommand\@cenword[1]{%
  \setlength{\nextcharwidth}{\widthof{#1}}%
  \textcolor{\ulinecolor}{\censorrule{\nextcharwidth}}%
  \kern -\nextcharwidth%
  \textcolor{black}{#1}}
\makeatother
\newcommand\couline[2][black]{%
  \def\ulinecolor{#1}%
  \censorruledepth=-.67ex\relax\color{#1}\xblackout{#2}\color{black}%
}
\newcommand\coline[2][blue!80!black]{\subsection{\protect\couline[#1]{#2}}}
%%%%%%%%%%%

\begin{document}
\coline{the cat sat on the mat}

Now I will test a multiline title

\coline[red]{the cat sat on the mat the cat sat on the mat the cat sat on the mat}

\large\couline[cyan]{the very large cat indeed sat on the mat. Once upon a 
time, the cat sat on the mat the cat sat on the mat}
\end{document}

enter image description here

2

From the ulem package manual, assuming your normal text is black, place this in the preamble:

\usepackage[normalem]{ulem}
\newcommand\blueuline{\bgroup\markoverwith{\textcolor{blue}{\rule[-0.75ex]{2pt}{1.5pt}}}\ULon}

You may need to adjust the parameters of \rule visually.

\documentclass{standalone}

\usepackage{xcolor}
\usepackage[normalem]{ulem}
\newcommand{\blueuline}{\bgroup\markoverwith{\textcolor{blue}{\rule[-0.75ex]{2pt}{1.5pt}}}\ULon}

\begin{document}
Here is some text. \blueuline{Here is some underlined text}
\end{document}

enter image description here

1

You can use Hugh's code in titlesec to make subsections look as you want. Here is how.

\documentclass[a4paper,12pt]{report}
\usepackage[table,hyperref,dvipsnames]{xcolor}
\usepackage[normalem]{ulem}
\newcommand{\blueuline}{\bgroup\markoverwith{\textcolor{blue}{\rule[-0.75ex]{2pt}{1.5pt}}}\ULon}

\usepackage{titlesec}
\newcommand{\mysec}[1]{\blueuline{#1}}

\titleformat{\subsection}
{\normalfont\large\bfseries}{\thesubsection}{1em}{\mysec}

\begin{document}
\chapter{}
\section{}
\subsection{Here is some text Here is some text Here is some text Here is some text Here is some text}
\end{document}

enter image description here

You must log in to answer this question.

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