6

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}
gsl
  • 699
  • 1
    I would try to avoid the use of \vskip if at all possible. See also fourier-orns – Sean Allred Oct 03 '14 at 14:17
  • @sean-allred Thank you. I need to use precisely the \varstar symbol. I did not see that in fourier-orns. I am using vskip in order to precisely align the text to the grid. Try to remove it, and you will see the difference. Is there a safer alternative? – gsl Oct 03 '14 at 14:30
  • 1
    The LaTeX version of \vskip is \vspace … see my answer below. – Tobi Oct 03 '14 at 14:35
  • 1
    As shown in the answers below, you need to not put the vertical spacing into a box, otherwise you will get very bad behaviour at a page break with anomalous white space not being dropped (at a page break your negative vskip would be discarded but the space that it was correcting, from the center environment would be kept as it is inside the box. – David Carlisle Oct 03 '14 at 14:43

2 Answers2

6

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
}
Tobi
  • 56,353
  • Very nice, thank you. The second paragraph remains centered and indented. How can I make it fully justified and with no indentation, like my original (primitive) code? – gsl Oct 03 '14 at 14:38
  • 1
    My fault. I forgot to add the group. It is fixed in the code above already (doubled braces at the begin/end of definition) … – Tobi Oct 03 '14 at 14:39
  • 1
    If you leave a trailing \noindent (anywhere) you will live to regret it:-) – David Carlisle Oct 03 '14 at 14:40
  • @DavidCarlisle: Why? If the following line shouldn’t be indented in all cases. Your welcome to change my definition in an appropriate way to no-indent the following line ;-) – Tobi Oct 03 '14 at 14:42
  • @DavidCarlisle: Then, how can one automatically define the following paragraph as without indentation, as I need to do? – gsl Oct 03 '14 at 14:45
  • 1
    I guess this is the way to go: http://tex.stackexchange.com/q/112404/4918 – Tobi Oct 03 '14 at 14:46
  • 1
    It prematurely starts the next paragraph, so if what follows is a vertical thing eg a list or a heading or a ... or even just a blank line then you will get an anomolous white line from a paragraph that contains nothing. I'd just delete the \noindent but if you want to make it suppress indentation it should work like a section heading or \item and use the \@afterheading mechanism – David Carlisle Oct 03 '14 at 14:46
  • @tobi: Thank you for pointing out noindentafter. And thank you for the answer! – gsl Oct 03 '14 at 14:47
  • @DavidCarlisle: I was having the feeling my original code was going to be troublesome somewhere. Thank you for pointing that out. – gsl Oct 03 '14 at 14:49
  • @DavidCarlisle: :-) thanks. But maybe you can explain something strange, please? With the above definition an {itemize} \item following the \starlet is on the right vertical position (i.e. the next grid line with one line space above) but when I remove \NoIndentAfterThis the \item adds more space and goes to a wrong position … why? – Tobi Oct 03 '14 at 15:03
2

(Answer updated to incorporate the fact that use of \varstar, rather than of some arbitrary asterisk symbol, is required.)

I suppose an idiomatic LaTeXy way of creating a blank line of height \baselineskip is to type \par\null\par. To center-set a given symbol, one could use the TeX "primitive" command \centerline. In the code below, the command \starlet sandwiches the instruction \centerline{$\varstar$} between two sets of \par\null\par instructions. The total height of the output generated by \starlet is exactly 3\baselineskip, automatically preserving any grid alignment that may be in place.

enter image description here

\documentclass[twocolumn]{article}
\usepackage{mathabx}  % for \varstar symbol

\newcommand\starlet{%
  \par\null\par%  a blank line of height \baselineskip
  \centerline{$\varstar$}%  center-set the ask
  \par\null\par}% another blank line of height \baselineskip

%% Just for this example:
  \setlength\parindent{0pt} 
  \usepackage[textwidth=2.95in,showframe]{geometry}

\begin{document}
Some meaningless fluff.

Some meaningless fluff.

Some meaningless fluff.

Some meaningless fluff.

Some meaningless fluff.

\newpage  % induce a column break
Some meaningless fluff.

\starlet

Some meaningless fluff.
\end{document}
Mico
  • 506,678
  • 1
    Thank you. \textasteriskcentered is nice, but the publisher requested the \varstar symbol to be used (they are slightly different asterisks) – gsl Oct 03 '14 at 14:42
  • @gsl - Sorry, I had missed the fact that usage of the \varstar symbol was a requirement. I've updated the code to incorporate this information. – Mico Oct 04 '14 at 07:56
  • But wouldn’t @DavidCarlisle’s comment, that we get in trouble when something like {itemize} follows, apply here too? – Tobi Oct 04 '14 at 17:18
  • @Tobi - Maybe I'm dense, but I don't "get" this concern. In my experience, "starlets" only ever occur in running text, with a paragraph both preceding and following the "starlet". I don't think one has to worry too much about a "vertical thing" (David's expression, not mine!) occurring immediately after a starlet. Single or multiple blank lines following my version of \starlet are actually OK, as my MWE shows... Maybe the OP will weigh in and communicate how he/she intends to use the "starlets"? – Mico Oct 04 '14 at 17:40
  • @Tobi - Another reason I think one doesn't have to worry about "vertical things" in the present context is that the OP has mentioned explicitly that he/she is trying to get typesetting on a grid going. I would therefore expect that the OP has already redefined \par to eliminate any stretchability and shrinkability. – Mico Oct 04 '14 at 17:46
  • I share your experience, that starlets are used kind of exclusively in normal paragraph contexts, but I wanted to add a note on this for sake of completeness ;-) – Tobi Oct 04 '14 at 18:45