In the examples it is assumed a minimal header including the basic mathematical packages
amsmath
,
amsfonts
and
amssymb
.
Namely, the examples have been tested with
\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
Tags: alignment, arrays, arrows, beamer, bibliography, boxes, footnotes, packages, page, paragraphs, spanish, summation, table of contents, templates, types.
Alignment: Odd centering |
---|
The command \stretch(<n>) indicates an undetermined length proportional to n .
This can be used in combination with \hspace to center the content of a line or a box as in this example:
\hspace{\stretch{1}}Centered text\hspace{\stretch{1}}
center but \stretch offers the possibility of some odd centering. For instance,
\hspace{\stretch{2}}Centered text\hspace{\stretch{1}}
center and \stretch is:
\ \vspace does not work.
|
Arrays: maximum number of columns |
---|
By default, the maximum number of columns is 10. This number can be modified changing the counter MaxMatrixCols . For instance,
\setcounter{MaxMatrixCols}{11} MaxMatrixCols is exceeded is strange: Extra alignment tab has been changed to \cr .
|
Arrows: long arrows |
---|
The length of \longrightarrow is fixed. It causes problems to put text or formula over or under it. For instance:
\[ \xrightarrow[...]{...} where the first argument (optional) gives the upper content and the second argument the lower one. Then the previous examples are repaired with:
\[ \xleftarrow with similar structure.
Using \hspace{...} as one of the arguments one can draw very long arrows. For instance A\xleftarrow{\hspace{200pt}}B .
\mapsto and \hookrightarrow . It can be emulated using that \mapstochar and \lhook generate the vertical bar and the hook appearing in these arrows. For instance, we obtain extra large \mapsto and \hookrightarrow with
\[ \joinrel avoids a small space between the hook and the arrow.
|
beamer : numbering |
---|
Sometimes we are using a theme, for instance Warsaw that does not show the number of the slide by default. In this case, it shows in the footer the short title. To add the number of the slide with minimal changes one can redefine \insertshorttitle adding to its definition the number with a very clever trick taken from
here which has broader interest. For the aforementioned problem of numbering, the code to include in the preamble is:
\expandafter\def\expandafter\insertshorttitle\expandafter{% n/N flushed to the right.
|
beamer : shorter blocks |
---|
Sometimes in beamer one needs to horizontally align two blocks or putting an image beside a block. The environment columns allows to define columns of different length without loading extra packages in the class beamer . This is an example of its use:
\begin{columns} |
beamer : verbatim |
---|
To use the environment verbatim in beamer we must start the slide with \begin{frame}[fragile] .
|
Bibliography: BibTeX entry for arXiv |
---|
A possibility for a BibTeX entry for a paper posted in the arXiv is like in this example
@UNPUBLISHED{arXiv:2107.07245, |
Bibliography: BibTeX entry for web material |
---|
A possibility for a BibTeX entry for contents published in the internet is like in this example
@MISC{chamizo, url .
|
Bibliography: BibTeX styles |
---|
The following lines are to use BibTeX with a file bibfile.bib getting the references ordered in the standard way (in mathematics) and numbered
\bibliographystyle{plain} alpha instead of plain that shows alphabetic labels.
There are some other admissible bibliography styles. Many of them are offered by scientific journals and downloadable from their websites.
It seems that the standard extra styles provided by the standard BibTeX are abbrv , acm , apalike , ieeetr , siam and unsrt .
The results are shown in the Overleaf documentation.
|
Bibliography: name |
---|
The variable \refname contains the name of the Bibliography. For instance "References" in the article style. It can be redefined with \renewcommand . The following example does not change the name but adds a footnote:
\renewcommand{\refname}{References\footnote{In the works authored by Euler we follow Enestrom classification.}}
|
Boxes: frames |
---|
The most used command to draw a frame around a part (sentence, word) of a line is \fbox .
The command frame is like \fbox leaving no separation between the content and the frame. It is use to limit images.
For \fbox , the variables \fboxrule and \fboxsep store the thickness of the frame and the separation. As usually, with brackets we give a local validity to the changes in these lengths. An example is
This is a {\setlength{\fboxrule}{2pt}\setlength{\fboxsep}{10pt}\fbox{thick frame}} separated a lot.
\fbox{\vbox{<text>}} .
Another possibility is to use the minipage environment in the form
\fbox{\begin{minipage}{\textwidth}<text>\end{minipage}} .
The command \framebox is more flexible than \fbox .
It has two optional arguments. The first one is the horizontal length of the frame and the second can take the values s , r and l , meaning the alignment spread, right and left.
For instance,
This is \framebox[0.5\textwidth][s]{a short text} for a long frame.
This is \framebox[0.5\textwidth][l]{\hspace{\stretch{1}}a short text\hspace{\stretch{1}}} for a long frame.
|
Boxes: general constructor |
---|
The general command to create a box is
\makebox[width][position]{text} . If the optional arguments are not used, then it works like \mbox{text} . The position can be c for centered (default), s for spread, r for flushright and l for flushleft.
Consider
\makebox[0.5\textwidth][s]{this is the text} Underfull \hbox because the words cannot be spread along half a line without excessive spaces between them. The second form prevents this error. In the third form, the spacing is as usual and the sentence appear centered in the half line.
The length \width is the usual width corresponding to the mandatory argument. For instance, Before\makebox[2\width]{Middle}After assign to Middle double width than usual, leaving extra spacing after and before. Changing 2\width by 0.5\width , the text would overlap with the preceding and next words.
A box of width zero can be useful to introduce text not interfering with the rest and avoiding errors, For instance, with
\noindent\makebox[0em][r]{margin text\ }This paragraph is supposed to take more than a line to see the alignment of the two first lines. There is no indent to make it apparent...
|
Boxes: minipage |
---|
The environment minipage creates a box with the width indicated in its argument. As the name suggests, this box is a special one which shares some properties with a page, namely it may contain paragraphs, footnotes and itemized lists.
A cheap form of including a two-column text in a one-column document is using minipage as in this example:
\noindent c (center, default) t (top) or b (bottom) and indicates the alignment with the surrounding text. For example, with the default option c
Read this $\to$\quad \begin{minipage}[c]{4cm} t it is in front of "Text" and with b , it is in front of bottom.
The second optional argument gives the height of the box. It can be used to leave some space after or before minipage. If it is less than the height of the content then part of the text will overlap with the following paragraph but no error is raised. The last optional argument is again c , t or b and indicates the alignment of the content inside the box. For instance, if in the example with two column we replace the second
\begin{minipage}{0.49\textwidth} by
\begin{minipage}[c][10cm][t]{0.49\textwidth}
then there is a lot of space after the columns and the first column appears in a lower vertical position.
|
Boxes: prevent hyphenation |
---|
With \mbox{} a box is created for its argument with the necessary width. It can be used to to prevent hyphenation because the box is kept in the same line.
|
Boxes: raise |
---|
A box can be raised with \raisebox{h}[l1][l2]{} where h is the height to raise and the optional lengths l1 and l2 are used to cheat LaTeX to pretend that the result extends l1 above the base line and l2 below the base line. For instance, with
\raisebox{-4.0pt}{w}\raisebox{4.4pt}{a}\raisebox{8.0pt}{v}%
\raisebox{0pt}[0pt][0pt]{\raisebox{-4.0pt}{w}\raisebox{4.4pt}{a}\raisebox{8.0pt}{v}% |
Boxes: rules |
---|
A rule is a black filled box. The syntax is \rule[opt]{width}{thickness} The width and the thickness are self-explanatory. The optional argument indicates how much it is raised over the baseline.
With \rule{0.25\textwidth}{8pt}\rule[-2pt]{0.25\textwidth}{8pt}
we get a black line of thickness 8pt along 1/4 of the text width followed by a similar one 2pt below.
It behaves as text and then it is affected by the package xcolor if we want to change color.
|
Boxes: show boxes |
---|
This simple code, which is a simple modification of the second answer here,
\makeatletter \wordboxes{} which shows the boxes associate to a word. It also work for sentences if the spaces are enclosed between brackets. The same rule applies for accents or other composed symbols.
\wordboxes{Hi!} \@tfor loop. In this kind of loops the variable takes as values the elements of a list of tokens.
|
Footnotes: numbering |
---|
The usual numbering of the footnotes can be altered indicating the new number as an optional argument of \footnote . For instance
The first sentence\footnote{First note} To simulate several consecutive calls to the same footnote one can use \footnotemark{\value{footnote}] instead of \footnote after the first call. For instance,
The first sentence\footnote{First block}.
The first sentence1. The second sentence1. The third sentence2. The
fourth sentence2 .
As the previous syntax suggests, footnote is a counter then with \setcounter{footnote}{n} the next footnote will be numbered with n+1 .
|
Footnotes: text in the footer |
---|
Sometimes one wants to put some text in the footer without any mark. A solution is to redefine temporarily \thefootnote as an empty string and decrease footnote by one. For instance,
The first sentence\footnote{First}.
1First
First fake note
Second fake note
1Second
|
Latexdiff |
---|
Latexdiff is a script to compare two LaTeX files giving a third file as output. Apparently it can give some poblems with mathematical formulas.
Two examples of use are:
latexdiff --math-markup="off" -t CFONT old.tex new.tex > diff.tex
latexdiff --math-markup="off" -t BOLD old.tex new.tex > diff.tex
|
Packages: fix-cm to scale fonts |
---|
A quick way of using nonstandard font sizes is to load the package fix-cm (the cm stands for Computer Modern). According to the documentation the orthodox form of loading this package is with \RequirePackage before specifying the class of the document:
\RequirePackage{fix-cm}
\fontsize{60pt}{70pt}\selectfont Very big tex
60pt is the font size and 70pt is the baseline skip. Using brackets to give to the command a local scope does not respect the base line skip. The solution is to finish with \par like this:
{\fontsize{60pt}{70pt}\selectfont Very big tex\par}
|
Packages: fontenc to clean the file name |
---|
The command \jobname shows the name of the file. This can be problematic if it includes underscores. To avoid it, employ \usepackage[T1]{fontenc} .
|
Packages: geometry for the page layout |
---|
Including this package in the preamble followed by \geometry{...} with some parameters, we have a more intuitive control of the page layout.
There is a list of the names of the arguments and their meaning in the
Overleaf documentation
An example taken from there is:
\usepackage{geometry} left is the real left margin, including
1 inch + \hoffset + \oddsidemargin
and, analogusly, top is the rel top margin, form the upper border of the page to the body. The dimensions in total indicate the text area (the body).
|
Packages: graphicx to include an image |
---|
The main command in the package is \includegraphics[options]{filename} . We only discuss the main options through examples. The most usual purpose of the options is to adjust the size of the image. The three examples
\includegraphics[scale = 0.5]{./imag/figs.eps} figs.eps in the folder ./imag . In the first example the image is reduced to one half of its original size. In the second example the height is adjusted to 100pt and the width change accordingly to keep the aspect ratio. The width is specified en the last examples and then the aspect ratio is distorted if different of 1/2.
A rotation can be specified assigning a value, in degrees, to angle . These are some examples:
\includegraphics[height = 100pt, angle = 20]{./imag/figs.eps} figs.eps has the same height and width, the first command generates a bigger figure because we adjust first the height 100pt while with the second command we rotate the figure first and it creates a bigger bounding box whose height is reduced to 100pt.
In the last examples origin specifies the origin of the rotation. By default it is the "reference point" of the box. In a figure typically it is the left lower corner. We have some freedom to change it with two characters, one can be t (top), b (bottom) or c (center) and the other l (left), r (right) or c (center). For instance cc is the center of the figure, which can be abbreviated simply by c (in general a missing character is assumed to be c ) and br is the right lower corner. In this way, in the three last examples the left lower corner is gradually descending.
It is possible to crop an image with the option trim , usually in combination with clip or, equivalently, clip = true . Here there is an example:
\includegraphics[scale = 0.5]{./imag/figs.eps} clip then the bounding box is trimmed but the image is not. The result will be that both figures will overlap.
|
Packages: graphicx to manipulate boxes. |
---|
The package graphicx , beside \includegraphics , also defines the commands
\rotatebox ,
\scalebox ,
\resizebox ,
for the manipulation of graphics or in general of boxes.
The names are self-explanatory. The command \rotatebox has a first argument indicating the angle in degrees. A couple of examples are
\rotatebox{10}{This is a sentence} The first arguments of \scalebox is a dimensionless quantity indicating the horizontal scale. A second optional argument indicates the vertical scale. A couple of examples are
\scalebox{0.5}{word} word is reduced to 1/2. In the second case, the width is kept and the height is doubled.
If the two arguments have different sign, it produces a mirror reflection. On the hand, there is also a \reflectbox that applies a vertical mirror reflection. Then
\reflectbox{This is a sentence}
and
\scalebox{-1}[1]{This is a sentence}
are equivalent.
Finally, \resizebox is a kind of variant of \scalebox in which the scales are substituted by absolute lengths. In this case, the two arguments are mandatory. If any of them is replaced by ! then the aspect ratio is preserved. For instance:
\resizebox{!}{!}{word} word appears as it is. With the second example the width becomes 30pt and the height 20pt . This height is preserved in the last example and the aspect ratio is the same as in word without any resizing.
There is a variant of \resizebox named \resizebox* . The only difference is that the second argument specifies the "totalheight". With the terminology of boxes, this is the height plus the depth. The height is counted from the baseline and the depth measures the part below the baseline.
Important: Apparently the effect of \scalebox and \resizebox is only correctly shown in the PDF but not in the DVI file.
|
Packages: lineno for line numbering |
---|
With \usepackage{lineno} putting \linenumbers we get line number for that point onward or until \nolinenumbers . It can also used as an environment \begin{linenumbers}...\end{linenumbers} . By default, the line count is not reset when applied several times. The starting number can be specified as an optional argument of the environment. For instance:
\begin{linenumbers} The numbering applies to text lines. To number also displayed formulas, use the argument mathlines of the package i.e., \usepackage[mathlines]{lineno} .
|
Packages: makeidx to make an index |
---|
With \usepackage{makeidx} and the command \makeindex in the preamble (before \begin{document} ) and \printindex at the point in which we want to locate the index, we will have an alphabetical index with references to page numbers of every word or phrase marked with \index (e.g. \index{mathematics} , \index{number theory} ).
Sometimes one wants to alter the alphabetical ordering mainly because the word contains symbols or accents. To solve this problem one can call \index as
\index{<item_for_ordering>@<item_for_showing>}
\index{pi@$\pi$} , \index{easy@\textit{easy}} , \index{pinata@piñata} .
If in \index we separate several items with ! then they appear as subentries of the first item. It is possible to use several levels. For instance:
\index{Kloosterman sums!definition} \index is \index{<item>|see {<main_item>}} which refers to <main_item> preceded by the word see in italics.
For more information see the Wikibook of LaTeX. |
Packages: overpic to overlap images and text |
---|
This packages must be loaded after graphicx and admits as parameters abs , percent and permil depending on if the positionin is in multiples of \unitlength , is a percentage or a per mille. The default is percent . For example, we can include in the preamble
\usepackage{graphicx} [percent] is unnecessary.
The package offers the environment overpic which superimpose to an image other images or text with positions specified by \put .
The optional arguments of the environment include grid to draw a grid (as help to position the objects) with separation given by tics and unit to specify the \unitlength . An example is
\begin{overpic}[grid, tics=15, unit=1mm]{./imag/figs.eps} unit=1mm has no effect.
|
Packages: printlen to print lengths. |
---|
It adds the command \printlength{} which prints in the document the length acting as argument. For instance, with
The \verb!\textheight! is \printlength{\textheight} or \textheight is 595.80026pt or 209.39738 mm".
|
Packages: scrextend to globally scale fonts |
---|
Putting in the preamble
\usepackage{lmodern} 20pt . Loading lmodern it is not completely necessary but assures that we are using scalable fonts. It seems that there are issues with the math mode.
|
Packages: showkeys to show labels |
---|
With \usepackage{showkeys} we can see the labels in the output document when defined and when quoted. This can be a little disturbing. In general a better option is \usepackage[notcite,notref,color]{showkeys} which only shows the labels in formulas in a gray tone.
|
Packages: xcolor , background color |
---|
The command \colorbox{c}{text} makes a box containing text with background color c . For instance:
\colorbox{blue!10!white}{A pale blue background}
\fboxsep to zero with
{\fboxsep=0pt\colorbox{blue!10!white}{A pale blue background}}
\colorbox{blue!10!white}{% \usepackage[table]{xcolor} and the command \cellcolor allows to select the color of a cell. For example
\begin{tabular}{ccc} |
Packages: xcolor , color names |
---|
Loading the package with \usepackage[usenames,dvipsnames]{xcolor} we can use the names of the 68 colors known to dvips . They are listed here.
For instance, one can write {\color{OliveGreen}Hi there!} .
Note that the colors will appear correctly in the pdf but not necessarily in the dvi file.
|
Page: enlarge |
---|
Example: \enlargethispage{1cm} enlarges the height of the current page 1cm.
|
Page: layout variables |
---|
The length variables controlling the page layout are:
\hoffset -> Basic horizontal margin minus one inch.
\voffset -> Basic vertical margin minus one inch.
\oddsidemargin -> Increase in the \hoffset for odd pages.
\evensidemargin -> Increase in the \hoffset for even pages.
\topmargin -> The distance from the header to the lower part of the vertical margin. If negative (usual), the header may be contained inside the margin.
\headheight -> Height of the header.
\headsep -> Distance from the lower part of the header to the body.
\textheight -> The height of the body.
\textwidth -> The width of the body.
\marginparsep -> Separation between the horizontal margin and the space for margin notes.
\marginparwidth -> Width of the space for margin notes.
\marginparpush ->The minimum vertical space between two marginal notes.
\footskip -> Space between the lower part of the body and the lower part of the footer.
\paperheight -> The height of the paper. For A4 it is 845.04684pt (approx. 297mm).
\paperwidth -> The width of the paper. For A4 it is 597.50787pt (approx. 210mm).
The meaning is more clear in a figure. See it for instance in the Overleaf documentation or in the p.115 of The Not So Short Introduction to LaTeX2ε. |
Page: multiple page titles |
---|
The environment titlepage allows to add several title pages. This can be used to make what it is called in the jargon of book design a "half title". This title page appears without page number and without heading. The page numbering will start by 1 after it.
|
Page: no page numbers |
---|
In some formats or headings it is difficult to suppress completely the page numbers. An extreme solution is \renewcommand{\thepage}{} .
|
Page: references |
---|
The command \pageref{<label>} shows the page number in which a certain label appears.
|
Paragraphs: indentation |
---|
By default every paragraph has an indentation stored in the variable \parindent . In this way, we disable the indentation with \setlength{\parindent}{0pt} .
The commands to force indentation or the lack of it, are \indent
and
\noindent . When a section starts the indentation is disabled and the command
\indent
does not work in this situation. An alternative is \makebox[0pt]{}\indent .
In user defined environments it may appear an unexpected indentation at the beginning or extra spaces at the end. To avoid it, it is convenient to start the definition with \noindent\ignorespaces and finish it with
\noindent\ignorespacesafterend .
|
Paragraphs: margin notes |
---|
The command \marginpar adds a margin note.
In the oneside format, it appears to the right. In the twoside format it appears in the exterior part (right for odd, left for even). To change this default behavior in any of the formats the command \reversemarginpar have to precede the margin note. To come back the the default behavior, use \normalmarginpar . Example:
First paragraph.\marginpar{Note 1} Margin par ... moved . The commands \normalmarginpar and \reversemarginpar affect to all notes in the paragraph.
|
Spanish: decimal point |
---|
In principle in Spanish the rule is to use decimal commas instead of decimal points then $1.3$ shows (with [spanish]{babel} ) 1,3 . It causes some problems, for instance in the coordinates of a vector. To change this default behavior and use decimal points as in English it is enough to write in the premable the command \decimalpoint after loading the babel package.
|
Summation: multiple sums with limits |
---|
The command \mathop allows to group several sums to admit common limits like this:
\mathop{\sum\ \sum}_{\substack{1<x+y<100\\ 2<3x-y<40}}
|
Summation: prime |
---|
Use \sideset{}{'}\sum to put a prime in a sum in the right place. It also works if the sum has limits. If the first argument of \sideset is not empty, its content appears preceding the sum. It does not seem very useful.
|
Table of contents: add or remove items |
---|
It is well known that with !\chapter*{...}*!, !\section*{...}*!, etc. we remove these items from the table of contents. To add
an item the command is
\addcontentsline{toc}{<unit>}{<text>}
where <unit> means chapter, section, etc. The following paradoxical example combines add and removing an item. The effect is that we get "Prologue" in the table of contents but it is not included as a numbered section.
\section*{Prologue}
\section*{Prologue} |
Table of contents: depth |
---|
The counter tocdepth indicates the depth of table of contents. For instance
\setcounter{tocdepth}{0} book class and the table of contents would be empty with the article class. Changing {0} by {1} , {2} or {3} we see also sections, subsections or subsections.
|
Table of contents: title |
---|
The variable \contentsname stores the title of the table of contents.
It can be changed like in this example
\renewcommand{\contentsname}{This is the table of contents} |
Templates: letter class |
---|
To write a letter.
\documentclass[11pt,a4paper]{letter} |
Types: footnotesize bug |
---|
By some reasons sometimes when footnotesize is applied to several paragraphs as an environment the final lineskip is altered. To avoid this awkward behavior it is enough to close the environment with
{} |
Types: italic boldface |
---|
A simple trick to obtain italic boldface types is \textbf{\itshape Italic boldface} .
|
Types: mathematical boldface |
---|
It is well known that
\mathbf{...} allows to use boldface letters in the mathematical mode but this command does not affect to Greek letters and mathematical operators. A "poor man" solution is the command \pmb{} . The name abbreviates "poor man boldface" and it superimposes the argument with a slightly translated version of it. Try for instance $\pmb{\alpha=\beta}=\pmb{\gamma}$ .
For a more professional solution use \mathversion{bold} which will turn every formula into boldface until deactivated with \mathversion{normal} .
For instance, with
\mathversion{bold} \mathversion is that it only applies to entire formulas.
|