User Tools

Site Tools


latex

Latex

Configuration

Installation

Unknown Errors are often caused by disabled automatic package installation. They can be enabled through the Settings Menu, which is avaiable under:

  • …MiKTeX x.x\miktex\bin\mo_admin.exe or through
  • Start Menu→Program Files→MiKTeX 2.9→Maintenance→Settings

In the settings menu you should set Install Missing Packages On-The-Fly → YES

Usage

Things to remember

  • When referencing an image write \caption before \label. r the \label or you will get ?? instead of a reference.
    \begin{wrapfigure}{r}{0.4\textwidth}
    \center
    \includegraphics[width=0.3\textwidth]{images/scratch_blockGroups.png}
    \caption{Block groups}
    \label{fig:blockgroups}
    \end{wrapfigure}
  • Use \clearpage and \cleardoublepage to start a new page. Theses commands really do begin a new page, drawing all pics before this command

Reference

Scaling

To scale something - put it into a box.

 \scalebox{0.7}{ scalebla something }

Centering

To center something - put it into a center environment

\begin{center}
to center
\end{center}

Define new commands

Use commands like: \mydef{Definition}

% define new Definition command
\newcounter{mydefcount}
\newcommand{\mydef}[1]{	\stepcounter{mydefcount}
						\colorbox{Orange}
						{\large\textbf{Def \arabic{mydefcount}: #1 }}
						\newline\newline
}

Temporary adjust text width

Outside of environments - wrap the text by adjustwidth

% allows for temporary adjustment of side margins
\usepackage{chngpage}
\begin{adjustwidth}{-4cm}{-4cm}
...
\end{adjustwidth}

when using adjustwidth together with other float environments, like figure or table - move adjustwidth insdide of the environment.

\begin{table}[h!b!p!]
	%temporary change textwidth
	\begin{adjustwidth}{-4cm}{-4cm}% adjust the L and R margins by 1 inch	
		\begin{tabular}{ *{2}{l} }
		
	CellOne   & CellTwo \\
	CellThree & CellFour \\

		\end{tabular}

	\end{adjustwidth}
\end{table}

Table

Table contains of two environments table and tabular. The first contais the second and can contain table settings. Here a table, which is wider, than the textwidth.

\begin{table}[h!b!p!]
	%temporary change textwidth
	\begin{adjustwidth}{-4cm}{-4cm}% adjust the L and R margins by 1 inch	

		%odd-even row coloring
		\rowcolors{2}{gray!10}{}

		%centering the table
		\begin{center}  
			%scaling the table
			\scalebox{0.8}{
				%tabular is INSIDE of all environments, table is OUTSIDE
				\begin{tabular}{ *{2}{l} }
		
	CellOne   & CellTwo \\
	CellThree & CellFour \\

				\end{tabular}
			}
		\end{center}

		\caption{Software key size related papers }
		\label{tab:keysize} 
		
	\end{adjustwidth}
\end{table}

As a second example a table, with a linebreak in one of the cells using parbox

\begin{table}[!h]

		%odd-even row coloring
		\rowcolors{2}{gray!10}{}

		%centering the table
		\begin{center}  
			%scaling the table
			\scalebox{0.70}{
				%tabular is INSIDE of all environments, table is OUTSIDE
				\begin{tabular}{ l p{3cm} p{4cm} l l l  }
		
	\multicolumn{1}{c}{Year} & 
	\multicolumn{1}{c}{Task} &
	\hline
	1990 & 	\parbox[t]{4cm}{First line \\ second} \\
	1991 & 	\parbox[t]{4cm}{Again a line \\ second} \\

				\end{tabular}
			}
		\end{center}

		\caption{Software key size related papers }
		\label{tab:keysize} 
		
\end{table}
}

Footmarks

Footmarks are easily possible in Latex. \footnotemark[1] creates a footmark. \footnotetext[1]{text} creates a footmark text.

\footnotemark \footnotetext{text}

Margin notes

Use package marginnote. It can create margin notes even in tables.

  \usepackage{marginnote}
  \newcommand{\mnote}[1]{\marginnote{\color{LightBlue}#1}}
  \mnote{Programming Block Type}

Site geometry

Use package geometry. It can resize the sites margins, headers, footers. The manual is here

  \usepackage{geometry}
  \newgeometry{top=0in,bottom=0in,right=0in,left=0in}
      \pagestyle{empty} %hides all titles and page numbers
      \fancyheadoffset[LO,RE]{0in}
      \fancyfootoffset[RE]{0in}

      %do something e.g. draw a picture
      \begin{figure}[htb]
        \center{\includegraphics[height=28cm]
        {images/uml.png}}
      \end{figure}

    \restoregeometry

Hyperlinks are imported by the package hyperref. The manual is available here
Internal links can be created by referencing a figure, section, table, bibtexentry etc.

\label{name}              %anchor can be inserted into environments, commands, figures, other objects with counters
\pageref{fig:example}     %prints the number of the page where the figure is located, with a link behind it.
\ref{bibkey}              %prints the name of the author of the bibtex entry


%define a command with a counter and 2 parameters and build in label to be passed as a parameter
\newcounter{mydefcount} % define new counter
\newcommand{\mydef}[2]{	\stepcounter{mydefcount}
						\colorbox{red}
						{\large\textbf{\label{#2}Def \arabic{mydefcount}: #1 }}
						\newline\newline
}

%use the command
\mydef{Definition text}{labelname}

%reference the definition
\ref{labelname}
\pageref{labelname}

or internal links can be created by introducing an anchor:

\hypertarget{name}{text}   %anchor
\hyperlink{<name>}{text}   %link

external links are created as

\href{http://link.com}{text}

Minipages

To align text and a picture side by side use minipages.

% Subclasses of ShapeWithSlotsHead 
\begin{figure}[ht]
\begin{minipage}[b]{0.5\linewidth}
	Text here
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.5\linewidth}
	\centering
	\includegraphics[scale=1]{picture.png}
	\caption{default}
	\label{fig:figure2}
\end{minipage}
\end{figure}

Citation

The package biblatex is required for citation. It can be loaded with a bunch of options. Here is a detailed manual to biblatex. Authoryear and abbreviate make citations look like Knuth et al., 2009.

 \usepackage[style=authoryear,
            bibstyle=authoryear,
            citestyle=authoryear,
            natbib=true,
            hyperref=true,
            backref=false,
            abbreviate=true]{biblatex}  

Citations is text can be dona with the commands. I prefer \parencite for citations to be displayed as [Knuth et al., 2009]

\citet = in-text citation, as in: Morgan & Keenan (1973)
\citep{<cite key>} = parenthetical citation, as in: (Morgan & Keenan 1973)
\nocite{<cite key>} = adds nothing to the text, but lets bibtex know that you want a citation included in the bibliography, in the document you may type: "As was shown in Morgan & Keenan (1973)\nocite{MK73} ..." 
\parencite  = citation in squared parentheses [Morgan et al. 1973]
\parencite* = the star makes all authors to be listed as [Morgan,Keenan and Resnick 1973] instead of writing et.al.

Unfortunately biblatex links only the year, not the whole entry. For the whole entry to be a link to look like that: add the following:

\makeatletter
%Works without the last bracket ;-)
\let\abx@macro@citeOrig\abx@macro@cite
\renewbibmacro{cite}{%
   \bibhyperref{%
   \let\bibhyperref\relax\relax%
   \abx@macro@citeOrig%
   }%
}
\let\abx@macro@textciteOrig\abx@macro@textcite
\renewbibmacro{textcite}{%
   \bibhyperref{%
   \let\bibhyperref\relax\relax%
   \abx@macro@textciteOrig%
   }%
}%
\makeatother

At least the literature references are printed with the command \printbibliography. To easily find the referenced literature it should start with the abbreviation in parentheses, as the citation in text does. For that use the following snippet:

\newcounter{mymaxcitenames}
\AtBeginDocument{%
  \setcounter{mymaxcitenames}{\value{maxnames}}%
}

\renewbibmacro*{begentry}{%
  \printtext[brackets]{%
    \begingroup
    \defcounter{maxnames}{\value{mymaxcitenames}}%
    \printnames{labelname}%
    \setunit{\nameyeardelim}%
    \printfield{labelyear}%
	\printfield{extrayear}%
    \endgroup
    }%
  \quad% or \addspace
}

\DeclareNameAlias{sortname}{first-last}

Sometimes it is useful to display the literature in separate groups. A filter can be used for that. Here is an example how to filter out the “online” literature. Than the filter can be passed to the \printbibliography command to print first all non-online literature and then all online literature.

\defbibfilter{online}{%
  \( \type{online} \)}

\defbibfilter{offline}{%
  \( \not \type{online} \)}

\printbibliography[heading=offline,filter=offline]
\printbibliography[heading=online,filter=online]
latex.txt · Last modified: 2020/12/27 20:35 by 127.0.0.1