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.

Normally, text that does not fit into the width of a parbox sticks out on the right side:

\documentclass{article}
\begin{document}
\fbox{\parbox[t]{1cm}{\strut\raggedleft This \mbox{doesnotfit}}}
\end{document}

looks like this:

   |  This|
   |doesno|tfit

However, I really want the overflow to occur on the left side, the right side of the parbox should stay justified at all costs, i.e. I want:

    |  This|
does|notfit|

Is there a way to do that?

share|improve this question
    
But the text does not stick out on both sides, as you can see using and \fbox: \documentclass{article} \begin{document} \fbox{\parbox[t]{1cm}{\strut\raggedleft This \mbox{doesnotfit}}} \end{document} –  Gonzalo Medina Mar 13 '12 at 1:35
    
@Nikratio It normally sticks to the right, not at both sides. perhaps you should explain in a bit more detail what is the ultimate goal you want to achieve. –  Yiannis Lazarides Mar 13 '12 at 1:35
    
@GonzaloMedina Indeed, I corrected the question accordingly. But I still want the text to stick out on the left only.. –  Nikratio Mar 13 '12 at 1:46
    
@YiannisLazarides The ultimate goal is really just to have the text stick out on the left instead of on the right. I have a document where this would look much nicer. –  Nikratio Mar 13 '12 at 1:47

1 Answer 1

up vote 6 down vote accepted

enter image description here

\documentclass{article}
\begin{document}


\hrule width 1cm

\noindent \parbox[t]{1cm}{
\raggedleft
\leftskip 0pt  plus \hsize minus \hsize

\strut  This \mbox{doesnotfit}}
\end{document}
share|improve this answer
    
Works great, thanks! But could you explain what exactly the \leftskip 0pt plus \hsize minus \hsize does? –  Nikratio Mar 13 '12 at 2:00
    
If the box goes overfull it will stick out on the right, so the trick is to add enough shrink glue that the left margin can go negative and back space enough so it fits. You can't add infinite shrink glue as that upsets the paragraph breaker, but you can make it "big enough" finite glue. So here the right margin can vary between -\hsize and \hsize so as long as your text isn't twice as wide as the box you are putting it in, you have enough negative space, otherwise you can increase that as required. –  David Carlisle Mar 13 '12 at 2:04

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.