4

Is it possible to draw a (coloured) border around the edge of a LaTeX symbol?
For instance, I would like to draw a black border around the edge of a \bigstar. So, something like this
enter image description here

Below a very short MWE

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usepackage{amssymb}

\begin{document}
\begin{tikzpicture}[scale = 0.5]
\node [yellow] at (0,0,0) {$\bigstar$};
\end{tikzpicture}
\end{document}

I searched for solutions, but I only get squared frames around basically anything, but not what I'm after. Any idea? Cheers

2 Answers 2

4

Basic

\documentclass[preview,border=12pt,varwidth,dvipsnames]{standalone}
\usepackage{contour}
\usepackage{xcolor,amssymb}


\contourlength{0.5pt} % thickness
\contournumber{10} % number of replication

\begin{document}
\huge
\contour{orange}{$\bigstar$}
\end{document}

enter image description here

Miscellaneous

The following example is not impossible but it takes much time and energy with PSTricks, let alone TikZ.

\documentclass[preview,border=12pt,varwidth,dvipsnames]{standalone}
\usepackage{contour}
\usepackage{xcolor,amsmath}
\usepackage{CJK}

\contourlength{0.2pt} % thickness
\contournumber{10} % number of replication

\begin{document}
\huge
\begin{CJK}{UTF8}{min}
\begin{center}
\contour{orange}{気持ちは}
\end{center}
\[
\contour{red}{$\sqrt{x^2}$}\,
\contour{green}{$\not=$}\,
\contour{blue}{$x$}
\]
\begin{center}
\contour{cyan}{言い表しにくいです}
\end{center}
\end{CJK}
\end{document}

enter image description here

2
  • \contour{red}{$\sqrt{x^2}$}\, \contour{green}{$\not=$}\, \contour{blue}{$x$} should be \contour{red}{$\mathsurround=0pt\displaystyle\sqrt{x^2}$} \mathrel{\contour{green}{$\mathsurround=0pt\displaystyle\neq$}} \contour{blue}{$\mathsurround=0pt\displaystyle x$} Commented Dec 12, 2018 at 2:01
  • these are both great answers, thank you guys. now the dilemma: which one to accept? Is there some criteria? I don't want to be unjust with @marmot
    – andrea
    Commented Dec 12, 2018 at 9:25
2

I guess the most simple-minded approach would be to draw the node in black and a bit larger underneath. Notice that you need to add transform shape for the scale=0.5 to affect the node.

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usepackage{amssymb}

\begin{document}
\begin{tikzpicture}[scale = 0.5,transform shape]
\node [black,scale=1.2] at (0,0,0) {$\bigstar$};
\node [yellow] at (0,0,0) {$\bigstar$};
\end{tikzpicture}
\end{document}

enter image description here

contour, as suggested in this answer does basically the same. However, TikZ also has star symbols built in. Why not use those?

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}
\node [star,draw,fill=yellow,minimum size=5mm,star point ratio=2]{};
\end{tikzpicture}
\end{document}

enter image description here

The crucial advantage is that you have all sorts of parameters that you can adjust to obtain the star you really want (a so-called super-star ;-), see the pgfmanual on p. 701.

enter image description here

3
  • +1. I also wrote the same code., except that I used red instead of black :)
    – nidhin
    Commented Dec 11, 2018 at 18:17
  • @nidhin You very recently scooped me in another answer, which I (of course) upvoted, thanks!
    – user121799
    Commented Dec 11, 2018 at 18:21
  • 1
    hehe. Then let us consider it even. :)
    – nidhin
    Commented Dec 11, 2018 at 18:22

You must log in to answer this question.

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