简体   繁体   中英

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.

在此处输入图片说明

For the image above, this is the code:

在此处输入图片说明

I would like to get something like this.

在此处输入图片说明

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

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

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM