0
\documentclass[11pt]{article} % Document class
\newcommand{\zzitem}[2]{%
\begin{description}
    \item[\textbf{#1}]: #2
    \vspace{-.75em}
\end{description}
}       

\pagestyle{empty}

\begin{document}
    \zzitem{Relevant Courses}{Calculus III, AP Computer Science, Business Statistics, Financial Accounting}
    \zzitem{Languages}{Russian, fluent; Spanish, conversational}
\end{document}

Here is the output of the above LaTeX:

enter image description here

However, if I remove just one letter on the first line, this is what I get:

enter image description here

This is my desired output, but if I were to add in that letter. What is causing this behavior to create a new line, but to not push anything onto this new line?

John
  • 1
  • 1
    Welcome to TeX.SE. I am unable to reproduce the first screenshot you posted using the LaTeX code you posted. Please state which document class you employ, which font (and which font size) you use, and how wide the text block is. Ideally, your updated code should generate the screen shot with the unwanted blank line. – Mico Jun 27 '21 at 20:52
  • 1
    In the definition, you have a space after #2. That is what is causing the blank line -- there isn't enough room left on the first line, so the space is sent over to the next line. Add a % sign there. As @Mico says, we can't test this reliably because we don't know what document class you're using. – barbara beeton Jun 27 '21 at 20:53
  • @barbarabeeton I don't see a space after #2. Do you mean a newline? – John Jun 27 '21 at 20:56
  • In this context, a newline is equivalent to a space. – barbara beeton Jun 27 '21 at 20:57
  • Yeah that worked @barbarabeeton Thanks! – John Jun 27 '21 at 20:59
  • Two earlier questions that shed light on the use of % at the end of a line: What is the use of percent signs (%) at the end of lines? (Why is my macro creating extra space?) and (La)TeX — What does the '%' character do?. (There are more, but I think these are the most relevant.) – barbara beeton Jun 27 '21 at 21:15
  • 1
    Is there any real need to make a single item description? – egreg Jun 27 '21 at 21:23
  • I woul rather use standard description . In your case: \documentclass[11pt]{article} \begin{document} \pagestyle{empty} \begin{description}\raggedright \item[Relevant Courses:] Calculus III, AP Computer Science, Business Statistics, Financial Accounting \item[Languages:] Russian, fluent; Spanish, conversational \end{description} \end{document} gives desired result. – Zarko Jun 27 '21 at 21:26
  • 1
    the question in your title mentions \raggedright but your code does not have that command? – David Carlisle Jun 27 '21 at 21:31
  • I'm really confused as to the purpose of the negative \vspace. Also, em is really meant to be a measure of horizontal space; the corresponding vertical measure is ex. – barbara beeton Jun 27 '21 at 21:54
  • @DavidCarlisle I edited the title of the question to correctly identify the issue. – Don Hosek Jun 27 '21 at 22:08
  • @barbarabeeton Knuth's definition of em is idiosyncratic to him, in particular having the width of an em vary if the font is expanded or compressed. Traditionally an em was a square piece of metal with the same height and width, that being the body-size (at size in TeX parlance) of the font (I'd note that even that isn't exactly true. A typecaster might cast a 9-pt font on an 10pt body (since they would more likely have plenty of 10pt spaces for composition lying about), or more rarely on a smaller body if everything would fit. Everywhere but TeX, 1em is usually the current typesize. – Don Hosek Jun 27 '21 at 22:13
  • @DonHosek -- Regarding the em, that is all true. But, since we're talking about TeX here, and ex doesn't change relative to the baseline setting while em does (I can't think of any document class that sets \baselineskip in ems), ex is likely to be a more reliable measure for a local vertical setting. – barbara beeton Jun 27 '21 at 22:21

2 Answers2

1

There is a space between #1 and \vspace (caused by the newline). So the offending paragraph ends with “Accounting<space><whatsit>”. The “whatsit” is an invisible object placed in the paragraph that will add vertical space after the line it happens to eventually be. You're unlucky, but you're the cause of it.

A blank line before \vspace{-0.75em} would do (or \par after #2, which would be exactly the same).

But is there any need for a single item description if you want to remove the space it produces?

\documentclass[11pt]{article}

\newcommand{\zzitem}[2]{% \par \addvspace{\topsep}% \noindent \hangindent=\leftmargini \textbf{#1}: #2\par \addvspace{\topsep}% }

\pagestyle{empty}

\begin{document}

\zzitem{Relevant Courses}{Calculus III, AP Computer Science, Business Statistics, Financial Accounting}

\zzitem{Languages}{Russian, fluent; Spanish, conversational}

Just for comparison, here's what you get with a \emph{single} description

\begin{description} \item[Relevant Courses\normalfont:] Calculus III, AP Computer Science, Business Statistics, Financial Accounting

\item[Languages\normalfont:] Russian, fluent; Spanish, conversational \end{description}

\end{document}

enter image description here

egreg
  • 1,121,712
0

Putting aside

  • the supplied code does not produce the indicated output (I had to fix the comment on the first line and adjust the line width with \addtolength{\textwidth}{1.6in} to get the expected result).
  • the approach to formatting is questionable

There remains the problem of understanding why an extra space would cause a new line to be created. After all, this doesn't happen normally in a LaTeX document.

And the reason for this is that \vspace doesn't do what a lot of people think it does. It does not start a new line and insert the space. Instead, it inserts the space after the current line if it appears in the middle of a paragraph. You can see this for yourself by running the following through LaTeX¹:

A surging, seething, murmuring crowd of beings 
that are human only in name, for to the eye and ear 
they seem naught but savage creatures, animated by 
vile passions and by the lust of vengeance and of hate.
\vspace{1in}
The hour, some little time before sunset, and the place, 
the West Barricade, at the very spot where, a decade 
later, a proud tyrant raised an undying monument to the 
nation’s glory and his own vanity.

\vspace is clever in that it will give the correct spacing regardless of whether there's a space before it or after it or both as is the case in this paragraph. You can try putting a % after hate. or after {1in} and you'll see identical output, but if you put in both %s, you'll get no space at all. But that cleverness comes at a cost. If it's at the end of a paragraph, the space that's normally discarded there will be retained.

egreg, surprisingly, managed to get the cause of the problem wrong. It's not that there's a space followed by a whatsit². In fact what's happening is that the code that does the space preservation in the \vspace command is responsible for putting an explicit space in the horizontal list that would otherwise have been dropped. We would get the same result if we had any other command that used the same mechanism to avoid extraneous spaces from going into the output such as \label

So, the bottom line is, to get your correct spacing the “best” solution would be to either add a blank line before \vspace so it's not treated as part of the paragraph or put a % after #2 so that there's no space to try to preserve. But I think I would instead, either use a description list as described in egreg's solution or, if you were committed to your structure, I would instead build up a single-item list environment with the skips set appropriately to format your output, but since that's beyond the question's scope, I won't offer an example here.


  1. In the source code for LaTeX (texdoc source2e) you will see the following in the comments:

    [For example, is \vspace ever used in the middle of a paragraph?]

    the answer to this is, yes, but probably not intentionally!

  2. As long as I'm being nitpicky, a \vadjust is not a whatsit but just vertical matter inserted into the main vertical list. Knuth had originally expected everyone to customize their TeX and add additional whatsits beyond the basic ones that are provided (\special and \write), but this never happened (except I think, but don't remember for sure that TeX-XeT's special codes for switching between L-R and R-L mode might have been implemented as whatsits).

  3. I'll have to remember to add a warning about this in the section of my book where I talk about \label.

Don Hosek
  • 14,078