Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Up to now I don't understand well what \null actually is and when we need it. I have only known that it can be used to create hypothetical anchors as follows.

\documentclass{article}
\usepackage[a6paper,margin=2cm]{geometry}
\parindent=0pt

\begin{document}
\hfill xport \hfill\null\\
\null\hrulefill{} never \hrulefill\par
\hrulefill{} dies. \hrulefill\par
\hfill really? \hfill\null\par


\newpage
\null
\vfill
\hfill The End \hfill\null
\end{document}
  1. What is \null and when do we need to use it?
  2. Why do \hrulefill and \hfill need starting \null when they follow \\ but not need \null when they follow \par?
  3. Why does \hfill always need ending \null but \hrulefill not need it?
share|improve this question
add comment

2 Answers

up vote 23 down vote accepted
  1. What is \null and when do we need to use it?
    \null is just \hbox{}. When is it needed? Never, actually.

  2. Why do \hrulefill and \hfill need starting \null when they follow \\ but not need \null when they follow \par?
    \hrulefill is \leavevmode\leaders\hrule\hfill\kern0pt, so it's not exactly like \hfill, as it adds a null kern after it, but very similar to it. The difference between \par\hrulefill and \\\hrulefill is that after a \par there's a box (the indent box, even with \noindent), but after \\ there's no box on the line, so glue disappears (and leaders, also).

  3. Why does \hfill always need ending \null but \hrulefill not need it?
    Because of the \kern0pt at the end of \hrulefill.

  4. Why is the first line after \begin{document} not regarded as a paragraph recall that starting \null is needed by \hfill there?
    Could you be more precise about this?

share|improve this answer
    
+1 And question number 4 has been canceled because it was based on my wrong assumption. Thanks. –  xport Aug 4 '11 at 20:58
add comment

TeX ignores spaces in some situation if there is no material. \null is the same as \hbox{} and it can be used for a material which reserves no space but shows TeX that there is a box which is taken into account for typesetting.

\documentclass{article}
    
\usepackage[a6paper,margin=2cm]{geometry}

    \parindent=0pt
    
    
\begin{document}
    
\hfill xport \hfill\null
    
    

\hrulefill never \hrulefill
    
    

\hrulefill dies \hrulefill
    
    
\newpage

\null
\vfill
    
\hfill The End \hfill\null
    
\vfill
    
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.