Latex Long Equations Alignment in single column - latex

I need multiple equations aligned in single column of a two columned document. I have tried a mixture of both align and multiline but it does not work.
\documentclass[12pt,journal,compsoc]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\begin{document}
\maketitle
\section{Introduction}
\begin{align*}
p(W_{i},T_{n})&=\begin{multline*}
p(W_{i},T_{n})\\+(p(W_{i},T_{n})*k/100)
\end{multline*}\\
p(W_{i},T_{n})&=\begin{multline*}
p(W_{i},T_{n})\\+(p(W_{i},T_{n})*k/100)
\end{multline*}\\
\end{align*}
\end{document}
It gives me the error
Package amsmath Error :\begin{multline*} allowed only in paragraph mode

There's no need for multline here; a regular align will do:
\documentclass[journal,compsoc]{IEEEtran}
\usepackage{amsmath,lipsum}
\begin{document}
\section{Introduction}
\lipsum*[1]
\begin{align*}
p(W_i, T_n) ={}& p(W_i, T_n) \\
& + (p(W_i, T_n) \times k / 100) \\
p(W_i, T_n) ={}& p(W_i, T_n) \\
& + (p(W_i, T_n) \times k / 100)
\end{align*}
\lipsum*[2]
\end{document}
Since you're aligning with a line-break, it's easier to use ={}& as opposed to the traditional &= (which would require additional \phantoms to ensure proper alignment).

Related

Aligning tags in a table [Latex] [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 days ago.
Improve this question
I am using the following code to create a table in Latex:
\begin{table}[]
\centering
\renewcommand{\arraystretch}{1}
\caption{Example table.}
\label{tab:model-testbed}
\renewcommand{\arraystretch}{1.1}
\resizebox{\linewidth}{!}{%
\begin{tabular}{|c|l|l|}
\hline
Comment & \multicolumn{1}{c|}{Device1} & \multicolumn{1}{c|}{Device2} \\ \hline
\begin{tabular}[c]{#{}c#{}}BlaBla \\ Sth \end{tabular} &
\begin{tabular}[c]{#{}l#{}}
\begin{equation}
\tag{1}\label{t3:1}
\begin{aligned}
y(x) = 66.1 + 1.11x - 1.28 \times 10^{-8}x^2 \\ +15.08 \times 10^{-2}x^1
\end{aligned}
\end{equation}
\end{tabular} &
\begin{tabular}[c]{#{}l#{}}
\begin{equation}
\tag{2}\label{t3:2}
\begin{aligned}
y(x) =20.33 + 1.24y - 1.74 \times 10^{-1}x^5 \\ + 1.14 \times 10^{-7}y^5
\end{aligned}
\end{equation}
\end{tabular} \\ \hline
\begin{tabular}[c]{#{}c#{}}BlaBla \\ Sth\end{tabular} &
\begin{equation}
\tag{3}\label{t3:3}
\begin{aligned}
w(x) =2.13 + 0.03x
\end{aligned}
\end{equation}
&
\begin{equation}
\tag{4} \label{t3:4}
\begin{aligned}
er(x) =4.85 + 33.56y
\end{aligned}
\end{equation}
\\ \hline
\begin{tabular}[c]{#{}c#{}}BlaBla\\ Sth\end{tabular} &
\begin{equation}
\tag{5}\label{t3:5}
\begin{aligned}
b(x) =12.2 + 5.20y
\end{aligned}
\end{equation}
&
\begin{equation}
\tag{6}\label{t3:6}
\begin{aligned}
a(x) =1.11 + 1.11x - 2.543 \times 10^{-2}x^2
\end{aligned}
\end{equation}
\hline
\end{tabular}}
\end{table}
And it outputs the following table:
I am struggling to find a way how to align the tags. As you can see next to each formula there is a tag (1), (3), etc. , and it is positioned right next to the equation. But, I would like all the tags to be aligned. I tried with \hspace{1cm} to try to move them to the left, hoping that I can position them to the end of the column and with it align them, but it did not work.
Does anyone have an idea how I could do it?
You would need to wrap "display" equations inside minipages. The tags would correctly be pushed to the right. However, equations get centred w.r.t. surrounding environment.
One way to achieve left alignment with right tags is to add equations in-line and then use \tag{} separately. However, the latter is not allowed outside equations. It can be sorted out by manually setting the #currentlabel for very next \label{} usage; I have made a macro for that--its optional star removes parentheses in case you don't want them.
A couple remarks. I added geometry to increase the page width for demonstration because this table gets quite wide. Sometimes, environments like equations cause issues with the standard vertical spacing and this needs a manual adjustment. There are other table-related packages that sort it out, e.g. tabularray but here I have used a strut: \xmathstrut{factor} from mathtools. Also, for multi lined texts, I'd suggest to use \makecell from makecell--a very convenient macro that allows line breaks. EDIT. the vertical spacing could also be sorted by increasing so-called "gape" inside makecells--I'll leave it for you.
Here's the example
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{array}
\usepackage{makecell}
\usepackage{mathtools}
\makeatletter
\NewDocumentCommand\refanchor{sm}{
% #1 star removes partheses
% #2 reference label
\IfBooleanF{#1}{(}#2\IfBooleanF{#1}{)}
\protected#edef\#currentlabel{#2}}
\makeatother
\begin{document}
References: eq.~\ref{t3:1} on page \pageref{t3:1}.
References with parentheses: eq.~\eqref{t3:3} on page \pageref{t3:3}.
\begin{table}[tbh]
\renewcommand{\arraystretch}{1.5}
\small
\centering
\caption{Example table.}\label{tab:model-testbed}
\begin{tabular}{|c|l#{}|l#{}|}
\hline
Comment
& \multicolumn{1}{c|}{Device1}
& \multicolumn{1}{c|}{Device2} \\
\hline
\makecell{BlaBla\\Sth}
&
\begin{minipage}{0.4\linewidth}
\(\xmathstrut{1.25}
\begin{aligned}
y(x) = 66.1 + 1.11x - 1.28 \times 10^{-8}x^2 \\
+15.08 \times 10^{-2}x^1
\end{aligned}\)%
\hfill
\refanchor{1}\label{t3:1}
\end{minipage}
&
\begin{minipage}{0.4\linewidth}
\(
\begin{aligned}
y(x) =20.33 + 1.24y - 1.74 \times 10^{-1}x^5\\
+1.14 \times 10^{-7}y^5
\end{aligned}\)
\hfill
\refanchor{2}\label{t3:2}
\end{minipage} \\
\hline
\makecell{BlaBla\\Sth}
&
\begin{minipage}{0.4\linewidth}
\(\xmathstrut{1.15} w(x) =2.13 + 0.03x \)%
\hfill
\refanchor{3}\label{t3:3}
\end{minipage}
&
\begin{minipage}{0.4\linewidth}
\(er(x) = 4.85 + 33.56y\)%
\hfill
\refanchor*{4}\label{t3:4}
\end{minipage}
\\ \hline
\end{tabular}
\end{table}
\end{document}

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}

LuaLaTeX: horitontal alignment of verbatim-environments inside a tabularx-environment

First, I'm fully aware that my code is probably not the ideal way to realize what I want to do. However I'm not a professional LaTeX User and this is the way I figured out.
I made a minimal example that hopefully works when compiled(compiler: LuaLaTeX) to display my problem.
I'm trying to make a beamer-frame with a tabularx-table, which contains in-line verbatim-environments on the one hand and equation-environments on the other. The "Y" column-type is a modified form of the "X" environment of tabularx, which I found on another Stackoverflow-thread.
The precise problem now is the following: I'd like the verbatim-expressions to be aligned with the equation-expressions or at least to be vertically centered in each cell.
As mentioned, I'm far from being an expert and I've exhausted all of my Ideas, so I'm very thankful for any form of ideas and suggestions. :)
\documentclass[c, 10pt]{beamer}
\usepackage{polyglossia}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{placeins}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{nicefrac}
\usepackage{array}
\setdefaultlanguage{english}
\usetheme{JuanLesPins}
\usecolortheme{seahorse}
\newcolumntype{Y}{>{\centering\arraybackslash} X}
\begin{document}
\begin{frame}[fragile, allowframebreaks]{Symbols and Commands}
\begin{block}{\centering \large{Division}}
\begin{table}[h]
\centering
\renewcommand\baselinestretch{0.01}\selectfont
\begin{tabularx}{\textwidth}{Y Y Y}
\toprule
\multicolumn{1}{m{.3\textwidth}}{\centering Code} & \multicolumn{2}{m{.6\textwidth}}{\centering Examples}\\
\midrule
\verb|\dfrac{a}{b}| &
{\begin{equation*}
\dfrac{a}{b}
\end{equation*}} &
{\begin{equation*}
\mathrm{e}^{\dfrac{1}{k_BT}}
\end{equation*}} \\
\verb|\frac{a}{b}| &
{\begin{equation*}
\frac{a}{b}
\end{equation*}} &
{\begin{equation*}
\mathrm{e}^{\frac{1}{k_BT}}
\end{equation*}} \\
\verb|\nicefrac{a}{b}| &
{\begin{equation*}
\nicefrac{a}{b}
\end{equation*}} &
{\begin{equation*}
\mathrm{e}^{\nicefrac{1}{k_BT}}
\end{equation*}} \\
\bottomrule
\end{tabularx}
\end{table}
\end{block}
\end{frame}
\end{document}
To place unnumbered equations in a table, I would rather use inline math instead of equation environments. To get the same rendering of fractions as in equations, add \displaystyle.
Off-topic:
don't load packages multiple times
don't use fragile, allowframebreaks unless they are really necessary for the frame
floating specifier like [H] don't make sense in a document class without floating mechanism
you don't need \centering in beamer tables, they are centred by default
the syntax \large{...} is wrong, \large is a switch and does not take an argument, so it should be \large Division. Anyway it would be better to not put formatting instructions inside an macro argument, but to set the appropriate beamer template that controls the font of the block title
\documentclass[c, 10pt]{beamer}
%\usepackage{polyglossia}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{tabularx}
%\usepackage{amsmath}
%\usepackage{amssymb}
%\usepackage{siunitx}
%\usepackage{placeins}
\usepackage{multirow}
\usepackage{booktabs}
%\usepackage{verbatim}
%\usepackage{fancyvrb}
\usepackage{nicefrac}
\usepackage{array}
%\setdefaultlanguage{english}
\usetheme{JuanLesPins}
\usecolortheme{seahorse}
\newcolumntype{Y}{>{\centering\arraybackslash} X}
\setbeamerfont{block title}{size=\large}
\begin{document}
\begin{frame}
\frametitle{Symbols and Commands}
\begin{block}{\centering Division}
\begin{table}
% \centering
% \renewcommand\baselinestretch{0.01}\selectfont
\begin{tabularx}{\textwidth}{Y Y Y}
\toprule
Code & \multicolumn{2}{c}{Examples}\\
\midrule
\verb|\dfrac{a}{b}| &
$\displaystyle\dfrac{a}{b}$ &
$\displaystyle\mathrm{e}^{\dfrac{1}{k_BT}}$ \\\addlinespace
\verb|\frac{a}{b}| &
$\displaystyle\frac{a}{b}$ &
$\displaystyle\mathrm{e}^{\frac{1}{k_BT}}$ \\\addlinespace
\verb|\nicefrac{a}{b}| &
$\displaystyle\nicefrac{a}{b}$ &
$\displaystyle\mathrm{e}^{\nicefrac{1}{k_BT}}$ \\
\bottomrule
\end{tabularx}
\end{table}
\end{block}
\end{frame}
\end{document}

Box in commutative diagram

In the following commuting diagram, I would like to draw a box containing the bottom triangle defined by nodes D, E and F. Do you know how I could do that?
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}[row sep=2.5em]
& \text{A} \\
\arrow[rightarrow]{d}{R_4}\text{B} \arrow[leftarrow]{ur}{R_1}
\arrow[dashed,leftrightarrow]{rr}{R_3} && \text{C} \\
\arrow[leftrightarrow]{rd}{R_1}\text{D}\arrow[leftrightarrow]{rr}{R_3} & &
\text{E} \arrow[leftrightarrow]{ld}{R_2}\\
& \text{F} &
\end{tikzcd}
\]
\end{document}
Searching here and there, I put together the following:
\documentclass{article}
\usepackage{amsmath}
%\usepackage{tikz-cd}
\usepackage{tikz}
\usetikzlibrary{cd}
\usetikzlibrary{fit, patterns}
\begin{document}
\[
\tikz[%remember picture,
overlay]{
\filldraw[fill=yellow!50,draw=red!50!yellow] (-.5,-3.2) rectangle (3.8,-.4);
}
\begin{tikzcd}[row sep=2.5em]
& \text{A} \\
\arrow[rightarrow]{d}{R_4}\text{B} \arrow[leftarrow]{ur}{R_1}
\arrow[dashed,leftrightarrow]{rr}{R_3} && \text{C} \\[3em]
\arrow[leftrightarrow]{rd}{R_1}\text{D}\arrow[leftrightarrow]{rr}{R_3} & &
\text{E} \arrow[leftrightarrow]{ld}{R_2}\\
& \text{F} &
\end{tikzcd}
\]
\end{document}
It outputs:
I didn't edit any of your code within \[ and \], except for adding [3em] in line 18 for the sake of vertical spacing.
The style (colors, margins) may be changed up to your personal taste!

How to center a vector in latex

I am using latex for my report. I am stuck in centering a vector. This is my latex code:
\begin{equation}
\centering
X_{i}=
$$\begin{bmatrix}
C_1\\
C_2\\
C_3\\
\vdots\\
\vdots\\
\vdots\\
\vdots\\
C_n\\
OlValue\\
\end{bmatrix}$$
\label{Vect}
\end{equation}
The centering command doesn't work. I tried several things but the vector is not on the center.
You're doing it wrong...
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent
X \dotfill X% To show the horizontal text width/margins
\begin{equation}
X_i =
\begin{bmatrix}
C_1 \\ C_2 \\
\vdots \\
C_n
\end{bmatrix}
\end{equation}
\end{document}
Don't use \centering inside an equation. Also don't use $$...$$. The equation environment automatically centres its contents, period.

Resources