3

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?

1

1 Answer 1

3

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.

1
  • I can confirm that adding the 3 %-signs in the places you suggest to remove the end-of-line spaces works. Thank you very much!
    – Gerhard
    Sep 1, 2015 at 6:20

You must log in to answer this question.

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