[Tex/LaTex] Remove whitespace around tikz picture in running text

spacingtikz-pgf

I'm trying to draw a star in text brackets using tikz and I can't figure out how to remove the large white space to the left and right. The code is:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric}

\newcommand{\yellowstar}{
\tikzstyle{scorestars}=[star, star points=5, star point ratio=2.5, draw,inner sep=1.3pt,anchor=outer point 3]
  \begin{tikzpicture}[baseline]
    \draw (0,0) node[name=star,scorestars,fill=yellow]  {};
  \end{tikzpicture}
}

\begin{document}
Hello (\yellowstar).
\end{document}

The code is based on this: Drawing stars/similar with Tikz

This suggestion of adding a %-sign after "(" and putting \yellowstar on the next line doesn't work: Reduce white space around TikZ picture?

Best Answer

You have end of line spaces. To remove them add few % marks at the end of lines like I did.

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric}

\newcommand{\yellowstar}{%
\tikzstyle{scorestars}=[star, star points=5, star point ratio=2.5, draw,inner sep=1.3pt,anchor=outer point 3]%
  \begin{tikzpicture}[baseline]
    \draw (0,0) node[name=star,scorestars,fill=yellow]  {};
  \end{tikzpicture}%
}

\begin{document}
Hello (\yellowstar).
\end{document}

Or you can simply push the style commands inside the TikZ picture with the preferred syntax /. handles. See Should \tikzset or \tikzstyle be used to define TikZ styles? for more details. Then the macro definition becomes

\newcommand{\yellowstar}{\begin{tikzpicture}[baseline,
          scorestars/.style={star, star points=5, star point ratio=2.5,
                             draw,inner sep=1.3pt,anchor=outer point 3}
 ]
    \draw (0,0) node[name=star,scorestars,fill=yellow]  {};
  \end{tikzpicture}%
}

Then you have no whitespace seen by TeX since TikZ gobbles the spurious whitespace within its own environment.