# Packages not working together

I have a problem with compiling a LaTeX document into PDF.

The code itself seems to be correct, as it compiles smoothly at sharelatex.com, but it doesn't work on my computer (I am using TeXstudio).

The problem seems to come from the fact that me and other people sharing the document have copied some \usepackage commands we typically use, which don't work together. The errors are

undefined control sequence

and

package error: this package cannot be used in cooperation with others

The problem seems to concern all the packages as I try to remove some of them at random. The packages I use are:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{color}
\usepackage{color,soul}
\usepackage{subcaption}
\usepackage{amsmath}
\usepackage{float}
\usepackage{mathtools}
\usepackage{array}
\usepackage[titletoc]{appendix}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[top=1in, bottom=1.25in, left=1.00in, right=1.00in]{geometry}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{multirow}
\usepackage{titling}
\usepackage{url}
\usepackage{subcaption}
\usepackage{hyperref}
\usepackage[english]{babel}

\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,

}
\usepackage{graphicx}
\usepackage{bm}

\makeatletter
\setlength{\@fptop}{0pt}
\makeatother

\usepackage{tabularx}
\usepackage[toc,page]{appendix}
\usepackage{booktabs}

\usepackage{caption}
\captionsetup{justification=centering}

\usepackage{array}
\usepackage{paralist}
\usepackage{verbatim}
\usepackage{subfig}
\usepackage{fancyhdr}
\usepackage{blindtext}

\pagestyle{fancy}
\lfoot{}\cfoot{\thepage}\rfoot{}

\usepackage{sectsty}
\allsectionsfont{\sffamily\mdseries\upshape}

\usepackage{listings}
\usepackage[nottoc,notlof,notlot]{tocbibind}
\usepackage[titles,subfigure]{tocloft}
\renewcommand{\cftsecfont}{\rmfamily\mdseries\upshape}
\renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape}

\usepackage{natbib}
\bibliographystyle{apalike}


What can I do to make it work?

• You should not use subcaption and subfig together. Remove one of them and use always the other one. And you load several packages more than once. It would be better to avoid this. – Schweinebacke Jan 11 '17 at 12:13
• Only use the packages you need for a specific document, don't randomly collect them. Don't load them multiple times and pay attention to the order. Things like hyperref should be loaded towards the end, babel near the beginning. – user36296 Jan 11 '17 at 12:14
• For suggestions of other collectibles see tex.stackexchange.com/a/326170/36296 – user36296 Jan 11 '17 at 12:25

You load geometry twice with different options, not a good idea.
You load appendix twice with different options, not a good idea.