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.

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?

share|improve this question
    
\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
1  
\hbox is not a supported LaTeX command: you are supposed to use \makebox –  David Carlisle Jun 26 '12 at 16:20

1 Answer 1

up vote 6 down vote accepted

\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.

enter image description here

\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.

share|improve this answer
    
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
3  
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

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.