Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 409
João Victor Avatar asked Feb 16 '19 13:02

João Victor


People also ask

How do you right justify text in LaTeX?

Right. The environment \begin{flushright}... \end{flushright} does the opposite of flushleft , and the text will be aligned with the right-hand margin, and have a ragged left-hand edge. If you are already in an environment you can switch this style of alignment on in a different way using \raggedleft .

How do you align a figure to the right in LaTeX?

For general text you can use \raggedright and \raggedleft to align the material to the left and right, respectively. To align images inside a figure easily you can use the adjustbox package which allows you to add alignment keys to \includegraphics .

What is ragged right in LaTeX?

This declaration corresponds to the flushleft environment. This declaration can be used inside an environment such as quote or in a parbox. Unlike the flushleft environment, the \raggedright command does not start a new paragraph; it simply changes how LaTeX formats paragraph units.


1 Answers

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" (\\).

like image 183
Alain Merigot Avatar answered Oct 17 '22 08:10

Alain Merigot