# Problem with \hbox inside list

In the example below, the first \hbox to \linewidth ends up at the left of the page, despite the fact that it is inside an itemize environment. The presence of \hspace*{0pt} before the second seems to eliminate the problem.

\documentclass[12pt]{article}
\begin{document}
This is some text which shows the width of the whole page.
We must make sure it is long enough to occupy at least one whole line.
\begin{itemize}
\item
Inside the itemize environment, the text is not so wide.
\par
\hbox to \linewidth{\rule{\linewidth}{1pt}}
\par
\hspace*{0pt}\hbox to \linewidth{\rule{\linewidth}{1pt}}
\end{itemize}
\end{document}


What is going on here?

-
\par is special inside a list. Using \endgraf you'll notice a different output than you see with using \par. – Werner Jun 26 '12 at 16:15
\hbox is not a supported LaTeX command: you are supposed to use \makebox – David Carlisle Jun 26 '12 at 16:20

\hbox is not a supported LaTeX command: you are supposed to use \makebox or in this case just \rule directly. (Note similarly that while the LaTeX \rule works the TeX primitive \hrule would fail in the same way as \hbox.

\documentclass[12pt]{article}
\begin{document}
This is some text which shows the width of the whole page.
We must make sure it is long enough to occupy at least one whole line.
\begin{itemize}
\item
Inside the itemize environment, the text is not so wide.
\par
\hbox to \linewidth{\rule{\linewidth}{1pt}}
\par
\hspace*{0pt}\hbox to \linewidth{\rule{\linewidth}{1pt}}
\par
\rule{\linewidth}{1pt}
\par
\makebox[\linewidth]{\rule{\linewidth}{1pt}}
\end{itemize}
\end{document}


Technically what is going wrong is that LaTeX lists produce indentation by adjusting the paragraph shape, but \hbox does not start a paragraph it adds itself directly to the current vertical or horizontal list, with the result you see.

-
In the actual application I need implicit braces and \makebox[\linewidth]\bgroup stuff \egroup fails. Any ideas? – Ian Thompson Jun 26 '12 at 16:31
well I could tell you to use an environment form but if no one is looking I could tell you to put \leavevmode in front of the \hbox. If you compare the definitions of \mbox and \hbox you'll see that is the main difference. Of course \leavevmode isn't a supported LaTeX command either, but sometimes two wrongs do make a right. – David Carlisle Jun 26 '12 at 16:36