4

As a beginner to LaTeX, I would like to know if this is a junk preamble.

\documentclass[a4paper,12pt]{report}
\renewcommand{\baselinestretch}{1.5}
\usepackage[margin=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage[english]{babel}
\usepackage[backend=biber,style=apa, maxcitenames=3]{biblatex}
\addbibresource{references.bib}
\usepackage{longtable}
\usepackage{setspace}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usepackage{pgfplotstable}
\pgfplotsset{height=7cm,width=10cm, compat=newest}
\usepackage{caption}
\usepackage[singlelinecheck=false]{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage {graphicx}
\graphicspath{{./unknown/}}
\usepackage{url}
\usepackage{amssymb}
\usepackage{tikz,setspace}
\usetikzlibrary{arrows.meta,
                decorations.pathreplacing,
                    calligraphy,
                positioning}
\usepackage{pdflscape}                
\usepackage{amsmath}
\usepackage{enumitem} 
\usetikzlibrary{shapes,positioning,arrows}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[RO,LE]{Thesis Title}
\fancyfoot{}
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[LO,CE]{Chapter \thechapter}
\fancyfoot[CO,RE]{Author Name}
epR8GaYuh
  • 2,432
PietroP
  • 105
  • 8
    That depends on your needs. For example many packages are loaded several times here. IMO it is better to learn to understand what these packages does and thus if you really need them. A good idea as a beginner is to write a short comment above each package as a reminder as to what this package does. That makes it easier to asses if this is something you actually need – daleif Jun 01 '21 at 15:02
  • Thank you. Which packages for example? – PietroP Jun 01 '21 at 15:09
  • Check for yourself, fx caption, setspace,. The baseline stretch is probably also quite excessive – daleif Jun 01 '21 at 15:14
  • Thank you. I see that you understand about this. What are the possible consequences of a junk preamble? – PietroP Jun 01 '21 at 15:17
  • 5
    \usepackage{caption}\usepackage[singlelinecheck=false]{caption} is a bit suspicious: Packages should only be loaded once. Loading the same package multiple times can lead to errors (the well-known option clash) and can confuse people looking at the code as to which line is relevant. The \renewcommand{\baselinestretch}{1.5} might not be the best idea (you load setspace, so you might as well use that directly instead of \baselinestretch) https://tex.stackexchange.com/q/373555/35864. – moewe Jun 01 '21 at 15:17
  • 12
    My suggestion is to always start with a minimal preamble: nothing apart your documentclass and maybe \usepackage[T1]{fontenc} for pdflatex. Nothing more. Start writing and add packages only when the need arises. That way you will a) avoid incompatibilities b) learn what each package that you use is doing. – Rmano Jun 01 '21 at 15:18
  • 2
    That said, you should only load packages you need. We can't tell from the outside if you actually need all the packages you load, this is something you'd need to check. Ideally you start with a very, very simple preamble and add only packages you need. – moewe Jun 01 '21 at 15:20
  • always start from an empty preamble and just add packages as you need them. Loading tikz for example is "junk" and seriously slows down the startup time if you don't have any tikz. Of course if you do have tikz then it is needed. – David Carlisle Jun 01 '21 at 15:35
  • also your geometry settings look suspicious, do you really want a text block that wide? – David Carlisle Jun 01 '21 at 15:37
  • @DavidCarlisle thank you. This geometry is due to institutional (University) requirements. – PietroP Jun 01 '21 at 15:40
  • @moewe thank you. – PietroP Jun 01 '21 at 15:41
  • @Rmano thank you. Is the documentclass wrong? Why to use \usepackage[T1]{fontenc} for pdflatex? – PietroP Jun 01 '21 at 15:43
  • Really? wow requirements not set by your institution's typography department clearly:-) Those lines are painfully long to read. Still you have to do what you have to do. – David Carlisle Jun 01 '21 at 15:44
  • Putting in google: "Why to use \usepackage[T1]{fontenc}", first hit: https://tex.stackexchange.com/questions/664/why-should-i-use-usepackaget1fontenc – Rmano Jun 01 '21 at 15:53
  • @DavidCarlisle reports for project evaluation I am reviewing now (from Italian Ministry) are full-size A4 landscape in font 9pt. Non-reflowable PDF (well, without tricks ,-)) – Rmano Jun 01 '21 at 15:58
  • You get the documentation of nearly any package with texdoc packagename (type this on a command line). – Keks Dose Jun 02 '21 at 12:18

1 Answers1

40

Any preamble that you have copied without understanding is a junk preamble.

This is a broad-brush slogan and not always 100% true, but it’s a good principle to start from. If you’ve got such a preamble that works well for you, that’s great — here’s a quick checklist for how to spend a little time (20 minutes max) turning it into a better preamble that you do (mostly) understand:

  • For each package loaded, and each command (or group of commands) defined, you want to work out what it does, and whether you really need it.

  • For a package: to find out what it does, look it up by name on CTAN; this will give a quick summary paragraph of description, plus a links to more detailed documentation, including usually at least a user guide. E.g. the first package your preamble loads is longtable, which “allows tables to flow over page boundaries”, plus providing a few other table-related improvements. Is this something you expect to use? If not, you can take it out for now, and put it back in if you need it later.

  • For both packages and (groups of) commands: if you’re unsure what difference they make, try removing them and recompiling the document, to see what changes appear or what errors occur.

  • If the preamble defines major specialised functionality that you know you want (e.g. for writing a CV or an exam), then you probably shouldn’t aim to change it too much until you’re more experienced and confident — but it’s still worth spending the time trying to understand what each part does.

  • If you’re just writing an ordinary article, then you probably don’t need most of what’s in there — it’s probably just accumulated cruft providing the particular features that its original writer wanted or needed in their papers. So in this case: Duplicate your paper, and cut out any parts of the preamble whose purpose you’re not sure of. Cut packages/commands out gradually — a few at a time — and recompile after removing each group. If you get an error, or an undesired change in output, then you know you were making use of something from that group, so try restoring them individually until you know what you really needed.

  • An alternative approach is to start with nothing in your preamble apart from the essential document setup (\documentclass, \title, etc), and then when you find yourself missing some feature you liked from the preamble you were using, try to work out which package/command(s) gave that feature, and add it to your new version.

  • When you’ve understood what some package or group of commands does, it may be useful to add a comment by them for future reference, noting which particular feature(s) you wanted them for — e.g. \usepackage{mathtools} % for \coloneqq and extensible arrows.

Congratulations! Now everything in your preamble is there because you know (roughly) what it does and you’ve decided you need or want it. Even if it’s exactly the same as when you started, it’s no longer a junk preamble!