1

I have two small lines of text with different width. I want flush them right keeping their left justification and the line height of previous text.

\documentclass{article}
\usepackage{fontspec} 

\usepackage{lipsum}

\begin{document}

I was yet young in life, which I had begun early; but my intimacy with him was of a recent date: we had been educated at the same schools and university; but his progress through these had preceded mine, and he had been deeply initiated into what is called the world while I was in noviciate noviciate noviciate.

\hfill\vbox{\hbox{Foo}
\hbox{Foobar}}

\end{document}

enter image description here

3

You can use a tabular with [t]op alignment.

\documentclass{article}
\usepackage{fontspec}

\usepackage{lipsum}

\begin{document}

I was yet young in life, which I had begun early; but my intimacy with him was of a recent date: we had been educated at the same schools and university; but his progress through these had preceded mine, and he had been deeply initiated into what is called the world while I was in noviciate noviciate noviciate.

\hspace*{\fill}
\begin{tabular}[t]{l@{}}
Foo\\
Foobar
\end{tabular}

\end{document}

enter image description here

  • I upvote @HarishKumar's answer, because that is the correct way of doing what you want to do. – GuM Apr 26 '15 at 11:44
  • To be fussy, with the t option to tabular you get the \lineskip glue, instead of \baselineskip, below the two exceptional lines. But probably, in a situation like this, it is not worth the effort to insist on performing the "optimal" solution (\strut in the preceding line, b option to tabular, then {\offinterlineskip\par} just after the tabular itself… (:-) – GuM Apr 26 '15 at 17:46
2

The simplest solution is to put a \strut both at the end of the preceding text and inside the \hbox:

\documentclass{article}
\usepackage[T1]{fontenc} 

\usepackage{lipsum}

\begin{document}

I was yet young in life, which I had begun early; but my intimacy with him
was of a recent date: we had been educated at the same schools and
university; but his progress through these had preceded mine, and he had
been deeply initiated into what is called the world while I was in
noviciate noviciate noviciate.\strut

\hfill\vbox{\hbox{\strut Foo}
\hbox{Foobar}}

\end{document}

But using primitive boxing commands in LaTeX is not recommended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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