[Tex/LaTex] How to center the title

titlesvertical alignment

How do I center the title?

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{setspace}
\usepackage[colorlinks,citecolor=blue,urlcolor=blue,linkcolor=black]{hyperref}
\usepackage{hypernat}

\usepackage{caption}
\usepackage{subcaption}
\usepackage{pdflscape}

\usepackage{afterpage}
\usepackage{xcolor}

\usepackage{verbatim}

\usepackage[margin=2.5cm]{geometry}
\usepackage{url}
\usepackage{booktabs,caption,fixltx2e}
\usepackage[flushleft]{threeparttable}
\usepackage{setspace}
\usepackage[capposition=top]{floatrow}

\usepackage{float}

\usepackage{rotating}
\usepackage{bm}

\usepackage{tabularx}

\onehalfspacing
\usepackage{graphicx}

\usepackage{subfig}

\renewcommand{\familydefault}{\sfdefault}

\font\titlefont=cmr12 at 40pt

\begin{document}
\pagenumbering{gobble}% Remove page numbers (and reset to 1)

\begin{center}
\color{white}{
  \titlefont 
  {\fontfamily{cmss}\selectfont
   \scalebox{5}{Big Title} 
  }
    \titlefont \\
    \vspace{2cm}
  {\fontfamily{cmss}\selectfont
   \scalebox{2}{Small title} 
  }
  }
\end{center}

\pagecolor{purple}\afterpage{\nopagecolor}

\newpage
\tableofcontents
\end{document}

Best Answer

To center the titles vertically, place the instruction \vspace*{\fill} before \begin{center} and the instruction \vspace*{\fill} after \end{center}.

I think you'd be well advised to simplify and declutter the LaTeX code you employ, as it's currently quite opaque, needlessly complicated, and full of redundancies. Don't load packages more than once, and be sure to load hyperref last. Oh, and as you've probably already discovered, you mustn't load both subcaption and subfig.

I've tried to do a preliminary cleanup in the following version of your code. Do try to go through the preamble carefully and eliminate all packages you don't use at all throughout the document.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm}

\usepackage{setspace}
\onehalfspacing

\usepackage{caption}
\usepackage{subcaption}
\usepackage{pdflscape}

\usepackage{afterpage}
\usepackage{xcolor}
\usepackage{verbatim}

\usepackage[margin=2.5cm]{geometry}
\usepackage[hyphens,spaces]{url} % 'hyphens' and 'spaces' options are very useful
\usepackage{booktabs}

%%,caption}   % no need to load twice
%% ,fixltx2e} % no need to load unless your TeX distribution is *ancient*

\usepackage[flushleft]{threeparttable}

%%\usepackage{setspace} % no need to load twice

\usepackage[capposition=top]{floatrow}
\usepackage{float}

\usepackage{rotating}
\usepackage{bm}

\usepackage{tabularx}
%%\usepackage{graphicx} % is loaded automatically by  'rotating' package

%% Load 'hyperref' package *last*
\usepackage[colorlinks,citecolor=blue,urlcolor=blue,
            linkcolor=black]{hyperref}
%% \usepackage{hypernat} % no need to load unless your TeX distribution is **ancient**

%%\usepackage{subfig}  % conflicts with 'subcaption'

\renewcommand{\familydefault}{\sfdefault}

% ------- end of preamble -------- %

\begin{document}
\pagenumbering{gobble}

\pagecolor{purple}

\vspace*{\fill}
\begin{center}
  \color{white}
  \scalebox{5}{Big Title}\\[2cm]
  \scalebox{2}{Small title}
\end{center}
\vspace{\fill}

\newpage
\nopagecolor 

\tableofcontents   
% remainder of document

\end{document}

enter image description here