8

This is probably a rather trivial question, but I don't see an obvious way on how to solve it. I want to center a piece of text, but i want to have the centered text be aligned left.

So I would like:

\begin{center}
line1
line2
line3
\end{center}

but where line1, line2 and line3 are aligned left, but still are centered.

  • Do you mean you don't want to use the whole width of a line? ␣␣␣␣␣text␣␣␣␣␣ – Johannes_B Dec 12 '13 at 9:51
  • Do you mean the whole body is aligned left but individual lines are centered among themselves? It is not very clear what you are asking for. Do you think you can show a simulated output? – Masroor Dec 12 '13 at 9:51
  • Sorry, what I mean is: I want to center the block of lines, but I want align the lines to the left of that centered block (i.e. I want to let all the lines start at the same point). – MaVe Dec 12 '13 at 9:54
  • 3
    Well then use a minipage \begin{center}\begin{minipage}{0.5\linewidth}<content>\end{minipage}\end{center} – Johannes_B Dec 12 '13 at 9:57
8

You could use a tabular which aligns the text to the left and is itself centered in the text. This could look like this:

\documentclass{scrreprt}
\usepackage{lipsum}
\begin{document}
 \lipsum[1]
 \begin{center}
  \begin{tabular}{l}
    This is line 1 with some text. \\
    This is line 2 with a slightly different text \\
    Line 3 is completely different and also a bit longer. \\
  \end{tabular}
 \end{center}
\end{document}

The output looks like this:

enter image description here

  • This solution is fine, only when the lines are rather short. If one of the lines is v-e-r-y long, this it won't do the job. – Dror Dec 12 '13 at 13:22
  • Thats right. You could use a table with fixed width, but these are centered, if I remember correct. – Chris Dec 12 '13 at 13:47
  • Define a new coloumntype with the ragged2e package and the definition of \newcolumntype{A}{>{\RaggedRight}p{1\textwidth}} and you have a defined width with left aligned text. But seriously, doing it with a minipage and maybe \hfill{} is better. – Ulle Dec 12 '13 at 14:35
1

Using a minipage is rather simple and can be helpful in this case.

\documentclass{scrreprt}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{center}
  \begin{minipage}{0.5\linewidth}
    \lipsum[2]

    \begin{itemize}
    \item This is line 1 with some text.
    \item This is line 2 with a slightly different text
    \item Line 3 is completely different and also a bit longer.
    \item And what about really really really really really
      really really really really really really really really really
      really lines?
    \end{itemize}
  \end{minipage}
\end{center}
\end{document}
  • Why the itemize environment? Works without it and a parskip too and i guess that is what he searched for. – Ulle Dec 12 '13 at 14:31
  • @JohannesO: Just for the sake of demonstration. It seemed like the OP referred to a list which is centered and indented. You could tweak the itemize environment as you want. – Dror Dec 12 '13 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.