Text FormattingHorizontal centering a flushleft text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
MasterWizz
Posts: 6
Joined: Wed Jan 27, 2021 1:11 am

Horizontal centering a flushleft text

Post by MasterWizz »

Hey, how can i horizontal center a flushleft text?

Infominimal working example

The spacing on the left side is bigger than the spacing on the right side. How can I center this for any text?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Horizontal centering a flushleft text

Post by Ijon Tichy »

First of all, fushleft is an environment. You should not misuse it as command. The corresponding command would be \raggedright.
MasterWizz wrote: The spacing on the left side is bigger than the spacing on the right side.
This only seems so and is a combination of an optical effect an the fact, that no text line of the shown example reachs to the right edge of the text area. This is an usual effect of unjustified text without hyphenation. You could minimize this effect, by allowing hyphenation using package ragged2e:

Code: Select all

\documentclass{report}
\usepackage[margin=14.3pt,paperwidth=194pt,paperheight=194pt,showframe]{geometry}
\usepackage{ragged2e}
\usepackage{lipsum}

\begin{document}
\RaggedRight
\lipsum[3]
\end{document}
I've activated geometry's option showframe to illustrate the text area and show, that this is indeed centered.

BTW: report does not provide font size 9pt. So option 9pt is unused in your example. If you really need 9pt you have to use an extra package like extsizes or scrextend or use another class, that provides font sizes other than 10pt, 11pt or 12pt, e.g., a KOMA-Script class.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
MasterWizz
Posts: 6
Joined: Wed Jan 27, 2021 1:11 am

Horizontal centering a flushleft text

Post by MasterWizz »

Hey Ijon thanks for your reply! I understand what you mean and it really looks better. But is there also a solution to get the same distance left and right to the border? The enviroment \begin{center}...\end{center} gives me the perfect result except the \RaggedRight alignment. I know that this is a special request because the distance to the border now is variable and depends on the longest text line. Any other text line has to have the same distance to the left border like the longest text line. Just the longest text line has the same distance to the right border.

I also understand that this is not a typical LaTeX request and I also think its extremely questionable. But I need it for a special project. Is there any chance to get this strange result?
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Horizontal centering a flushleft text

Post by Ijon Tichy »

I don't think, that this would make sense, because in this case the margins have to change on each page. Something, that is not provided by TeX. However, inside one page, you can center a varwidth environment.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
MasterWizz
Posts: 6
Joined: Wed Jan 27, 2021 1:11 am

Horizontal centering a flushleft text

Post by MasterWizz »

YES! This is exactly what I was looking for! Its ugly like hell but I have to use it for a projekt....
Thank you!! :)

Edit:

Code: Select all

\begin{varwidth}{\textwidth}
\narrowragged
\lipsum[3]
\end{varwidth}
Works with any text.
Post Reply