2

Here's the MWE:

\documentclass[a4paper, 12pt]{article}

\renewcommand{\rmdefault}{ptm}
\usepackage[table]{xcolor}

\definecolor{tpgray}{gray}{0.90}
\newcommand{\tp}[1]{\colorbox{tpgray}{#1}}

\begin{document}
The board connectors are called \tp{GND} and \tp{VDD}.
\end{document}

This results in

enter image description here

How do I reduce the width of the gray area left and right of the highlighted text? I think there's a bit too much space, particularly at the end before the period. I don't mind leaving it as is but if there is a simple answer that takes less than 5 minutes (I don't want to waste anybody's time), I'd highly appreciate it :-)

1
  • \setlength{\fboxsep}{0pt} may help you without disturbing your existing code....
    – MadyYuvi
    Commented Aug 26, 2018 at 9:27

1 Answer 1

4

The following solution shows two approaches: (1) use \colorbox and reduce the spacing at all sides and (2) use \tcbox from tcolorbox and change the sides independently.

boxing

\documentclass[a4paper, 12pt]{article}

\renewcommand{\rmdefault}{ptm}
\usepackage[table]{xcolor}

\definecolor{tpgray}{gray}{0.90}
\newcommand{\tp}[1]{\colorbox{tpgray}{#1}}
\setlength{\fboxsep}{1pt}

\usepackage[skins]{tcolorbox}
\newtcbox\tcbtp{hbox, on line, colback=tpgray, enhanced, frame hidden, boxrule=0pt, 
    top=1pt, bottom=1pt, right=-2pt, left=-2pt, sharp corners}

\begin{document}
The board connectors are called \tp{GND} and \tp{VDD}.

The board connectors are called \tcbtp{GND} and \tcbtp{VDD}.
\end{document}
1
  • Dang, that's cool! And now I can even use rounded corners which makes it look even better. Very nice. Thanks a lot for your quick help. This community is awesome.
    – Hansel
    Commented Aug 26, 2018 at 8:24

You must log in to answer this question.

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