6

How can I style some element that looks like stackoverflow tags? enter image description here

3
  • 4
    Welcome to TeX.SX! This can be easily done with TikZ or alike. Please see the PGF manual and try to construct them. If you encounter any problems, post you code here with your specific question and we try to help you. Like this, it is just a "do-it-for-me"-question which will not find much interest here. – LaRiFaRi Jan 9 '15 at 8:31
  • tex does not have "elements" are you asking about a web page (with mathjax style math as on math.stackexchange?) (If so it is off topic for this site) – David Carlisle Jan 9 '15 at 8:43
  • tcolorbox could be another solution. – Ignasi Jan 9 '15 at 9:01
5

Here's another option using tcolorbox:

enter image description here

The code:

\documentclass{article}
\usepackage[many]{tcolorbox}

\definecolor{tagbg}{RGB}{224,234,241}
\definecolor{tagtext}{RGB}{62,109,154}

\newtcbox{\mytag}{
  enhanced,
  nobeforeafter,
  tcbox raise base,
  boxrule=0.4pt,
  top=1pt,
  bottom=1pt,
  right=3pt,
  left=3pt,
  arc=0pt,
  outer arc=0pt,
  boxrule=0.4pt,
  before upper={\vphantom{dlg}},
  coltext=tagtext,
  colback=tagbg,
  colframe=tagtext,
  fontupper=\sffamily
}

\begin{document}

\mytag{html}
\mytag{css}
\mytag{alignment}

\end{document}
0
11

With \fcolorbox command from the xcolor package you can define a new command \tagbox

\newcommand{\tagbox}[1]{\fcolorbox{LightGray}{LightCyan}{\textsf{#1}}}

Change the colors to the ones you like.

MWE:

\documentclass{article}
\usepackage[svgnames]{xcolor}
\newcommand{\tagbox}[1]{\fcolorbox{LightGray}{LightCyan}{\textsf{#1}}}
\begin{document}
\tagbox{html}
\end{document}

Output:

enter image description here


EDIT

Just to show that it can be done without tcolorbox.

MWE (colors borrowed from Gonzalo's answer

\documentclass{article}
\usepackage{xcolor}

% colors borrowed from Gonzalo's answer
\definecolor{TagBG}{RGB}{224,234,241}
\definecolor{TagText}{RGB}{62,109,154}

\newcommand{\tagbox}[1]{\fcolorbox{TagText}{TagBG}{\textcolor{TagText}{\textsf{\vphantom{hg}#1}}}}

\begin{document}
\tagbox{html} \tagbox{css} \tagbox{alignment}
\end{document} 

Output:

enter image description here

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.