[Tex/LaTex] How to right-align text

alignmenthorizontal alignment

I'm looking to format some text in the same way as showed in the image (highlighted part) where the text is right-aligned and the next line starts in the same horizontal position as the previous one. I tried to use \hspace but didn't work as expected.

Example of some text in the wanted format

Thanks for the help.

Best Answer

SX!

You can achieve that by using a \parbox or a minipage environment. Use \hfill before it, in order to achieve your alignment. I used an \fbox additionally in my MWE to have a frame around the text. The % can be deleted if you want the marked text to move to the next line.

\documentclass{article}

\begin{document}
Some text
%
\hfill
\fbox{\parbox[t]{2cm}{This is the text in your marked box.}}
\end{document}

MWE result

edit: In case you have a small box width and long words, you might get big white spaces. To get the usual typesetting behavior inside a \parbox, one could use \fussy in the beginning of a \parbox. This is the default options latex uses for line breaking. Note, however, this doesn't help with too small boxes, which is the main issue here. You'll get underfull \hbox or overfull \hbox warnings, but you'll get em until you tackled the problem.

Related Question