Tag Archives: Latex

LaTeX Error: Can be used only in preamble

LaTeX Error: Can be used only in preamble
translation: Xovee
translation time: June 11, 2020
LaTeX Error: Can be used only in preamble
This error occurs if you introduce a package or class in the body of the text, rather than in the preamble. Before the command \begin{document}, everything is called a prologue. In the prologue, you define the type of document, the language of the document, and many basic Settings. For example, the preface to a general document looks something like this:

\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\title{First document}
\author{Hubert Farnsworth \thanks{funded by the ShareLaTeX team}}
\date{February 2014}

If you introduce the package in the body (after \begin{document}) instead of in the preface, you will get this error:

To resolve this error, you must ensure that all packages introduce the command \usepackage{… }, and \ documentClass []{… }, before the \begin{document} command. If you want to learn more about LaTeX document structure, please refer to this document.

Solve the problem: Something’s wrong–perhaps a missing \item. \end{thebibliography}

Sometimes when we compile papers with latex, we encounter problems related to BIB, as follows:
Something’s wrong–perhaps a missing \item. \end{thebibliography}
The same latex documents are fine to compile in Windows but not on MAC.
The underlying problem is the *.bbL file in the directory where *.tex resides. This file is handled differently on Windows and MAC. When there are no references in the article, Windows compiles, but MAC does not.
So here’s the solution:
(1) First close *.tex file, and then delete *.bbL file;
(2) Open *.tex file and add the statement \ {*} anywhere in the article;
(3) Compile again, there is no problem.

[latex] latex adjust row spacing

we usually use two kinds of units to adjust the line spacing in word, one is single spacing , 1.5 times spacing, 2 times spacing, etc., and the other is USES “pounds” for setting, I generally do not like to use single spacing when writing documents, I think the 22 pound spacing is the most appropriate, looks the most comfortable.

today when I was editing my paper with latex, I wanted to adjust the line spacing in the LLNCS template, so I summarized both approaches, but before I could use them, I had to introduce the package file: \usepackage{setspace} :

1) \ renewcommand {\ baselinestretch} {1.0}

can be understood as what I just used in word, one is to adjust the single spacing, 1.5 times the spacing, 2 times the spacing, etc..

2) \ setlength {\ baselineskip} {20 pt}
First of all, we need to know several common unit conversions of LaTeX:

We often see the units of length used by LaTeX, in, em, and so on.
LaTeX the length of the support units are:

  • in inches (inch)
  • mm mm (millimeters)
  • cm (centimeters)
  • pt points (approximately 1/72 inch) em-
  • 0 1 ex – 2 Approximately the height of an “x” in the current font

length can also be negative, such as 1.5 em. notice the number 0 itself is not a length, must show is 0 in or 0 pt, etc.

and “pounds” is a measure of the size of a print, which is about one seventy-two inches. While 1 inch = 25.4 mm, 1 pound = 25.4/72≈0.353 mm. The pounds agree with LaTeX’s Pt-points (about 1/72 inch).

so this can be roughly equal to the “pounds” in wor units.