LaTeX forum ⇒ Graphics, Figures & TablesColoured 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

Postby tarasm » Sun May 29, 2022 1:24 am

Hello,

I am trying to achieve the following in LaTeX:

Image

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.

Thanks in advance

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook
rais
Posts: 332
Joined: Sun Nov 16, 2014 8:51 pm

Coloured bars under and below parts of words  Topic is solved

Postby rais » Sun May 29, 2022 9:42 am

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

Postby tarasm » Sun May 29, 2022 12:28 pm

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

Best Regards,
T


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 6 guests