How to set tab stops after whitespaces in LaTeX? - latex

I'm trying to set tab stops in LaTeX in the tabbing environment. My problem is that I want to set a tab stop after a number of whitespaces. The problem is that LaTeX of course ignores multiple whitespaces, and it seems to only support setting tab stops after actual text.
What I would like to be able to do is format the arrows below so that they line up together.
A -> B
CD -> A
BDD -> F
The problem is that the extra spaces after the characters on the left of the arrows are ignored for the purposes of setting the tab stop. What is the solution?

The tabbing environment allows to set tab stops and position text accordingly; it may be used to simulate simple tables.
\= in the first line sets a tab stop, \> advances to the next tab stop in the second line and below.
Please note that tabbing does not expand tab stops, so you need to ensure they are placed wide enough from each other. For example, I put some nonbreakable spaces after A in the first line:
\begin{tabbing}
A~~~~ \= $\to$ \= B \\
CD \> $\to$ \> A \\
BDD \> $\to$ \> F \\
\end{tabbing}
The result looks like
Using tables (e.g. tabular) is often easier, but tabbing allows to redefine tab points later, so it may be used to simulate indented text, like source code.
See also: LaTeX: tabbing.

If you want this in math mode, put \usepackage{amsmath} in your preamble, and try
\begin{align*}
A &\to B \\
CD &\to A
\end{align*}
The ampersands are invisible, and are aligned with each other, so the arrows will line up.
This can also be done in text mode as a table (without needing the amsmath package):
\begin{tabular}{r #{$\to$} l}
A & B \\
CD & A
\end{tabular}
With the # expression in the column specification, the columns will be separated by whatever symbol you like -- in this case, the arrow -- thus aligning that symbol between rows.

Use {\hskip 4em} to specify whitespace four font-width spaces wide, or what have you. There are a number of prespecified whitespace characters in Latex, such as \qquad for \hskip2em.
\hskip whitespace specified in this way is inflexible, that is, Tex will not change the amount of whitespace, but you can use something like {\hskip 3em plus 1em minus 1em} for space that tries to be 3ems long, but can stretch or shorten to between 2ems and 4ems.

If you want to use tabbing (instead of e.g. tabular), you can use kill to make a "template" line that sets the stops. See http://latex.computersci.org/Reference/TableEnvironments.

Related

paracol and footnote placing in Latex

For my current project I need two text lined up in two column. The idea is that one column shows the original language and the second column its translation, neatly lined up line by line. The package paracol does what I want except for one thing: footnote placement.
If one of the columns has a footnote and the other hasn't, the lines of the original and the translation do not stay together. The footnote disrupts the lining up of lines.
This is an example in which you can see that "some other text that should be next to the line in the left column" is not lined up with the lines of the original. All because of the footnote.
\documentclass[twoside,a4paper,11pt]{book}
\usepackage{paracol}
\usepackage{lipsum}
\begin{document}
\begin{paracol}{2}
\lipsum[1-2]
\switchcolumn
\lipsum[1-2]
\switchcolumn
text with footnote\footnote{the footnote}
and some other text
\switchcolumn
the translation without footnote
some other text that should be next to the line in the left column
\end{paracol}
\end{document}
As you can see, the footnote disrupts the alignment of lines. How to remedy this?
I found the solution to my own problem by adding the following line after loading the paracol package:
\footnotelayout{p}
This ensures that footnotes are layed out for the whole page instead of the default of per column.
(Since I also added footmisc with the perpage parameter, I also had to delete the perpage parameter and add this:
\usepackage{everypage}
\AddEverypageHook{\setcounter{footnote}{0}} % resets footnote counter on every page
)

What is the best way to add new lines and new paragraphs in LaTeX?

I'm currently writing a report where I write new paragraphs like this:
I like sharks, sharks are cool.
Also bears are really cool.
Which basically has one completely empty line between then. In order to create a new paragraph I use the "\" code:
I like sharks, sharks are cool. \\
Also bears are really cool.
However this generates "Underfull \hbox (badness 10000)" error. What is the correct way of starting a new paragraph?
use \par after the line of code you want there to be a new paragraph
after
I like sharks, sharks are cool. \par
Also bears are really cool.
https://www.sharelatex.com/learn/Paragraphs_and_new_lines
If your looking for line breaks go here
https://www.sharelatex.com/learn/Line_breaks_and_blank_spaces
You have several options
\\ (two backslashes)
\newline
\hfill \break
\vspace{5mm}
Inserts a vertical spaces whose length is 5mm. Other LATEX units can be used with this command.
\vfill
Inserts a blank space that will stretch accordingly to fill the vertical space available. That's why the line "Text at the bottom of the page." is moved to the bottom, and the rest of the space is filled in.
\smallskip
Adds a 3pt space plus or minus 1pt depending on other factors (document type, available space, etc)
\medskip
Adds a 6pt space plus or minus 2pt depending on other factors (document type, available space, etc)
\bigskip
Adds a 12pt space plus or minus 4pt depending on other factors (document type, available space, etc)
Not sure if it's best practice, but I would use:
I like sharks, sharks are cool. \newline
Also bears are really cool.
\newline followed by an empty line will give you the space between the two lines.
I just put a blank line in between.
I like sharks, sharks are cool.
Also bears are really cool.
I wouldn't worry about an underfull \hbox warning though. You probably have better things to do than try to make all of LaTeX's warnings go away.
I would also take a look at \paragraph{} command, that may provide paragraph heading too.

margin note with tabbing environment in latex

I need to put a margin note next to a tabbing environment. If I try to use \marginpar within the environment I get an error: LaTeX Error: Not in outer par mode.
I've tried putting the \marginpar just before the \begin of the environment but it ends up aligned with the last line of the preceding paragraph instead of with the first line of the tabbing environment.
In the example below the first margin note gets aligned above the tabbing text and the second one below. I tried using \vspace to shift the top note down, and that works okay unless a page break occurs between the tabbing environment and the preceding paragraph -- then the margin note and the tabbing text end up on separate pages.
Any ideas how to get the margin note to line up with the top of the tabbing text?
\documentclass{memoir}
\begin{document}
Now is the time for all good men to come to the aid of their country.
\marginpar{a margin note}\begin{tabbing}
tabbing text a\\
tabbing text b\\
\end{tabbing}\marginpar{another margin note}
Now is the time for all good men to come to the aid of their country.
\end{document}
The marginnote package provides a work-around for this:
\documentclass{memoir}
\usepackage{marginnote}% http://ctan.org/pkg/marginnote
\begin{document}
Now is the time for all good men to come to the aid of their country.
\begin{tabbing}
tabbing text a \marginnote{a margin note} \\
tabbing text b
\end{tabbing}
Now is the time for all good men to come to the aid of their country.
\end{document}

LaTeX table positioning

I have a LaTeX document that contains a paragraph followed by 4 tables followed by a second paragraph. I want the 4 tables to appear between the two paragraphs which from what I've read means I should use the [h] option after beginning the table environment (e.g. \begin{table}[h]).
Using this the first two tables appear after paragraph 1 as expected, however paragraph 2 is then displayed with the last two tables appearing on the following page. How can I get the tables to appear in the correct location?
I've tried various things to correct the positioning such as using [h!] however this doesn't seem to have any effect. Using \clearpage after the tables does have the desired effect of making the tables appear before the second paragraph but it then leaves the last two tables on their own page with loads of white-space, when I would prefer to have the second paragraph begin immediately after the tables.
Paragraph 1...
\begin{table}[h]
table1...
\end{table}
\begin{table}[h]
table2...
\end{table}[h]
...
Paragraph 2...
After doing some more googling I came across the float package which lets you prevent LaTeX from repositioning the tables.
In the preamble:
\usepackage{float}
Then for each table you can use the H placement option (e.g. \begin{table}[H]) to make sure it doesn't get repositioned.
Table Positioning
Available Parameters
A table can easily be placed with the following parameters:
h Place the float here, i.e., approximately at the same point it occurs in the source text (however, not exactly at the spot)
t Position at the top of the page.
b Position at the bottom of the page.
p Put on a special page for floats only.
! Override internal parameters LaTeX uses for determining "good" float positions.
H Places the float at precisely the location in the LATEX code. Requires the float package. This is somewhat equivalent to h!.
If you want to make use of H (or h!) for an exact positioning, make sure you got the float package correctly set up in the preamble:
\usepackage{float}
\restylefloat{table}
Example
If you want to place the table at the same page, either at the exact place or at least at the top of the page (what fits best for the latex engine), use the parameters h and t like this:
\begin{table}[ht]
table content ...
\end{table}
Sources: Overleaf.com
At the beginning with the usepackage definitions include:
\usepackage{placeins}
And before and after add:
\FloatBarrier
\begin{table}[h]
\begin{tabular}{llll}
....
\end{tabular}
\end{table}
\FloatBarrier
This places the table exactly where you want in the text.
Here's an easy solution, from Wikibooks:
The placeins package provides the command \FloatBarrier, which can be used to prevent floats from being moved over it.
I just put \FloatBarrier before and after every table.
What happens if the text plus tables plus text doesn't fit onto a single page? By trying to force the typesetting in this way, you are very likely to end up with pages that run too short; i.e., because a table cannot by default break over a page it will be pushed to the next, and leave a gap on the page before. You'll notice that you never see this in a published book.
The floating behaviour is a Good Thing! I recommend using [htbp] as the default setting for all tables and figures until your document is complete; only then should think about fine-tuning their precise placement.
P.S. Read the FAQ; most other answers here are partial combinations of advice given there.
If you want to have two tables next to each other you can use: (with float package loaded)
\begin{table}[H]
\begin{minipage}{.5\textwidth}
%first table
\end{minipage}
\begin{minipage}{.5\textwidth}
%second table
\end{minipage}
\end{table}
Each one will have own caption and number.
Another option is subfigure package.
In my case I was having an issue where the table was not being displayed right after the paragraph I inserted it, so I simply changed
\begin{table}[]
to
\begin{table}[ht]
You may want to add this to your preamble, and adjust the values as necessary:
%------------begin Float Adjustment
%two column float page must be 90% full
\renewcommand\dblfloatpagefraction{.90}
%two column top float can cover up to 80% of page
\renewcommand\dbltopfraction{.80}
%float page must be 90% full
\renewcommand\floatpagefraction{.90}
%top float can cover up to 80% of page
\renewcommand\topfraction{.80}
%bottom float can cover up to 80% of page
\renewcommand\bottomfraction{.80}
%at least 10% of a normal page must contain text
\renewcommand\textfraction{.1}
%separation between floats and text
\setlength\dbltextfloatsep{9pt plus 5pt minus 3pt }
%separation between two column floats and text
\setlength\textfloatsep{4pt plus 2pt minus 1.5pt}
Particularly, the \floatpagefraction may be of interest.
Not necessary to use \restylefloat and destroys other options, like caption placement. just use [H] or [!h] after \begin{table}.

How do I correctly insert an image/figure and have the text "flow around" the image/figure in latex?

I've been struggling with this. I wanted to insert an image and have it 'near' the text that discusses it, but have the text on that page wrap/flow around the image.
The image I've converted into eps format. I initially tried to use the figure environment (\begin{figure}...), but that merely placed the image at the top or bottom of the page without any text beside it, leaving a large portion of the page empty.
I did some digging on the web and identified the 'wrapfig' package, it seemed a likely solution, but I get a series of errors, and the image appears at the end of the document.
The errors:
Package wrapfig Warning: wrapfigure used inside a conflicting environment on input line 297.
Package wrapfig Warning: Stationary wrapfigure forced to float on input line 303.
Package wrapfig Warning: Stationary wrapfigure forced to float on input line 306.
Which continues for several lines.
What's odd is that one occasion, after compiling, the image appeared exactly where I wanted it, and then on the next it didn't.
[Added a minute or so later]
The latex code I have currently:
\begin{wrapfigure}{r}{0.2\textwidth}[h]
\begin{center}
\includegraphics[width=0.18\textwidth]{vec-perp.eps}
\end{center}
\caption{A}
\end{wrapfigure}
wrapfigure does not need the [h] specifier.
you need to include the wrapfigure package in your preamble:
\usepackage{wrapfig}
then, put the wrapfigure call above the text you want to wrap into, like this:
\begin{wrapfigure}{r or l}{width/height} \centering \includegraphics[width/height]{graphic.filename} \caption{foo} \end{wrapfigure}
a real world example:
\begin{wrapfigure}{r}{1.5in}
\centering
\includegraphics[width=1.5in]{smile.jpg}
\end{wrapfigure}
I just went through my document, commenting it out in sections, hoping to find the environment it was complaining about...in the process, I unintentionally introduced a blank line that I didn't have before. Apparently, the environment it was complaining about was the environment before the figure. I didn't have a blank line between the previous part, which was an itemize environment.
So...this, for example, is 'broken':
Ingredients for the Banana-Grape Bread Recipe
\begin{itemize}
\item Bananas
\item Grapes
\item Eggs
\end{itemize}
\begin{wrapfigure}{r}{0.2\textwidth}
\centering
\includegraphics[width=0.18\textwidth]{banana-grape.eps}
\caption{BananaGrape Bread}
\end{wrapfigure}
And inserting a empty line:
\end{itemize}
\begin{wrapfigure}{r}{0.2\textwidth}
Clears up my problems. Along the way I learned all sorts of things, yay! On the other hand, I'm pretty sure I don't have a clear understanding of environments yet. Time to spend some time reading, I reckon.

Resources