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 :-)

  • \setlength{\fboxsep}{0pt} may help you without disturbing your existing code.... – MadyYuvi Aug 26 '18 at 9:27
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}
  • 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 Aug 26 '18 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.