Spaces (glues and kerns) disappear after line breaks by rule; by the same rule, line breaks can happen only at the "left edge" of a space. Moreover, if one says \hspace{1cm}\hspace{1cm}
, the first \hspace
is a feasible break point, but not the second one.
This is how TeX attains alignment to the left margin for normal and ragged right paragraphs (ragged left uses a different feature).
More precisely, a glue (\hspace
) can be chosen as break point only if it is preceded by a non discardable item (most commonly a character or a rule). Among discardable items are penalties.
In some cases one wants to have spaces that don't disappear at line breaks: for instance blanks that should filled by hand in an exercise. Thus LaTeX provides the \hspace*
variant.
When \hspace*{1cm}
is called, LaTeX uses the internal command \@hspacer
, which does
\vrule width 0pt \nobreak \hskip 1cm \hskip 0pt plus 0pt minus 0pt
\vrule width 0pt
places an invisible object that takes up no space;
\nobreak
sets a point where line breaking is impossible, by issuing a very large penalty;
\hskip 1cm
cannot be used as a break point, because it is preceded by a discardable item (the penalty);
\hskip 0pt plus 0pt minus 0pt
is inserted to avoid possible problems due to the peculiar syntax of the primitive \hskip
; it won't be a feasible break point, because it's preceded by a discardable item;
Thus \hspace*{1cm}
forms, so to speak, an indivisible unit that will never be taken as a break point, nor will disappear at line breaks.
A consequence of this rules is that a space after \hskip*{1cm}
cannot be used as break point.
Suppose we want to define a \blank
macro for leaving space to be later filled in by hand:
\documentclass{article}
\newcommand{\blank}[1]{\hspace*{#1}}
\begin{document}
\parbox{4cm}{
Some text to see what's going on: \blank{2cm} and \blank{3cm} with text after them
}
\end{document}
The result will be
(where the rules represent the \hspace*{...}
commands; they won't be printed by this command, I used them just to show the effect). You can see that the space after \blank{...}
is not used as break point.
With a different definition, the blanks can appear at the end of the line:
\documentclass{article}
\newcommand{\blank}[1]{\hspace*{#1}\linebreak[0]}
\begin{document}
\parbox{4cm}{
Some text to see what's going on: \blank{2cm} and \blank{3cm} with text after them
}
\end{document}
will result in
Of course the typesetting here is suboptimal, but the point is to show how the thing works.
The \linebreak[0]
command just inserts a feasible break point, without stating any particular preference for it.
For the interested readers, the "rule" effect for showing \hspace*
has been obtained with the following trick:
\let\TeXhskip\hskip
\def\hskip{\leaders\hrule\TeXhskip}
What your code does
From the unofficial LaTeX reference manual, sec. 20.1:
LaTeX normally removes horizontal space that comes at the beginning or
end of a line. To preserve this space, use the optional *
form [of \hspace
].
So let’s use \hspace*
instead:
\documentclass[]{article}
\begin{document}
\section*{Affirmation}
\addcontentsline{toc}{section}{Affirmation}
\hspace{1cm}something
\vspace{2cm}
\hspace{1cm}city, date \hspace{3cm}\line(1,0){200}
\newline
\hspace*{8cm}(name)
\clearpage
\end{document}
What your picture says
The rest of the spacing is pretty different from your output because your screen shot was quite certainly not produced by the code you posted. With a bit of guesswork, I think this is closer to what you intended (note that you have to use the starred version of \hspace
in several instances):
\documentclass{article}
\begin{document}
\section*{Affirmation}
\addcontentsline{toc}{section}{Affirmation}
\hspace*{1cm}something
\vspace{2cm}
\noindent\hspace*{1cm}city, date \hspace{3cm}\line(1,0){200}
\newline
\noindent\hspace*{8cm}(name)
\end{document}
What I would suggest
Taking your layout and thinking about an implementation, I would do something like this, which is cleaner than meddling with a lot of spacing manually:
\documentclass{article}
\begin{document}
\section*{Affirmation}
\addcontentsline{toc}{section}{Affirmation}
something\\[2cm]
city, date \hfill
\begin{minipage}[t]{7cm}\centering
\rule{\linewidth}{.5pt}\\
(name)
\end{minipage}
\end{document}
Best Answer
At the start of a line TeX ignores spaces. The star form is needed:
\hspace*{-15pt}
.