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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following example:

\documentclass[a4paper,11pt]{article}
\usepackage{showframe}

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua.
\hfill
\fbox{At vero eos et accusam et justo duo dolores et ea rebum. Sed non arcu.}

\end{document}

The problem is that the contents of the \fbox does not fit on the line it is typeset and produces an overfull \hbox.

The question is: how to define a command that automatically puts the \fbox on the next line if an Overfull \hbox is generated?

share|improve this question
up vote 7 down vote accepted

You want to introduce a potential linebreak point after the fill.

enter image description here

\documentclass[a4paper,11pt]{article}
\usepackage{showframe}

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. \hspace*{\fill}\linebreak[0]%
\fbox{At vero eos et accusam et justo duo dolores et ea rebum. Sed non arcu.}



Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. \hspace*{\fill}\linebreak[0]%
\fbox{At vero eos et accusam et justo duo dolores et ea rebum.}

\end{document}
share|improve this answer

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.