How to make an equation span the whole page / line in LaTeX? - latex

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.

Related

How to make the word size in the LaTeX formula become the same in the table?

How to make the word size of numerator smaller?
I have tried to modified the whole table' s word size, but only this formulation's numerator of word become large.
First, please always provide the MWE!
You can add \scriptstyle to each inner component of \splitfrac to decrease font in that three part fraction.
I also added another example of your table with the straight fraction. IMO it looks much clearer. Besides, can the first terms be reduced?
As a side note, If you add something larger than one line to array or tabular with rules, it is almost always required to provide extra vertical spacing. Otherwise, the content "hugs" both top and the bottom rules. mathtools provides a macro \xmathstrut[]{} which helps with that.
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{float}
\usepackage{mathtools}
\NewExpandableDocumentCommand{\spr}{m}{\specialrule{#1}{0pt}{0pt}}
\begin{document}
\begin{table}[H]
\renewcommand*{\arraystretch}{1.25}
\DeclareDocumentCommand{\heavyrulewidth}{}{2pt}
\DeclareDocumentCommand{\lightrulewidth}{}{2pt}
\[
\begin{array}{l#{\hspace{0.5em}}l|c}
\spr{\heavyrulewidth}
\mathrlap{Case} & & \beta_H^{*} \\
\spr{\lightrulewidth}
(1) & I & p(-p-q_I+1) \\
\spr{0.4pt}
(2) & I+H+L & \frac{
\splitfrac{
\scriptstyle 2q_I\gamma_H(\gamma_H - \gamma_L)
}{\splitfrac{
\scriptstyle -(2p\gamma_H - 2p + q_I\gamma_H)
}{
\scriptstyle (3\gamma_H\gamma_L - 4\gamma_H + \gamma_L)
}
}
}{4q_I\gamma_H(\gamma_H - \gamma_L)}\xmathstrut[0.75]{2.5} \\
\spr{\heavyrulewidth}
\end{array}
\]
\end{table}
\begin{table}[H]
\renewcommand*{\arraystretch}{2}
\DeclareDocumentCommand{\heavyrulewidth}{}{1.2pt}
\DeclareDocumentCommand{\lightrulewidth}{}{0.8pt}
\setlength\extrarowheight{-2pt}
\[
\begin{array}{l#{\hspace{0.5em}}l|c}
\spr{\heavyrulewidth}
\mathrlap{Case} & & \beta_H^{*} \\
\spr{\lightrulewidth}
(1) & I & p(-p-q_I+1) \\
\spr{0.4pt}
(2) & I+H+L & \dfrac{1}{2}
- \dfrac{
(2p\gamma_H - 2p + q_I\gamma_H)(3\gamma_H\gamma_L - 4\gamma_H + \gamma_L)
}{
4q_I\gamma_H(\gamma_H - \gamma_L)
}\xmathstrut{1.25}\\
\spr{\heavyrulewidth}
\end{array}
\]
\end{table}
\end{document}

Problems in formatting table and closing tables "boxes" in latex

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}

White space in siunitx columns

I am trying to format a table of numbers with units using the siunitx package to align the numbers on the decimal.
I am having trouble controlling the amount of white space that siunitx is allocating to the display of numbers.
Here is an example. I would like the numbers in the first column to be closer to the right, as they are in the third column, and I would like there to be less space on the left of numbers in the third column. (The vertical lines are ugly, I know, but they show the column widths.)
\documentclass[10pt,a4paper]{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{|S|r|S|r|}
\multicolumn{2}{c}{Range} & \multicolumn{2}{c}{Readout} \\
\hline
10 & mV & 0.000049 & mV \\
100 & V & 0.00007 & mV \\
\end{tabular}
\end{document}
EDIT
As a continuation of this question, I am trying to find a way to report numbers and units in the same column, with a single (or at least uniform) space between them. But again whitespace is hard to control. For example,
\begin{tabular}{
S|
S|
S[table-format=1.9]
}
{Range} & {Readout} & {Uncertainty} \\
\hline
10 {mV} & 0.000022~{mV} & 0.000069 {mV}\\
100 {mV} & -0.00001~{mV} & 0.00011 {mV}\\
1 {V} & -0.0000007~{V} & 0.00000029 V\\
10 {V} & -0.000007~{V} & 0.0000029 V\\
100 {V} & -0.000075~{V} & 0.000058 V\\
\end{tabular}
which produces this
Here, in the first column, space is inserted after the numbers depending on how big the mantissa is; in the second column there is too much white space on the left of the numbers; in the third column, the space between the number and unit allows for a certain number of digits.
Also, the use of ~ in the second column seems necessary. Without it, the text is joined directly to the number. I have played with table-align-text-post and -pre, as described in the siunitx docs, but they don't seem to work here. I thought they would.
You can specify how many digits are before and after the decimal marker. The syntax is table-format=<digits before marker>.<digits after the marker>
\documentclass[10pt,a4paper]{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{|S[table-format=3.0]|r|S[table-format=1.6]|r|}
\multicolumn{2}{c}{Range} & \multicolumn{2}{c}{Readout} \\
\hline
10 & mV & 0.000049 & mV \\
100 & V & 0.00007 & mV \\
\end{tabular}
\end{document}

Extra alignment in tabular array

I am trying to center one of the columns in a table and It says I have an extra column. The table also doesnt look correct i.e.
What it looks like:
F(t) F(s)
u(t)
1/s
e 1/(s-a)
What I expect:
F(t) F(s)
u(t) 1/s
e 1/(s-a)
I think it is because I'm trying to insert an equation in the table but I'm not sure.
Here is the code
\documentclass[12pt, letterpaper, fleqn]{article}
\usepackage{array}
\begin{document}
\begin{table}
% \setlength{\tabcolsep}{6pt}
% \renewcommand{\arraystretch}{1}
\begin{tabular}{p{0.225\textwidth} >{\centering}p{0.15\textwidth}}
\textbf{F(t)} & \textbf{F(s)} \\
\(u(t)\) & \(\frac{1}{s}\) \\
\(e^{at}\) & \(\frac{1}{s-a}\) \\
\end{tabular}
\end{table}
\end{document}
Your use of \centering to centre the column works, but it screws up the way \\ is interpreted. A correction is included in the array package documentation after using alignment switches (like \centering, \raggedright, \raggedleft, etc) using \arraybackslash:
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{ p{0.225\textwidth} >{\centering\arraybackslash}p{0.15\textwidth} }
$\mathbf{F(t)}$ & $\mathbf{F(s)}$ \\
$u(t)$ & $1 / s$ \\
$e^{at}$ & $1 / (s - a)$
\end{tabular}
\end{document}
If you remove >{\centering}, then your code should compile as expected. Post a comment otherwise! Do you want any column to have centered contents?

How to insert manual line breaks inside LaTeX tables?

I know that if you define a width in a table's column, you can get automatic word-wrapping.
However, I need to control where newlines should happen in a specific table cell.
Thus, how can I insert manual line breaks in a LaTeX table cell?
Usually, you use a column definition like p{3cm} instead of l, and then use \newline instead of \\ in the cell body.
You could do it like this:
\documentclass{report}
\begin{document}
\begin{tabular}{|l|l|}
\hline
A & B \\
& C \\
\hline
D & E \\
\hline
\end{tabular}
\end{document}
which produces:
The command \shortstack can be used to wrap cell content and use \\ inside it:
\begin{tabular}{|l|l|}
\hline
one line & \shortstack{two\\ lines} \\
\hline
XX & YYY \\
\hline
\end{tabular}
EDIT: however I just realised that interline spacing might differ between your columns. So it's not the prettiest solution.
It can be achieved by using \newline. Since, the accepted answer did not have any sample snippet, a working sample is provided here:
\begin{tabular}{p{2cm} p{10cm}}
\em{Programming} \textsc{languages} & Java, Node.js, Python, Clojure \\
\newline & \newline \\
\em{Development systems} & Concurrent Programming, Design Patterns
\end{tabular}
You can do like Bart suggested above and combine with multirow to centralize single line texts.
\begin{table}[h]
\centering
\caption{Optimized models (Softmax) final results with confidence intervals.}
\begin{tabular}{|c|c|c|c|c|}
\hline
\multirow{2}*{Architecture} & Batch & N. & Learning & \multirow{2}*{Micro-F1} \\
& size & epochs & rate & \\
\hline
ResNet50& 64 & 60 & $5\times10^{-3}$ & $(\textbf{0.7683} \pm 0.0223)$ \\
\hline
ResNet152\_V2& 64 & 40 & $5\times10^{-4}$ & $(0.6698 \pm 0.0467)$\\
\hline
\end{tabular}
\label{final_result_softmax}
\end{table}
Yields:
\newline works to break a line within a cell in tabularx environment.

Resources