[Tex/LaTex] Article class geometry margins

geometrymarginstitlesec

Question still unanswered

I am trying to set up margins equal to 2.5cm all around the document.
With use of geometry (and fancyhdr) package which is:

\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.50cm]{geometry}

However i have noticed that by default top and bottom margins are slightly bigger than the left and right. Why is it like that and how to fix it?

Thus how to make those margins (all of them) identical and equal to 2.5cm?

My entire code is:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\newcommand*{\savedfootnotes}{}
\newcommand*{\resetsavedfootnotes}{\global\let\savedfootnotes\empty}
\newcommand{\tablefootnote}[1]%
{%
    \footnotemark
    \xdef\savedfootnotes%
    {\unexpanded\expandafter{\savedfootnotes}\noexpand\footnotetext{#1}}%
}
\edef\endtable%
{%
    \aftergroup\noexpand\savedfootnotes
    \aftergroup\noexpand\resetsavedfootnotes
    \unexpanded\expandafter{\endtable}%
}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lastpage}
\usepackage{titling}
\usepackage{array}
\usepackage{titlesec}
\usepackage{bibentry}
 \nobibliography*
\usepackage{tocloft}
 \usepackage{titling}
\newcommand{\subtitle}[1]{%
    \posttitle{%
        \par\end{center}
    \begin{center}\large#1\end{center}
    \vskip0.5em}%
}

\renewcommand\cftsecfont{\normalfont}
\renewcommand\cftsecpagefont{\normalfont}
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}
\renewcommand\cftsecdotsep{\cftdot}
\renewcommand\cftsubsecdotsep{\cftdot}
\usepackage{cite}
\usepackage{fancyhdr}
\usepackage[pdftex,
pdfauthor={},
pdftitle={}]{hyperref}
%
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}

 \linespread{1.5}
\fancyhf{}

\renewcommand{\headrulewidth}{0pt} 
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.50cm]{geometry}

\pagestyle{fancy}
\cfoot{ \thepage}
\setlength{\droptitle}{5cm}
\setlength\parindent{1cm}

\makeatletter
\renewcommand\thesection{}
\renewcommand\thesubsection{\@arabic\c@section.\@arabic\c@subsection}
\makeatother

\titlespacing*{\section}
{2.5cm}{0 pt}{1.5 pt}
\titlespacing*{\subsection}
{2.5cm}{1.5 pt}{1.5 pt}

\setcounter{section}{-1}


\begin{document}
    \pagenumbering{gobble}


\pagenumbering{arabic}
\setcounter{page}{0}
\thispagestyle{empty}
\clearpage

title page


\newpage
\tableofcontents
\newpage
\section{\hfil 0 \hfil}
\newpage


\section{\hfil 1 \hfil}



\section{\hfil Bib \hfil}
\nocite{*}

\begingroup
\renewcommand{\section}[2]{}
\bibliographystyle{plain}
\bibliography{bibl2}

\endgroup
\newpage

\end{document}

Entire page looks like that:
enter image description here

At the top of it i have 0.1 inches more that on the left hand side. I want to have 1inch everywhere


Edit by touhami

Following comments it seems that the question is how to remove the gap between the frame and section title (this is related to titlesec)

\documentclass[12pt,a4paper]{article}
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.50cm,showframe]{geometry}

\usepackage{titlesec}

\usepackage{mwe}% just for the example

\linespread{1.5}

\begin{document}
\blinddocument
\end{document}

Best Answer

A solution is to not use titlesec. One can replace the stuff of this package i.e.

\usepackage{titlesec}

and

\titlespacing*{\section}
{2.5cm}{0 pt}{1.5 pt}
\titlespacing*{\subsection}
{2.5cm}{1.5 pt}{1.5 pt}

with

\makeatletter 
\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-1sp \@plus -1pt \@minus -.2pt}%
                                   {1.5pt \@plus .2pt}%
                                   {\normalfont\Large\bfseries}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-1.5pt \@plus -1pt \@minus -.2pt}%
                                     {1.5pt \@plus .2pt}%
                                     {\normalfont\large\bfseries}}
\makeatother

MWE

\documentclass[12pt,a4paper]{article}
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.50cm,showframe]{geometry}

\usepackage{mwe}% just for the example


\makeatletter 
\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-1sp \@plus -1pt \@minus -.2pt}%
                                   {1.5pt \@plus .2pt}%
                                   {\normalfont\Large\bfseries}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-1.5pt \@plus -1pt \@minus -.2pt}%
                                     {1.5pt \@plus .2pt}%
                                     {\normalfont\large\bfseries}}
\makeatother

\linespread{1.5}

\begin{document}
\section{lipsum foo}
\lipsum[1]
\section{lipsum foo}
\lipsum[1]
\subsection{lipsum foo}
\lipsum[1]
\end{document}

enter image description here