## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Coloured bars under and below parts of words Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
tarasm
Posts: 2
Joined: Sat May 28, 2022 6:56 pm

### Coloured bars under and below parts of words

Hello,

I am trying to achieve the following in LaTeX:

It's always some part of the word that has to be underlined, or overlined. the underlined/overlined length in characters always differs.

I'd like to type something like:

g\LOWERLINE{aa}tum y\LOWERLINE{a}jnaay\UPPERLINE{a}...

Can't figure out how to get this working.

LaTeXguide.org • LaTeX-Cookbook.net

rais
Posts: 332
Joined: Sun Nov 16, 2014 8:51 pm

### Coloured bars under and below parts of words  Topic is solved

Here's an idea:
\documentclass{article}
\usepackage{xcolor}
\newlength\mylinelength
\newlength\mylinethickness
\setlength\mylinethickness{2pt}
\newcommand*\LOWERLINE[2][cyan]{%
\settowidth\mylinelength{#2}%
\mbox{% this ensures the contents stay in one line
\makebox[0pt][l]{% this allows overprinting
\raisebox{-\mylinethickness}{% shift the rule below baseline
{\color{#1}\rule{\mylinelength}{\mylinethickness}}% the colored rule
}%
}%
#2%
}%
}%\LOWERLINE[color]{text}
\newcommand*\UPPERLINE[2][cyan]{%
\settowidth\mylinelength{#2}%
\mbox{% this ensures the contents stay in one line
\makebox[0pt][l]{% this allows overprinting
\raisebox{1.2ex}{% shift the rule above text
{\color{#1}\rule{\mylinelength}{\mylinethickness}}% the colored rule
}%
}%
#2%
}%
}%\UPPERLINE[color]{text}

\begin{document}
g\LOWERLINE{aa}tum y\LOWERLINE[red]{a}jnaay\UPPERLINE{a}...
\end{document}


May need some tweaking regarding rule positions, thickness, and color.

KR
Rainer

tarasm
Posts: 2
Joined: Sat May 28, 2022 6:56 pm

### Coloured bars under and below parts of words

Perfect! Thank you so much Rainer! And extra thanks for a prompt reply!

Best Regards,
T