3

I'm trying to highlight a footnote in a paper. However, using xcolor/colorbox seems to break the formatting, as the attached minimal example should illustrate. There must be a fix or alternative? (Just removing "\colorbox{yellow}" restores the correct formatting, but at the expense of the required highlighting, of course.)

\documentclass[12pt]{article}
\usepackage{xcolor}

\begin{document}

Hello world\footnote{\colorbox{yellow}{This is a highlighted footnote that is intended to occupy only one column, but which actually runs across -- and beyond -- two columns when highlighted using ``colorbox''.}}.

\end{document}

[In reality, the text is in two-column format, and the footnote also contains (natbib) references, which seems to break the soul package. But those observations are just for info, and incidental to the main problem.]

ionh
  • 75

2 Answers2

4

Without lualatex underlining and highlighting is a world of pain.

Use lua-ul and luacolor and your life will be much easier:

% TeX Program = lualatex
\documentclass[12pt]{article}
\usepackage{luacolor}
\usepackage{lua-ul}
\begin{document}
\null\vfill
Hello world\footnote{\highLight{This is a highlighted footnote that is
intended to occupy only one column, but which actually runs across -- and
beyond -- two columns when highlighted using ``colorbox''.}}.
\end{document}

output

David Purton
  • 25,884
  • I'd been locked in to pdflatex, but this worked nicely. Sorry i can't mark both your reply and anis' as an accepted answer, as your solution worked just as well as his. Thanks! – ionh Jan 03 '23 at 15:09
3

Why not use soul package and the command hl{}?

\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{soul}
\begin{document}
Hello world\footnote{\hl{This is a highlighted footnote
            that is intended to occupy only one column, but which actually
            runs across -- and beyond -- two columns when highlighted using
            ``colorbox''.}}.

\end{document}

Works with pdflatex

For the natbib ref, there is a solution see the comment below.

anis
  • 1,510
  • 5
  • 13
  • Take a look at this: https://tex.stackexchange.com/questions/139463/how-to-make-hl-highlighting-to-automatically-place-incompatible-commands-in , you need to add this in the preambule : \soulregister\cite7 to tell soul not to expand the argument when it is cite. – anis Jan 03 '23 at 13:25
  • Actually, i'd started with this solution, but soul had broken on two counts (the citations, and also a "\newcommand" text definition). However, your supplementary comment pointed me at what turns out to be the very straightforward workround of just putting problematical items into \mboxes. Thanks! – ionh Jan 03 '23 at 15:07
  • yes, you can basically do this : soulregister\anycommandthatyouwant7 . Finally, if you use any utf8 characters, there is the soulutf8 package. – anis Jan 03 '23 at 15:13