Thursday, April 12, 2007

Latex note: use minipage to align a figure of text to center, while keeping text aligned to left

Sometimes we need to align text with multiple lines to the center of page.

\begin{figure}[t]
\centering
this is first line \\
\hspace*{0.5cm} this is second line \\
this is third line \\
this is fourth line
\caption{caption}
\label{l}
\end{figure}

The above may not work because all lines are aligned to center, and they look messy on the left border. The solution is using a minipage to align text inside figure.

\begin{figure}[t]
\centering
\begin{minipage}[t]{0.5\textwidth}
this is first line \\
\hspace*{0.5cm} this is second line \\
this is third line \\
this is fourth line
\end{minipage}
\caption{caption}
\label{l}
\end{figure}

No comments: