Search code examples
alignmentlatex

How to right align text and justify it? [Latex]


I've spent a while trying to figure this out and haven't able to make it so far.

My question is, I have a document in Latex and I would like to change the alignment of a piece of text to the right and justify it too. What I have now can be seen in this picture.

enter image description here

For the image above, this is the code:

enter image description here

I would like to get something like this.

enter image description here

I am just starting out with Latex and I'm still taking some time to learn about it. Thanks in advance.


Solution

  • Actually what you want is:

    • justified text
    • in a smaller box shifted to the right of page

    The way to do that is with a minipage environment. This allows to determine a box with a given size and to put text (or anything) in it.

    Then it is possible to place the minipage at a given position of the page.

    Here is an example

    \documentclass{article}
    
    \begin{document}
    \hfill\begin{minipage}{0.5\linewidth}
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat 
    non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \end{minipage}
    \end{document}
    

    and the result

    enter image description here

    The minipage is 50% of textwidth. Change that value as required.

    \hfill does horizontal filling and pushes next element (ie the minipage) towards the right margin. To have a finer control on the position of the minipage, you can use \hspace{6cm}(minipage)\\. It will leave 6cm, insert the minipage box and ends the "line" (\\).