2

I couldn't find a question that answers this. I'm new to tex so I'm trying to figure out how the spacing works. Basically I want the following to to appear as if it's one word with different highlighting:

My preamble:

\documentclass[12pt,a4paper]{article} % din a4, 11 pt, one sided
\setlength{\parindent}{0in}
\setlength{\parskip}{0in}
\usepackage{xcolor}

\definecolor{orange}{HTML}{FF9456}
\definecolor{red}{HTML}{DD7A7A}
\definecolor{blue}{HTML}{93B5EA}

\newcommand{\orahi}[1]{\colorbox{orange}{#1}}
\newcommand{\redhi}[1]{\colorbox{red}{#1}}
\newcommand{\bluhi}[1]{\colorbox{blue}{#1}}

My text:

\orahi{sometexthere}
\redhi{sometexthere}
\bluhi{bluetexthere}

The output (PDF):

initial tex output

Removing the carriage returns between tags helps the actual white space, but not padding between words:

\orahi{sometexthere}\redhi{sometexthere}\bluhi{bluetexthere}

enter image description here

Again I want this to just appear as if it is one word with different highlight colors. Ideally it would be across many lines as shown in the first example, because this will eventually be a long string generated by Jinja. Any suggestions? Thanks in advance.

1
  • Likely the more powerfulltcolorbox could help to control the (unwanted) padding.
    – Jhor
    Jun 29, 2018 at 21:04

1 Answer 1

5

You need to comment out (or not add) the linebreaks which are inter-word spaces, and \colorbox adds padding of \fboxsep around its content so you can add

\setlength\fboxsep{0pt}
\orahi{sometexthere}%
\redhi{sometexthere}%
\bluhi{bluetexthere}%

You must log in to answer this question.

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