[Tex/LaTex] Colored box just around the text

borderboxescolor

I want to have a rounded box with black border lines and a backgroundcolor, f.e. yellow just around the text, not around the whole line, so the sentence should just continue on the same line. I found many threads regarding similar questions but the answer was always around a whole line or a whole paragraph but not about just one word.

Best Answer

Based on this answer by Roelof Spijker, just add draw=black to achieve the black border:

\documentclass{article}
\usepackage{tikz}
\newcommand\mybox[2][]{\tikz[overlay]\node[fill=yellow!20,draw=black,inner sep=2pt, anchor=text, rectangle, rounded corners=1mm,#1] {#2};\phantom{#2}}
\begin{document}
  \begin{minipage}{0.4\textwidth}
    \noindent
    this is some text \mybox{box} text\\
    this is some text box text
  \end{minipage}
  \begin{minipage}{0.4\textwidth}
    \noindent
    this is some text box text\\
    this is some text box text
  \end{minipage}    
\end{document}