[Tex/LaTex] Centered box, text inside it flushed right

horizontal alignmentpositioning

I have some text (like a title), that needs to be centered, and some notes to it (multiline – note 1 \\ note 2),
which should be directly underneath it and on the left side of it:

       Some centered text
       note1
       note2

How can I do it?

Best Answer

Use the varwidth package:

enter image description here

\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{varwidth}% http://ctan.org/pkg/varwidth
\begin{document}
Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text.

\begin{center}
  ​\begin{varwidth}{\textwidth}
    Here is some title that is somewhat long. \par
    And some notes. \\
    And some more notes.
  \end{varwidth}
\end{center}

Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text.
\end{document}

A width of \textwidth for the varwidth environment makes sure that the text will fit within the text block, but also shrink to the natural width of the box (in case it's not as wide).

For keeping the title centred (if the notes extend beyond the width of the title), you can use

\begin{center}
  ​\begin{varwidth}{\textwidth}
    \centerline{Here is some title that is somewhat long.} \par
    And some notes. \\
    And some more notes. And some more notes. And some more notes.
  \end{varwidth}
\end{center}

However, you are required to use \par to the title here then. There are other ways to do this as well.

The showframe package merely highlights the "centred-ness".