[Tex/LaTex] \centerline ignores page margin

margins

I have the following page which I am trying to get the first line to be centered without affecting the other text. However, using \centerline{} seems to ignore the page margin and does not wrap text to fit the original margin.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\begin{document}
\centerline{\textbf{\large{Appendix \hypertarget{Appendix}{F}: Construction of the Managerial Performance Indicator (MSI)}}}

\vspace{0.5 cm}

This text is just for the example
\end{document}

enter image description here

Best Answer

The macro \centerline comes from Plain TeX and its behavior is exactly what you see: it centers without wrapping text and without respecting the margin.

The macro is not supported in LaTeX; it exists just for historical reasons. If one knows how to properly use it, well; otherwise, it's better to leave it alone.

Perhaps you are looking for

\begin{center}
\bfseries\large
Appendix \hypertarget{Appendix}{F}: Construction of the 
Managerial Performance Indicator (MSI)
\end{center}

Technical note.

Here is the definition of \centerline:

% latex.ltx, line 5030:
\def\centerline#1{\@@line{\hss#1\hss}}

and here is the definition of \@@line:

% latex.ltx, line 5027:
\def\@@line{\hb@xt@\hsize}

Oh, well, what's \hb@xt@?

% latex.ltx, line 784:
\def\hb@xt@{\hbox to}

So \centerline{text} is the same as typing

\hbox to \hsize{\hss text\hss}

which has some peculiar properties:

  1. It doesn't start horizontal mode
  2. The text inside is not wrapped
  3. If the text inside is wider than \hsize (the current width for typesetting paragraphs), it will stick out in the margins by the same amount at left and right.
Related Question