[Tex/LaTex] How to fix text alignment

errorshorizontal alignmenttext;titlestitling

Update2:

Never mind, i made the mistake of including a extra \begin{center}. removing it fixed the problem.

Update on Thorbjørns solution

I did not manage to get it working.

When i include the pretitle, it works, but the sharelatex marks evrything in red like this enter image description here
I recive the following errors:

Extra }, or forgotten \endgroup.
\maketitle ...\@bspretitle \@title \@bsposttitle }
                                                   \maketitlehookb {\@bsprea...
l.48 \maketitle

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.
 main.tex, line 48
LaTeX Error: \begin{center} on input line 48 ended by \end{titlepage}.
See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...     

.
l.48 \maketitle

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.
 main.tex, line 69
LaTeX Error: \begin{titlepage} on input line 48 ended by \end{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...   

.
l.69 \end{document}

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.
 main.tex
Package Fancyhdr Warning: \headheight is too small (52.16212pt): Make it at least 104.08003pt. We now make it that large for the rest of the document. This may cause the page layout to be inconsistent, however.

Here is my updated code:

\documentclass[11pt,a4paper,titlepage]{article}
%packs
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[demo]{graphicx}
\usepackage{fourier}
\usepackage{titling}
\usepackage{fancyhdr}
\usepackage[margin=1in,headsep=.2in]{geometry}
\usepackage{subfig}
\usepackage[export]{adjustbox}
\usepackage{subfiles}
\usepackage{rotating}
\usepackage{relsize}
\usepackage{mathtools}
\pagestyle{fancy}


\date{\today}
\author{Peter Sloth Mierzwa, S154194  \qquad \qquad \qquad Jakob Will Iversen S143262}
\title{Kursusopgave 5, 62738 Digital signalbehandling E16 }

%headers and footers
\rhead{\includegraphics[width=3cm]{pics/DTUlogo.png}}
\lhead{Peter Sloth Mierzwa S154194, Jakob W. Iversen S143262}
\renewcommand{\headrulewidth}{2pt}
\setlength{\headheight}{52.16212pt}

%
\pretitle{\begin{center}\Large}
\posttitle{%
  \begin{center}
  \begin{minipage}[b]{0.4\textwidth}
    \includegraphics[width=6cm]{pics/UserPicture.png}
  \end{minipage}
  \qquad
  \begin{minipage}[b]{0.4\textwidth}
    \includegraphics[width=6cm]{pics/UserPicture2.png}
  \end{minipage}
  \end{center}
}




\begin{document}
\maketitle
\tableofcontents
\clearpage

\subsection{Digital to Analog}

This is correct

\subsubsection{Teori}
\begin{figure}[!h]
\centering\includegraphics[width=7cm,height=7cm]{pics/DSP/DAC/R2R-schematic.png}
\caption{R2R diagram}%
\label{fig:R2R-diagram}
\end{figure}


Figur \ref{fig:R2R-diagram} This text is indented with the normal paragraph indent.
Make it long enough to wrap to the next line and you'll see that.

\subsection{test}
This is correct
\end{document}

EDIT:

I updated the question with a minimal edition

My code looks like this:

\documentclass[11pt,a4paper,titlepage]{article}
%packs
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{fourier}
\usepackage{titling}
\usepackage{fancyhdr}
\usepackage[margin=1in,headsep=.2in]{geometry}
\usepackage{subfig}
\usepackage[export]{adjustbox}
\usepackage{subfiles}
\usepackage{rotating}
\usepackage{relsize}
\usepackage{mathtools}

\pagestyle{fancy}


\date{\today}
\author{}
\title{Kursusopgave 5, 62738 Digital signalbehandling E16 }

%headers and footers
%\rhead{\includegraphics[width=3cm]{pics/DTUlogo.png}}
\lhead{}
\renewcommand{\headrulewidth}{2pt}
\setlength{\headheight}{52.16212pt}

%
\posttitle{%
  \begin{center}
  \begin{minipage}[b]{0.4\textwidth}
    %\includegraphics[width=6cm]{pics/UserPicture.png}
  \end{minipage}
  \qquad
  \begin{minipage}[b]{0.4\textwidth}
    %\includegraphics[width=6cm]{pics/UserPicture2.png}
  \end{minipage}
  \end{center}
}


\begin{document}

\maketitle
\clearpage

\subsection{Digital to Analog}

This is correct

\subsubsection{Teori}
\begin{figure}[!h]
\centering\includegraphics[width=7cm,height=7cm]{pics/DSP/DAC/R2R-schematic.png}
\caption{R2R diagram}%
\label{fig:R2R-diagram}
\end{figure}


Figur \ref{fig:R2R-diagram} This text is wierd

\subsection{test}
This is correct
\end{document}

and it produces a result like this

enter image description here

Original question

I am writing my first assignment in LaTeX, but I encountered some problems.

I feel like I can't control the text alignment, if you look at the picture below, you will see that the text has a different margin than in the other sections.

Further more, if I choose to do a linebreak myself it makes some weird alignment too, as seen in the second picture.

I've included the code for the first picture at the end of the post.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     DAC     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\clearpage

\subsection{Digital to Analog}

DAC'en skal omsætte et digitalt signal til et analogt signal. Her kommer et eksempel på et sådant kredsløb

\subsubsection{Teori}
\begin{figure}[!h]
\center{\includegraphics[width=7cm,height=7cm]{pics/DSP/DAC/R2R-schematic.png}}
\caption{R2R diagram}
\label{fig:R2R-diagram}
\end{figure}

Figur \ref{fig:R2R-diagram} viser et diagram over en 3-bit DAC opbygget efter R2R princippet.

Systemet giver en spænding mellem $0$ til $\sim5V$. For hver bit der bliver trukket høj, stiger 
spændingen.

MSB giver den største spænding (cirka $50\%$ af max), mens LSB giver den mindste spændings 
ændring. Udgangen svarer til summen af alle tændte bits.

EDIT:

Additionally i have 3 warnings in my document that might be playing a role.

Extra }, or forgotten \endgroup.
\maketitle ...\@bspretitle \@title \@bsposttitle }
                                                   \maketitlehookb {\@bsprea...
 l.52 \maketitle
                 I've deleted a group-closing symbol because it seems to be spurious, as in `$x}$'. But perhaps the } is legitimate and you
 forgot something else, as in `\hbox{$x}'. In such cases the way to
 recover is to insert both the forgotten and the deleted material,
 e.g., by typing `I$}'.


 LaTeX Error: \begin{center} on input line 52 ended by \end{titlepage}.
 See the LaTeX manual or LaTeX Companion for explanation. Type  H
 <return>  for immediate help.  ... 

.

l.52 \maketitle
Your command was ignored. Type  I <command> <return>  to replace it with another command, or  <return>  to continue without
it.



LaTeX Error: \begin{titlepage} on input line 52 ended by
 \end{document}. See the LaTeX manual or LaTeX Companion for
 explanation. Type  H <return>  for immediate help.  ..

.

l.110 \end{document}
Your command was ignored. Type  I <command> <return>  to replace it with another command, or  <return>  to
continue without it.

Line 51-53 looks like this

 \begin{document} 
\maketitle 
\tableofcontents

Best Answer

Seems that when you have a \posttitle you must have a \pretitle as well.

As ebo mentioned in a comment, the text isn't weird, it's just indented with the standard paragraph indentation. Paragraphs that start right after a section heading isn't indented by default. I would recommend keeping paragraph indentation. If you really don't want it, but instead prefer to have some vertical space to indicate the start of a new paragraph, add \usepackage{parskip}.

Also, you had loaded amsmath three times (mathtools loads amsmath), which isn't necessary.

Note that in the code below I added [demo] as an option to the graphicx package, as I don't have the images. You'll need to remove that.

\documentclass[11pt,a4paper,titlepage]{article}
%packs
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[demo]{graphicx}
\usepackage{fourier}
\usepackage{titling}
\usepackage{fancyhdr}
\usepackage[margin=1in,headsep=.2in]{geometry}
\usepackage{subfig}
\usepackage[export]{adjustbox}
\usepackage{subfiles}
\usepackage{rotating}
\usepackage{relsize}
\usepackage{mathtools}

\pagestyle{fancy}


\author{}
\title{Kursusopgave 5, 62738 Digital signalbehandling E16 }

%headers and footers
%\rhead{\includegraphics[width=3cm]{pics/DTUlogo.png}}
\lhead{}
\renewcommand{\headrulewidth}{2pt}
\setlength{\headheight}{52.16212pt}

%
\pretitle{\begin{center}\Large}
\posttitle{%
  \par\medskip\begin{minipage}[b]{0.4\textwidth}
    \includegraphics[width=6cm]{pics/UserPicture.png}
  \end{minipage}
  \qquad
  \begin{minipage}[b]{0.4\textwidth}
    \includegraphics[width=6cm]{pics/UserPicture2.png}
  \end{minipage}
  \end{center}
}


\begin{document}

\maketitle
\clearpage

\subsection{Digital to Analog}

This is correct

\subsubsection{Teori}
\begin{figure}[!h]
\centering\includegraphics[width=7cm,height=7cm]{pics/DSP/DAC/R2R-schematic.png}
\caption{R2R diagram}%
\label{fig:R2R-diagram}
\end{figure}


Figur \ref{fig:R2R-diagram} This text is indented with the normal paragraph indent.
Make it long enough to wrap to the next line and you'll see that.

\subsection{test}
This is correct
\end{document}