How do I center part of a sentence or text in LaTeX?

In some cases, we need to show a part of a sentence in the center. There are several ways to do this in latex.

In this tutorial, we will discuss all those methods and in between, you can choose the method of your choice.

TopicText center in LaTeX
Type of topicText alignment
Package (requirement)No
ArgumentYes
Latex command\centerline{*}

In latex, the default command is \centerline{arg}. As an argument to this command, the text you pass will move to the center position of the output.

This is the easiest way to center text, but I do not recommend this method as it may not be suitable for long text.

\documentclass{article}
\begin{document}
  This is the first sentence. Some parts of the second sentence are here in the\\ 
  \centerline{center of the second line.}
  \textbf{Some more examples:}\\[6pt]
  No one rejects, dislikes, or avoids pleasure itself, because it is pleasure,\\
  \centerline{but because those who do not know}
  how to pursue pleasure rationally encounter consequences that are\\
  \centerline{extremely painful.}
\end{document}

Output :

Text center in latex.

Use center environment

In latex, the best way to place text or sentences in the center position of a line is to use the center environment.

If you type any text in this environment, it will move to the center position of the line. Take a look:

\documentclass{article}
\begin{document}
  This is the first sentence. Some parts of the second sentence are here in the
  \begin{center}
   center of the second line.
  \end{center}
  This is the third sentence.text text text text text text text text text text.
\end{document}

Output :

Text center useing center environment in latex.

In Latex, there are many ways to center text but the best way is to use center environment, for which I recommend this method.

Use \makebox and hspace*

Here are some examples of using \makebox.

\documentclass{article}
\begin{document}
  This is the first sentence. Some parts of the second sentence are here in the\\
  \makebox[\textwidth]{center of the second line.}
  This is a really long sentence as an example.  The second half of this\\
  \makebox[\textwidth]{sentence should be centered.}
  \end{document}

Output :

Text center using \makebox command in latex.

In the case of \hspace* you need to use \\ like this \hspace*{\fill}\\ to break the line. Here are some examples.

\documentclass{article}
\begin{document}
  This is the first sentence. Some parts of the second sentence are here in the\\
  \hspace*{\fill}center of the second line.\hspace*{\fill}\\
  This is a really long sentence as an example.  The second half of this\\
  \hspace*{\fill} sentence should be centered. \hspace*{\fill}
  \end{document}

Output :

Text center using hspace* in latex.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top