10

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?

3 Answers 3

9

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".

1
  • 1
    Nice! I guess there's no easy way to keep the title line centred if the notes lines are longer?
    – Jake
    Apr 24, 2012 at 18:59
7

You can use the minipage or the varwidth environment for the text. Then put the whole thing in a center environment.

\documentclass{article}

\usepackage{varwidth}
\usepackage{lipsum}
\begin{document}

\lipsum[1]% dummy text

\begin{center}
    \begin{varwidth}{5cm}
        \textbf{Some title}\\
        Node 1\\
        Node 2 
    \end{varwidth}
\end{center}

\lipsum[2]% dummy text

\end{document}

Of course you can use adjustbox to simplify the code a little. However the env key is unfortunately broken in the current version. I will upload a fix soon to CTAN.

\documentclass{article}

\usepackage{adjustbox}
\usepackage{lipsum}
\begin{document}

\lipsum[1]% dummy text

% Add `varwidth` and `center` environment (but broken in current version :-( )
\noindent\adjustbox{varwidth=5cm,env=center}{% 
        \textbf{Some title}\\
        Node 1\\
        Node 2
}

\lipsum[2]% dummy text

\noindent\adjustbox{varwidth=5cm,center,margin=0pt \bigskipamount}{% (`margin` adds a vertical skip above and belo)
        \textbf{Some title}\\
        Node 1\\
        Node 2
}

\lipsum[3]% dummy text


\end{document}
5

If the lines don't need wrapping, then there is a simple method without extra packages:

\begin{center}
\begin{tabular}{@{}l@{}}
Some centered text\\
note1\\
note2
\end{tabular}
\end{center}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .