Is it possible to get multline like behavior within a gather
environment? I have a set of equations in a gather environment, but
one of them is too long, and I'd like to split it up onto two lines
where the first line is left-aligned and the second line is right-aligned
(just like multline). If there is a way of aligning individual lines
within the gather or split environment (like flushleft or flushright but
functional in mathmode) this would solve the problem.
The mathtools package has an inner multlined environment similar to gathered and the likes, but it required a small amount of manual tweaking:
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
% \begin{multline}
% \framebox[0.65\linewidth]{\strut} \\
% \framebox[0.6\linewidth]{\strut} \\
% \framebox[0.65\linewidth]{\strut} \\
% \framebox[0.6\linewidth]{\strut}
% \end{multline}
\begin{gather}
\framebox[0.8\linewidth]{\strut} \\
\begin{multlined}[b][\linewidth-3\multlinegap]
\framebox[0.65\linewidth]{\strut} \\
\framebox[0.6\linewidth]{\strut} \\
\framebox[0.65\linewidth]{\strut} \\
\framebox[0.6\linewidth]{\strut}
\end{multlined} \\
\framebox[0.4\linewidth]{\strut}
\end{gather}
\end{document}
I haven't tested this, but you can try putting \hfill in front of the second line.
Having said that: IMHO, multline behavior inside a gather environment is undesirable. Especially if you have the fleqn option enabled, you should consider the following option:
put the long equation inside a split, with alignment on the left side of the equality. Assuming the right hand side is too long, put its second part on a new line (still inside the split) and use \hspace{1cm} (or some other length) to indent the second part a bit further.
For an overview of all AMS multiline blocks, see the amsmath documentation.
Related
I am having problems in adjusting the format for a table in LaTex. The code is the following and the image depicts how the table comes out after compiling:
\begin{table}[H]
\centering
\renewcommand{\arraystretch}{1.2}
\resizebox{\columnwidth}{!}{
\begin{tabular}{|p{2cm}|c|c|c|}
\hline
{\textbf{Labels}} & {\textbf{Precision}} & {\textbf{Recall}} & {\textbf{F1-Score}}
\\
% \hline
\cline{2-9}
% \textbf{Inactive Modes} & \textbf{Description}\\
%\hhline{~--}
{Not Misogynous} & $37.49\%\pm1.91\%$ & $46.13\%$ & $36.15\%\pm2.61\%$ & \\ \hline
{Not Misogynous} & $37.49\%\pm1.91\%$ & $46.13\%$ & $36.15\%\pm2.61\%$ & \\ \hline
\end{tabular}
}
\caption{BERTweet binary task}
\label{table:bert_binary}
\end{table}
I don't understand how to add the necessary line to "close" the boxes around the table
You have a few issues in your code.
You specify 4 columns p{}ccc while a content of tabular body has 5 columns (with the extra ending &). This is why the lines are discontinued.
Numbers X and Y in the argument of \cline{X-Y} must not exceed the available number of columns. You define 4 and trying to draw horizontal rule between 2 and 9. You probably get the error: Extra alignment tab has been changed to \cr.
You should avoid inserting empty line in tables. Most of the times LaTeX do not accept \par in table environments, which is converted from empty lines. It may work in modern packages that use more recent advances in LaTeX.
I also wonder why you enclose cells inside {...}. The code works without them. Is there any particular reason? Perhaps in the main code you load siunitx and apply S-type column. Then, you do have to tell siunitx which cells are non-numeric by wrapping cells inside braces. Otherwise, siunitx issues error!
Here's my suggestion for the table:
I defined columns which accept math expressions without extra $...$
The main values and uncertainties are split in columns to improve formatting and spacing
booktabs provides improved rules that arguably improved presentation
Default gap between the table and its caption seems too large, so I slightly reduced it (requires caption package)
I keep captions of tables at the top and captions of figures at the bottom but this is again a personal preference.
One of the rules I usually follow is to avoid repeated information in tables. The % in your case is repeated everywhere. You could remove it and add annotation that values in all three columns are percentages.
Here's the table
and the code
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup[table]{position=bottom,skip=3pt}
\newcolumntype{R}{>{\(}r<{\)}}
\newcolumntype{L}{>{\(}r<{\)}}
\begin{document}
\begin{table}[tbh]
\centering
\renewcommand{\arraystretch}{1.2}
\caption{BERTweet binary task}
\label{table:bert_binary}
\begin{tabular}{p{2.5cm} R#{\;}L c R#{\;}L}
\toprule
\textbf{Labels}
& \multicolumn{2}{c}{\textbf{Precision}}
& \textbf{Recall}
& \multicolumn{2}{c}{\textbf{F1-Score}} \\
\midrule
Not Misogynous & 37.49 & \pm1.91 & 46.13 & 36.15 & \pm2.61 \\
Not Misogynous & 37.49 & \pm1.91 & 46.13 & 36.15 & \pm2.61 \\
\bottomrule
\multicolumn{6}{#{}l#{}}{\footnotesize All values in \%}
\end{tabular}
\end{table}
\end{document}
I think the previous answer to this question is very good and detailed, including many observations that is always useful to consider when doing tables in LaTeX. It also addresses you to avoid vertical lines in tables (consistently with the use of the package booktabs).
I add the following code and output just for the sake to remark the minimal edits necessary for your original code to reach a threshold look.
\documentclass{article}
\begin{document}
\renewcommand{\arraystretch}{1.2}
\begin{table}%[H]
\centering
\begin{tabular}{|p{3cm}|c|c|c|}
\hline
{\textbf{Labels}} & {\textbf{Precision}} & {\textbf{Recall}} & {\textbf{F1-Score}}\\
\hline
Not Misogynous & $37.49\%\pm1.91\%$ & $46.13\%$ & $36.15\%\pm2.61\%$\\
\hline
Not Misogynous & $37.49\%\pm1.91\%$ & $46.13\%$ & $36.15\%\pm2.61\%$\\
\hline
\end{tabular}
\caption{BERTweet binary task}
\label{table:bert_binary}
\end{table}
\end{document}
I have been using common align environment from amsmath and noticed strange behaviour of kerning when placing the & sign from either side of the + sign. Namely assume the following code and the result it produces for me:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a&+b\\
a+&b
\end{align}
\end{document}
Is this a bug? If this is intended behaviour, can you please explain why the kerning is different in those cases?
For all it could matter I am using TexStudio 4.0.1 and MikTex (Console version 4.8, all packages updated on 24th Aug 22) to produce the output from the code.
I think it's working as expected. The ampersand characters defines a boundary between left and right columns, which in turn are right and left aligned, respectively. Everything to the left is pushed leftwards and everything to the right is pushed rightwards.
Consider the code
\documentclass{article}
\usepackage{amsmath}
\setlength\fboxsep{0pt}
\begin{document}
\begin{align}
\boxed{a} \clap{\rule[-3pt]{0.4pt}{12pt}}& + b\\
a + \clap{\rule[-3pt]{0.4pt}{12pt}}& \boxed{b}
\end{align}
\end{document}
IMO there's the perfect split between two columns. The extra spacing comes from + being an operator so LaTeX does add extra spacing around it.
In your code, there is another issue. An ampersand placed at the right of an operator cancels its status of being the operator. The effect is it's losing expected spacing; the same would happen with =. Adding anything between an operator and & restore its status. Therefore, {} placed right before & is he easiest solution
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a & + b \\
a + {}& b
\end{align}
\end{document}
I want to put a basic table into a 2-columns document.
I saw that instead of:
\begin{table}
enter code here
\end{table}
we should use:
\begin{table*}
enter code here
\end{table*}
but it is not working.
If anyone has an idea, thanks in advance! Below a minimal example.
\documentclass[10pt]{article}
\usepackage{lipsum}% fake text
\usepackage{multicol}% enable writing in 2 columns
\setlength{\columnsep}{7mm}% separation between the two columns
\setlength{\columnseprule}{1pt}% width of the separation lign(comment if not wanted)
\begin{document}
\begin{multicols}{2}
\lipsum[1]
\begin{table*}[t]
\begin{tabular}{cc}
A & b\\
c & d
\end{tabular}
\end{table*}
\end{multicols}
\end{document}
It seems that the document class is important.
If I change
article -> scrartcl
I can use the
\captionof{table}{my caption}
without using the table environment.
But I don't know if it is the right way to do it.
Floats and marginpars are not allowed inside multicols environment. Also, table* would be page wide. If you comment the table* environment, you get the tabular in the second column:
\documentclass[10pt]{article}
\usepackage{lipsum}% fake text
\usepackage{multicol}% enable writing in 2 columns
\setlength{\columnsep}{7mm}% separation between the two columns
\setlength{\columnseprule}{1pt}% width of the separation lign(comment if not wanted)
\begin{document}
\begin{multicols}{2}
\lipsum[1]
%\begin{table*}[t]
\begin{tabular}{cc}
A & b\\
c & d
\end{tabular}
%\end{table*}
\end{multicols}
\end{document}
Rather, you can nest the tabular inside a center environment and, if you need, use the package caption to label and reference your tabular although it's not a float.
I'm a LaTeX beginner and would like to have two equations aligned on the equals symbol which is working fine so far. Now, between these two equations I need a line of text. But LaTeX interprets this as a math formula since it's showing a (2) right next to it.
I would like to have it as normal text without a (2) aligned on the far left.
I have already tried things like
\begin{flushleft} line of text \end{flushleft}
but it's not working, maybe because I'm using it inside an {align} environment.
Not sure if it's important to mention but I'm using Overleaf (online LaTeX editor).
\begin{align}
\tilde{w}_{ij} &=
\begin{cases}
w_{ij} & \text{mit $P(i)$}\\
0 & \text{sonst}
\end{cases}\\
\text{This text be on the far left}\\
\tilde{w}_{ij} &= w_{ij} * P(i)
\end{align}
produces this ->
This sounds like a job for \intertext from amsmath:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align}
\tilde{w}_{ij} &=
\begin{cases}
w_{ij} & \text{mit $P(i)$}\\
0 & \text{sonst}
\end{cases}\\
\intertext{This text be on the far left}
\tilde{w}_{ij} &= w_{ij} * P(i)
\end{align}
\end{document}
I have this equation and it's quite big (basically a FDM one) but it aligns with the text and then continues out on the right side to the nothingness. I've tried stuff like \begin{center} and \hspace*{-2.5cm} but to no avail. I want it to use the whole line not just from the left-margin and out to the right.
How do I do it and do I need to install some special package for it?
I use the \[ instead of the displaymath like this
\[
Equation arrays here
\]
The code
\[
\left(
\begin{array}{cccccc}
-(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) & 0 & \cdots & 0 \\
-\kappa & -(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) & 0 & \cdots \\
0 & -\kappa & -(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) & 0 & \cdots \\
\vdots & 0 & \ddots & \vdots \\
\vdots & \vdots & \vdots & -\kappa & -(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) \\
0 & \vdots & \vdots & 0 & \kappa - \frac{2h\kappa_{v}}{\kappa}(\frac{hv\rho}{2} - \kappa) & -2\kappa \\
\end{array}
\right)
\left(
\begin{array}{c}
T_{1} \\
T_{2} \\
\vdots \\
T_{n} \\
\end{array}
\right)
=
\left(
\begin{array}{c}
Q(0) + \kappa T_{0} \\
Q(h) \\
Q(2h) \\
\vdots \\
Q((n-1)h) \\
2\frac{\kappa_{v}}{\kappa_{v}}T_{out} \\
\end{array}
\right)
\]
The \[ \] delimiters are intended for single-line equations. In basic LaTeX you can use the eqnarray environment to make a multi-line equations, or you can use the multline environment from the amsmath package. The eqnarray environment lets you use \\ for line breaks but if you want the equation to be numbered, you also need to use the \nonumber command on all lines but one to prevent the numbering of all lines. The multline environment is intended for a single equation so it always produces just one equation number too.
EDIT: This isn't what I would do habitually, but since your equation does seem to fit on a single line, here's the code I've used to get whole-line spanning things:
\newenvironment{widefig}[1][1in]{%
\begin{list}{}{\setlength{\itemindent}{-#1}%
\setlength{\leftmargin}{0pt}%
\setlength{\rightmargin}{0pt}}\item
}{%
\end{list}
}
Like the environment name suggests, I wrote it for figures that are too wide to fit inside the margins, so this allows controlling the left margin and permits a figure to be centered on the whole line.
How I modified your example was to wrap it inside a \begin{widefig}[1.5in]-\end{widefig} pair, added
\relpenalty=10000
\binoppenalty=10000
after the \begin{widefig} line to prohibit line breaking inside the formula, and changed the \[\] into \(\) because the widefig environment only works for inline, not display. You might also need to fiddle a bit with the amount of space given on the \begin line to make the equation properly centered.
I don't believe this is very good typesetting style, though, so you'll want to be very careful about using it, and preferably try to fit things inside the margins. For instance, in this case you could also get rid of a few columns in your first matrix; the usual standard is to have only the first, second, and last, but you probably also want the second-to-last row and column, since the changes in the values for the last row and column is a bit surprising. If you did that, it might fit (but I didn't check).
If you really don't want to break the equation over lines and you don't mind breaking the text width, you could try something like: (untested)
\centerline{$\displaystyle <long equation here>$}
could you add a line-break using \\ ?
Begin centre only aligns things like figures, it won't affect line equations.
You might like to look at the American Mathematical Society guide to their package s
ftp://ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf
You could use the eqnarray environment to break equations into multiple lines.