[Tex/LaTex] Better idiomatic way to print a centered “starlet” (asterisk)

code-review

I need to print what the publisher calls "a starlet" (asterisk).

I devised the code below, but I am not sure if it is a sound code, i.e., it won't cause problems later on, within other commands and the text stream.

Is that the idiomatic way to print a special character (in this case, mathabx's \varstar), centered and with 1 blank line above and below?

I am using \vgrid in order to check the vertical alignment is preserved as precisely as possible, in respect to the underlying grid.

\documentclass[
DIV=calc,
twoside,
openright,
twocolumn=false,
titlepage,
numbers=noenddot,
headinclude=true,
footinclude=true,
]{scrbook}

\usepackage{kantlipsum}
\usepackage{mathabx}
\newcommand{\aster}{$\varstar$} 

\usepackage{vgrid}

\makeatletter
\newcommand{\starlet}{% 
  \par
  \vskip -0.5pt
  \noindent
  \parbox{\linewidth}{
    \begin{center}
      \aster
    \end{center}
  }
  \par
  \vskip 0.6pt % make it fit the grid
  \noindent
}
\makeatother

\begin{document}
\kant[1]
\starlet
\kant[1]
\end{document}

Best Answer

I suggest using \centering instead of {center} since the former adds no vertical space and let’s you control the spacing exactly it without the need of fiddling with corrections. To use \centering only for a part of your document enclose it in a group, i.e. {…}, and add a \par after it but inside the group. Then use \(add)vspace with \baselineskip as value to add blank lines before and after.

\usepackage{adjustbox,noindentafter}

\newcommand{\starlet}{%
  {% 
    \par
    \addvspace{\baselineskip}%
    \centering
    \adjustbox{raise=1pt}{\aster}%
    \par
    \vspace{\baselineskip}%
  }%
  \NoIndentAfterThis
}

Some notes

  • \addvspace chacks wether there is already some space before and adds it only when necessary. At the of the definition you can use the normal \vspace since there won't be any space before it.
  • \NoIndentAfterThis (needs noindentafter) is the way to prevent the indent after the command. This must be outside of the group. (see Reliable code for automatic \noindent after specific environments?)
  • If you want to center \aster in the line, one way is to use \adjustbox{raise=1pt}{\aster} (needs adjustbox) or another way is \raisbox{1pt}{\aster} (needs graphicx).
  • The \makeatletter/other pair isn’t needed here since you don’t use commands containing @ as part of their name.

To center a single line (box) one can also use \hspace with \fill as a value:

\newcommand{\starletII}{%
  \par
  \addvspace{\baselineskip}%
  \hspace*{\fill}% without the star space would be ignored it it
         % begins/ends a line
  \adjustbox{raise=1pt}{$\star$}%
  \hspace*{\fill}
  \par
  \vspace{\baselineskip}%
  \NoIndentAfterThis
}
Related Question