0

I have implemented the suggestions from this thread using a tcolorbox to highlight inline with rounded corners.

I've noticed that the box has vertical margins I am unable to remove, and it pushes the lines before and after it further away.

screenshot

MVE as follows:

\documentclass[]{article}
\usepackage[most]{tcolorbox}
\usepackage{relsize}

\definecolor{kode-color}{RGB}{240,240,240}
\newcommand{\codesize}{\smaller[0.75]} 

\newcommand{\kode}[1]{%
    \tcbox[on line,
        show bounding box,
        boxsep=4pt, 
        left=0pt, right=0pt, top=0pt, bottom=0pt,
        colframe=white,colback=kode-color
    ]{\texttt{\codesize #1}}%
}

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea \kode{commodo consequat} duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{document}

Any idea how to avoid it? I'm not so keen on using tcolorbox, as I've read it gives headaches with line-breaking. What I'm using now is this:

\definecolor{kode-color}{RGB}{140,40,40}
\newcommand{\codesize}{\smaller[0.75]} % requires "relsize"
% File extension
\newcommand{\kode}[1]{\colorbox[HTML]{EEEEEE}{\color{kode-color}{{\texttt{\codesize #1}}}}}

It is simpler, with no line-height or line-breaking problems (AFAIK), but no rounded corners either. I'm trying to understand whether I can add a bit of eye candy without ruining it functionally.

Thanks!

4
  • For \tcbox, it's caused by your setting boxsep=4pt. For \colorbox, it's caused by \fboxsep which defaults to 3pt. Commented Sep 17, 2023 at 11:50
  • I need some internal padding. I can set boxsep=0pt, and the line height is indeed OK, but the box is too tight. Setting left, right, top, and bottom gets me back to square one, alas.
    – unDavide
    Commented Sep 17, 2023 at 12:37
  • 1
    Box extrusion options (documented in tcolorbox package manual, sec. 4.15.5) won't enlarge bounding box. You can try with boxsep=0pt, left=0pt, right=0pt, top=0pt, bottom=0pt, extrude by=2pt (extrusion option must be the last). Commented Sep 17, 2023 at 13:00
  • @unDavide, any news?
    – Zarko
    Commented Oct 17, 2023 at 13:09

1 Answer 1

0

For what you like to achieve it seems to be better to use soul package:

\documentclass{article}
\usepackage{xcolor}
\usepackage{soul}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea 
\hl{Commodo consequat} 
duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\end{document}

enter image description here

If you like to have different highlighting color, put in preamble or local group with highlighted text \sethlcolor{<desired color>}

You must log in to answer this question.

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