2

I'm at that stage in my thesis where anything is a distraction, right now it's cleaning my tex preamble, my document layout is pretty much as perfect as I could want it. Any suggestions to use a "cleaner" code would be appreciated. This is my first document I wrote using latex.

%----------------------------------------------------------------------------------------
%   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[11.5pt]{report} % Change font size here
\usepackage[margin=2.5cm]{geometry} % Change margins to 2.5cm on all sides
\geometry{a4paper} % Set the page size to be A4 
\usepackage{graphicx} % Required for including pictures
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float} % Allows putting an [H] in \begin{figure} to specify the exact location of the figure
\usepackage{wrapfig} % Allows in-line images
\graphicspath{{../figures/}}  % Specifies the directory where pictures are stored
\usepackage[T1]{fontenc}
\usepackage{newtxmath,newtxtext} %times new roman font
\usepackage[utf8]{inputenc} % Unicode Characters
\linespread{1.2} % Line spacing\frac{(\overline{w'c'})
\usepackage[hyphenbreaks]{breakurl}
\usepackage[hyphens]{url}

%used to center the chapter headings and decrease the space before and after the heading which is unreasonable in the normal setting
\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}
  {\chaptertitlename\ \thechapter}{-5pt}{\huge}
  \titlespacing*{\chapter}{0pt}{-50pt}{10pt} 

\usepackage[colorlinks=true,urlcolor=blue,citecolor=blue,linkcolor=black,bookmarks=true,pagebackref]{hyperref} % makes color citations
\renewcommand{\backrefxxx}[3]{%
  (\hyperlink{page.#1}{$\uparrow$#1})} %this is to add backref from bib to text, used with pagebackref^

\usepackage[sort&compress,round,semicolon,authoryear]{natbib}
\usepackage{siunitx}
\usepackage{gensymb}
\usepackage{pdfpages}
\usepackage{tabularx}
\usepackage{glossaries}
\usepackage{bookmark}
\setcounter{secnumdepth}{0} % only number chapters 
\usepackage[linguistics]{forest} % to create pretty diagrams
\usepackage[nottoc,numbib]{tocbibind}
\usepackage{tikz-qtree}
\usepackage{minitoc}
\usepackage{tocloft}
\setlength\cftparskip{0pt}
\setlength\cftbeforechapskip{0pt}


\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3pt plus 1pt minus 1pt}{1ex plus .2ex}

\usetikzlibrary{arrows.meta}
\tikzset{
  my rounded corners/.append style={rounded corners=2pt},
}
\colorlet{linecol}{black!75}
\setcounter{tocdepth}{1}

\bookmarksetup{
  numbered,
  open
}

\setlength{\parindent}{0pt}
\setlength{\parskip}{0.5em}
\setlength{\cftbeforetoctitleskip}{0pt}
\setlength{\cftbeforeloftitleskip}{0pt}
\setlength{\cftbeforelottitleskip}{0pt}

%\renewcommand*{\thesection}{\arabic{section}}

% document begin
\begin{document}

%----------------------------------------------------------------------------------------
%   Title page
%----------------------------------------------------------------------------------------
\pagenumbering{Roman}
\input{../1titlepage&abstract/titlepage.tex}
\thispagestyle{empty}

%----------------------------------------------------------------------------------------
%   Declaration
%----------------------------------------------------------------------------------------
\input{../2preface&acknowledgements/declaration.tex}
\thispagestyle{empty}
\newpage

%----------------------------------------------------------------------------------------
%   Abstract
%----------------------------------------------------------------------------------------
\input{../1titlepage&abstract/abstract.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Dedication
%----------------------------------------------------------------------------------------
\input{../2preface&acknowledgements/dedication.tex}
\thispagestyle{empty}
\newpage

%----------------------------------------------------------------------------------------
%   Preface
%----------------------------------------------------------------------------------------
\input{../2preface&acknowledgements/preface.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Table of contents
%----------------------------------------------------------------------------------------
\pagenumbering{roman}
\tableofcontents % Include a table of contents
\addtocontents{toc}{~\hfill\textbf{Page}\par}
\newpage % Begins the essay on a new page instead of on the same page as the table of contents 

%----------------------------------------------------------------------------------------
%   List of Figures
%----------------------------------------------------------------------------------------
\listoffigures
\addtocontents{lof}{~\hfill\textbf{Page}\par}
\newpage

%----------------------------------------------------------------------------------------
%   List of Tables
%----------------------------------------------------------------------------------------
\listoftables
\addtocontents{lot}{~\hfill\textbf{Page}\par}
\newpage

%----------------------------------------------------------------------------------------
%   List of Abbreviations
%----------------------------------------------------------------------------------------
%\makeglossaries
%\input{../glossaries/glossaries.tex}
%\printglossaries
%\newpage

%----------------------------------------------------------------------------------------
%   Section: Introduction and background
%----------------------------------------------------------------------------------------
\input{../3background&introduction/background&introduction.tex} 

%----------------------------------------------------------------------------------------
%   Subsection: Aims, Objectives and Layout
%----------------------------------------------------------------------------------------
\input{../5aims&objectives/aims&objectives.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Study Area, Data & Methods
%----------------------------------------------------------------------------------------
\input{../4data&methods/data&methods.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Objective1
%----------------------------------------------------------------------------------------
\input{../6objective1/objective1.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Obejctive2
%----------------------------------------------------------------------------------------
\input{../7objective2/objective2.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Obejctive3
%----------------------------------------------------------------------------------------
\input{../8objective3/objective3.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Conclusion
%----------------------------------------------------------------------------------------
\chapter{Conclusion} % Major section
\label{ch:conclusion}
\newpage

%----------------------------------------------------------------------------------------
%   Bibliography
%----------------------------------------------------------------------------------------
\bibliographystyle{agsm}%Choose a bibliograhpic style
\renewcommand{\bibpreamble}{$\uparrow$ refers back to in text citations}
\bibliography{../bibliography/master}
\label{sec:bib}

%----------------------------------------------------------------------------------------

\end{document}

excuse all the notes I made for myself.

EDIT: I accepted user124577 answer, however, I realize that there is more than one way one could go about organizing the preamble. I really did not expect all the helpful feedback so quickly. I can honestly count the number of people on my hand who use latex at my university, this site has been god send in me actually understanding latex without much other support.

  • 1
    First of all a4paper is a geometry option, secondly you should put graphicspath and \linespread after loading packages (just for logic). Then I would try to group you packages logically (e.g. url, breakurl and hyperref at one place). But we cannot help you reducing unnecessary packages (reasons should be clear). – TeXnician Feb 8 '17 at 7:29
  • 1
    +1 for I'm at that stage in my thesis where anything is a distraction: I think we are many here in the same situation! – CarLaTeX Feb 8 '17 at 7:38
  • 2
    You should load hyperref as late as possible. If you use par skip instead of indent with a standard class, package parskip is recommended (see the manual for the reasons). Standard class report does not know option 11.5pt. This will result in 10pt. (See LaTeX Warning: Unused global option(s): [11.5pt]. in the log-file). – Schweinebacke Feb 8 '17 at 7:43
  • 1
    \documentclass[11.5pt]{report} % Change font size here report does not have an 11.5pt option you presumably get a warning about that? use 11pt. (the size options are 10pt, 11pt or 12pt) – David Carlisle Feb 8 '17 at 8:03
  • 1
    titlesec, tocloft and minitoc is a very nice combination .... /irony ;-) – user31729 Feb 8 '17 at 9:28
3

Maybe just as an untested summary of the comments (feel free to edit and add):

\documentclass[11pt]{report} % Change font size here
\usepackage[a4paper,margin=2.5cm]{geometry} % Change margins to 2.5cm on all sides

%% language, input and output options
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % Unicode Characters
\usepackage{newtxmath,newtxtext} %times new roman font

%% graphics and float packages
\usepackage{graphicx} % Required for including pictures
\usepackage{wrapfig} % Allows in-line images
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float} % Allows putting an [H] in \begin{figure} to specify the exact location of the figure
\graphicspath{{../figures/}}  % Specifies the directory where pictures are stored

%% inclusion of other packages
\usepackage[sort&compress,round,semicolon,authoryear]{natbib}
\usepackage{siunitx}
\usepackage{gensymb}
\usepackage{pdfpages}
\usepackage{tabularx}
\usepackage{glossaries}
\usepackage{tocloft}
\usepackage[linguistics]{forest} % to create pretty diagrams
\usepackage[nottoc,numbib]{tocbibind}
\usepackage{tikz-qtree}

%% setup titles and sectioning
\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}
  {\chaptertitlename\ \thechapter}{-5pt}{\huge}
  \titlespacing*{\chapter}{0pt}{-50pt}{10pt}     
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3pt plus 1pt minus 1pt}{1ex plus .2ex}

%% setup tikz, bookmarks, colors
\colorlet{linecol}{black!75}
\usetikzlibrary{arrows.meta}
\tikzset{
  my rounded corners/.append style={rounded corners=2pt},
}

%% modify links
\usepackage[hyphenbreaks]{breakurl}
\usepackage[hyphens]{url}
\usepackage[colorlinks=true,urlcolor=blue,citecolor=blue,linkcolor=black,bookmarks=true,pagebackref]{hyperref} % makes color citations
\renewcommand{\backrefxxx}[3]{%
  (\hyperlink{page.#1}{$\uparrow$#1})} %this is to add backref from bib to text, used with pagebackref
\usepackage{bookmark}
\bookmarksetup{numbered,open}

%% change lengths
\setlength{\parindent}{0pt}
\setlength{\parskip}{0.5em plus 0.2em minus 0.2em}
\linespread{1.2} % Line spacing\frac{(\overline{w'c'})
\setcounter{secnumdepth}{0} % only number chapters
\setcounter{tocdepth}{1}
\setlength{\cftbeforetoctitleskip}{0pt}
\setlength{\cftbeforeloftitleskip}{0pt}
\setlength{\cftbeforelottitleskip}{0pt}
\setlength\cftparskip{0pt}
\setlength\cftbeforechapskip{0pt}

%\renewcommand*{\thesection}{\arabic{section}}

% document begin
\begin{document}

%----------------------------------------------------------------------------------------
%   Title page
%----------------------------------------------------------------------------------------
\pagenumbering{Roman}
\input{../1titlepage&abstract/titlepage.tex}
\thispagestyle{empty}

%----------------------------------------------------------------------------------------
%   Declaration
%----------------------------------------------------------------------------------------
\input{../2preface&acknowledgements/declaration.tex}
\thispagestyle{empty}
\newpage

%----------------------------------------------------------------------------------------
%   Abstract
%----------------------------------------------------------------------------------------
\input{../1titlepage&abstract/abstract.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Dedication
%----------------------------------------------------------------------------------------
\input{../2preface&acknowledgements/dedication.tex}
\thispagestyle{empty}
\newpage

%----------------------------------------------------------------------------------------
%   Preface
%----------------------------------------------------------------------------------------
\input{../2preface&acknowledgements/preface.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Table of contents
%----------------------------------------------------------------------------------------
\pagenumbering{roman}
\tableofcontents % Include a table of contents
\addtocontents{toc}{~\hfill\textbf{Page}\par}
\newpage % Begins the essay on a new page instead of on the same page as the table of contents 

%----------------------------------------------------------------------------------------
%   List of Figures
%----------------------------------------------------------------------------------------
\listoffigures
\addtocontents{lof}{~\hfill\textbf{Page}\par}
\newpage

%----------------------------------------------------------------------------------------
%   List of Tables
%----------------------------------------------------------------------------------------
\listoftables
\addtocontents{lot}{~\hfill\textbf{Page}\par}
\newpage

%----------------------------------------------------------------------------------------
%   List of Abbreviations
%----------------------------------------------------------------------------------------
%\makeglossaries
%\input{../glossaries/glossaries.tex}
%\printglossaries
%\newpage

%----------------------------------------------------------------------------------------
%   Section: Introduction and background
%----------------------------------------------------------------------------------------
\input{../3background&introduction/background&introduction.tex} 

%----------------------------------------------------------------------------------------
%   Subsection: Aims, Objectives and Layout
%----------------------------------------------------------------------------------------
\input{../5aims&objectives/aims&objectives.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Study Area, Data & Methods
%----------------------------------------------------------------------------------------
\input{../4data&methods/data&methods.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Objective1
%----------------------------------------------------------------------------------------
\input{../6objective1/objective1.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Obejctive2
%----------------------------------------------------------------------------------------
\input{../7objective2/objective2.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Obejctive3
%----------------------------------------------------------------------------------------
\input{../8objective3/objective3.tex}
\newpage

%----------------------------------------------------------------------------------------
%   Conclusion
%----------------------------------------------------------------------------------------
\chapter{Conclusion} % Major section
\label{ch:conclusion}
\newpage

%----------------------------------------------------------------------------------------
%   Bibliography
%----------------------------------------------------------------------------------------
\bibliographystyle{agsm}%Choose a bibliograhpic style
\renewcommand{\bibpreamble}{$\uparrow$ refers back to in text citations}
\bibliography{../bibliography/master}
\label{sec:bib}

%----------------------------------------------------------------------------------------

\end{document}
  • Thank you, maybe I can add that I had to move '\usepackage[colorlinks=true,urlcolor=blue,citecolor=blue,linkcolor=black,bookmarks=true,pagebackref]{hyperref} % makes color citations \renewcommand{\backrefxxx}[3]{% (\hyperlink{page.#1}{$\uparrow$#1})' above '\usepackage{bookmark}' – Padawan Feb 8 '17 at 8:32
  • @Padawan I've improved it. – TeXnician Feb 8 '17 at 8:35
  • I removed ` \usepackage{minitoc} ` after your comment :). – Padawan Feb 8 '17 at 8:39
  • Summarising comments (including ones from other people) into an easily editable answer would be a prime candidate for a community wiki answer, see stackoverflow.com/help/privileges/community-wiki for details. – user36296 Feb 8 '17 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.