Alternative to Bordermatrix for MathJax - latex

I'm using bordermatrix to write matrix with coefficient on the top and on the left:
I would like to display a similar matrix on my website where I use Mathjax but I get a [Math Processing Error]. Do you have a MathJax-alternative to bordermatrix to get the same result?

You can use the following construction:
\begin{align}
f(x) &= ax^2 + bx + c \\
&= \begin{array}{c c}
& \begin{array} {#{} c c c #{}}
u_1 & \cdots & u_q
\end{array} \\
\begin{array}{c}
e_1 \\ \vdots \\ e_n
\end{array}\hspace{-1em} &
\left(
\begin{array}{#{} c c c #{}}
u_{11} & \cdots & u_{1q} \\
\vdots & & \vdots \\
u_{n1} & \cdots & u_{nq}
\end{array}
\right) \\
\mbox{} % Blank line to match column names so as to align the = vertically
\end{array} \\[-12pt] % Correction for blank line
&= ax^2 + bx + c
\end{align}
Depending on whether you're aligning it with other content, you might not need the vertical adjustment I inserted.
Tested on Math.SE.

Related

How to draw matrices with a label in a latex figure?

I want to create tables as part of a figure in latex. I want to achieve this look:
I have no idea which package/commands to use.
Nothing fancy here; just some math as part of the figure environment:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.4\linewidth]{example-image}
\medskip
$\sigma_1 \rightarrow \sigma_2 :
\begin{array}{ | *{5}{c|} }
a & b & c & e & f \\
\hline
a & b & c & e & f
\end{array}$ \quad
$\sigma_1 \rightarrow \sigma_3 :
\begin{array}{ | *{5}{c|} }
a & b & c & e & f \\
\hline
a & b & c & \gg & f
\end{array}$
\caption{A figure caption}
\end{figure}
\end{document}

Changing latex table text direction?

I want to change the table generated by the following code so that the first column looks like the figure below by 1- changing the text direction in the first column. I made some changes regarding this post but still have a problem.
Desired output:
Current output:
\begin{table}[h!]
\centering
\caption[Transformation table]{Transformations generated by Mach et al. Y in a dark cell: highly recommended, Y in a light cell: usable, N in a dark cell: unusable \label{tab:power}}
\begin{tblr}{
colspec={XXXXXX},
vlines,
hlines,
cells={halign=c},
column{1-2}={halign=l},
hspan=even,
}
& \SetCell[c=5]{halign=c,bg=gray,fg=white} Type of Distribution & & & &\\
\SetCell[r=5]{bg=gray,fg=white} \parbox[t]{2mm}{\multirow{5}{*}{\rotatebox[origin=c]{90}{Type of \\ Transformation}}} & & Lognormal & Exponential & Gamma & Weibull \\
& Box-Cox & Y & Y & \SetCell{bg=lightgray,font=\bfseries} Y & \SetCell{bg=lightgray,font=\bfseries} Y \\
& Exponential & Y & Y & Y & Y\\
& Simple power & Y & \SetCell{bg=lightgray,font=\bfseries} Y & \SetCell{bg=lightgray,font=\bfseries} Y & \SetCell{bg=lightgray,font=\bfseries} Y \\
& Logarithmic & \SetCell{bg=lightgray,font=\bfseries} Y & Y & \SetCell{font=\bfseries} N & \SetCell{font=\bfseries} N \\
\end{tblr}
\end{table}
\begin{table}[H]
\centering
\begin{tabular}{|c|l|r|r|r|r|}
\hline
& \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{text}\\
\hline
\rotatebox{90}{\parbox{2mm}{\multirow{3}{*}{rota}}} & text &&&&\\
& text &&&&\\
& text &&&&\\
\hline
\end{tabular}
\end{table}
Use the \rotatebox before the \parbox (and don't use \multirow in a tblr, that's no longer defined there):
---
title: "misc"
author: "Me"
date: "`r Sys.Date()`"
output:
pdf_document:
keep_tex: true
extra_dependencies: caption
number_sections: yes
fig_caption: yes
classoption: table
header-includes:
- \usepackage{tabularray}
language:
label:
fig: !expr function(x) sprintf("**Figure %s.** ", x)
fontsize: 11pt
urlcolor: blue
---
\begin{table}[h!]
\centering
\caption[Transformation table]{Transformations generated by Mach et al. Y in a dark cell: highly recommended, Y in a light cell: usable, N in a dark cell: unusable \label{tab:power}}
\begin{tblr}{
colspec={lXXXXX},
vlines,
hlines,
cells={halign=c},
column{1-2}={halign=l},
vspan=even,
cell{1}{2}={halign=c,bg=gray,fg=white},
cell{2}{1}={bg=gray,fg=white},
cell{3}{5-6}={bg=lightgray,font=\bfseries},
cell{5}{4-6}={bg=lightgray,font=\bfseries},
cell{6}{3}={bg=lightgray,font=\bfseries},
}
& \SetCell[c=5]{} Type of Distribution & & & &\\
\SetCell[r=5]{} \rotatebox{90}{\parbox{3.5cm}{\centering Type of Transformation}} & & Lognormal & Exponential & Gamma & Weibull \\
& Box-Cox & Y & Y & Y & Y \\
& Exponential & Y & Y & Y & Y\\
& Simple power & Y & Y & Y & Y \\
& Logarithmic & Y & Y & N & N \\
\end{tblr}
\end{table}

Remove indent in equation LaTex

I have a rather simple problem. I have an unwanted indent in my equation.
\documentclass[11 pt, a4paper, fleqn]{article}
\usepackage{float}
\usepackage{amssymb}
\usepackage{amsmath}
\setlength{\mathindent}{0cm}
\begin{document}
\noindent Through rigorous analytical calculations found in \textbf{Appendix A} a state space representation was found:
\begin{multline}
X= \begin{pmatrix}\dot{x_1} \\ \dot{x_2} \\ \dot{x_3} \end{pmatrix} =
\begin{pmatrix}0 & 1 & 0\\ 0 & 0 & 1 \\ -1000 & -300 & -30\end{pmatrix}
\begin{pmatrix}x_1 \\ x_2 \\ x_3 \end{pmatrix}+\begin{pmatrix} 0 \\ 0 \\ 160 \end{pmatrix}u \\
\noindent Y=\begin{pmatrix}1 & 0 & 0 \end{pmatrix} \begin{pmatrix}
x_1 \\ x_2 \\ x_3 \end{pmatrix}
\end{multline}
\end{document}
Which give me this result:
enter image description here
I would like to have the second line at the left margin.
I have tried using \[ \begin{aligned} \end{aligned} \] and at the before I begin my document I have the command \setlength{\mathindent}{0cm} but still the indent persists. It's driving me quite mad.
Please and thank you!
edit: made compileable
You can use:
\begin{align}
X &= \begin{pmatrix}\dot{x_1} \\ \dot{x_2} \\ \dot{x_3} \end{pmatrix} =
\begin{pmatrix}0 & 1 & 0\\ 0 & 0 & 1 \\ -1000 & -300 & -30\end{pmatrix}
\begin{pmatrix}x_1 \\ x_2 \\ x_3 \end{pmatrix}+\begin{pmatrix} 0 \\ 0 \\ 160 \end{pmatrix}u \\
Y &=\begin{pmatrix}1 & 0 & 0 \end{pmatrix} \begin{pmatrix}
x_1 \\ x_2 \\ x_3 \end{pmatrix}
\end{align}
Use align* if you don't want line numbers.
I hope that works!
The multiline environment is specifically meant for a single equation which is too long for one line. The first line will align to the left, the second to the right.
If you want to align multiple different equations, I would use something like the align environment as #HelloWorld shows in their answer.
However just for completeness, you can also do this with multiline:
\documentclass[11 pt, a4paper, fleqn]{article}
\usepackage{float}
\usepackage{amssymb}
\usepackage{amsmath}
\setlength{\mathindent}{0cm}
\begin{document}
\noindent Through rigorous analytical calculations found in \textbf{Appendix A} a state space representation was found:
\begin{multline}
X= \begin{pmatrix}\dot{x_1} \\ \dot{x_2} \\ \dot{x_3} \end{pmatrix} =
\begin{pmatrix}0 & 1 & 0\\ 0 & 0 & 1 \\ -1000 & -300 & -30\end{pmatrix}
\begin{pmatrix}x_1 \\ x_2 \\ x_3 \end{pmatrix}+\begin{pmatrix} 0 \\ 0 \\ 160 \end{pmatrix}u \\
Y=\begin{pmatrix}1 & 0 & 0 \end{pmatrix} \begin{pmatrix}
x_1 \\ x_2 \\ x_3 \end{pmatrix}\hfill
\end{multline}
\end{document}

Right margin in table cells aligned to the right in Latex

I have the following table in Latex
Created with this code:
\begin{table}[h]
\caption{aaaa}
\label{tab:treatments}
\centering
\scalebox{0.8}{
\begin{tabular}{l c c c}
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{Quantificazione log-dim} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\%& 5.4\\
B& A & 2.0\%& 4.6\\
C & N & 5.8\% & 4.6\\
D & N & 3.5\% & 4.26\\
E & K & 22.5\% & 3.7\\
\bottomrule\\
\end{tabular}
}
\end{table}
I would like to have the third column of percentages aligned to the right
At the same time the column label is too large. If I aligned the column to the right it would and up visually weird.
In a Word table I would align the column to the right and than add a right margin to the cells. The numbers would move toward the cell center while keeping their alignment to the right.
How do I do that in Latex? How do I add a margin to the right?
There are a number of options you can try:
Original:
Multi-row header:
Manual alignment of centred columns using \phantoms:
Manual alignment of centred columns using \eqmakeboxes (from eqparbox):
Automated alignment of centred columns using siunitx:
\documentclass{article}
\usepackage{booktabs,graphicx,makecell,siunitx,eqparbox}
\newcommand{\tabhead}{\textbf}
\begin{document}
Original:
\begin{tabular}{ l c c c }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{Quantificazione log-dim} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\% & 5.4 \\
B & A & 2.0\% & 4.6 \\
C & N & 5.8\% & 4.6 \\
D & N & 3.5\% & 4.26 \\
E & K & 22.5\% & 3.7 \\
\bottomrule
\end{tabular}
\bigskip
Multi-row header:
\begin{tabular}{ l c c c }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{\makecell[b]{Quantificazione \\ log-dim}} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\% & 5.4 \\
B & A & 2.0\% & 4.6 \\
C & N & 5.8\% & 4.6 \\
D & N & 3.5\% & 4.26 \\
E & K & 22.5\% & 3.7 \\
\bottomrule
\end{tabular}
\bigskip
Manual alignment of centred columns using \verb|\phantom|s:
\begin{tabular}{ l c c c }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{\makecell[b]{Quantificazione \\ log-dim}} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\% & 5.4\phantom{0} \\
B & A & \phantom{0}2.0\% & 4.6\phantom{0} \\
C & N & \phantom{0}5.8\% & 4.6\phantom{0} \\
D & N & \phantom{0}3.5\% & 4.26 \\
E & K & 22.5\% & 3.7\phantom{0} \\
\bottomrule
\end{tabular}
\bigskip
Manual alignment of centred columns using \verb|\eqmakebox|es:
\begin{tabular}{ l c c c }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{\makecell[b]{Quantificazione \\ log-dim}} & \tabhead{cintin\'a} \\
\midrule
A & M & \eqmakebox[log][r]{99.3\%} & \eqmakebox[cint][l]{5.4} \\
B & A & \eqmakebox[log][r]{ 2.0\%} & \eqmakebox[cint][l]{4.6} \\
C & N & \eqmakebox[log][r]{ 5.8\%} & \eqmakebox[cint][l]{4.6} \\
D & N & \eqmakebox[log][r]{ 3.5\%} & \eqmakebox[cint][l]{4.26} \\
E & K & \eqmakebox[log][r]{22.5\%} & \eqmakebox[cint][l]{3.7} \\
\bottomrule
\end{tabular}
\newpage
Automated alignment of centred columns using \verb|siunitx|:
\begin{tabular}{ l c S[table-format = 2.1, table-space-text-post = \%] S[table-format = 1.2] }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{\makecell[b]{Quantificazione \\ log-dim}} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\% & 5.4 \\
B & A & 2.0\% & 4.6 \\
C & N & 5.8\% & 4.6 \\
D & N & 3.5\% & 4.26 \\
E & K & 22.5\% & 3.7 \\
\bottomrule
\end{tabular}
\end{document}

avoid latex table thicker line

I make a table like this one :
\documentclass[pdfa,sl,draft,english]{letter}
\usepackage[flushleft]{threeparttable}
\begin{document}
\begin{table}
\begin{center}
\begin{threeparttable}
\caption{Table caption}
\begin{tabular}{ | c | c| c | c |}
\hline
a
& \multicolumn{1}{|p{3cm}|}{\centering b \\ (unit) }
& c ${}^{a}$
& d ${}^{b}$ \\ \hline
1 & 1b & 1c & 1d \\
2 & 2b & 2c & 2d \\ \hline
\end{tabular}
\begin{tablenotes}
\small
\item ${}^{a}$ Note for c column
\item ${}^{b}$ Note for d column
\end{tablenotes}
\end{threeparttable}
\end{center}
\end{table}
\end{document}
The compilation make a thicker right line on the first column and first row. Do you have an idea to avoid this?
This works. It is a bit of a hack, but essentially you set the columns to a width that you predefine. It seems to look okay like this.
\documentclass[pdfa,sl,draft,english]{letter}
\usepackage[flushleft]{threeparttable}
\usepackage{makecell}
\newcolumntype{?}{!{\vrule width 0.1pt}}
\begin{document}
Table With Bold Line
\begin{tabular}{ | c | c | c | c |}
\hline
a
& \multicolumn{1}{|p{3cm}|}{\centering b \\ (unit) }
& c ${}^{a}$
& d ${}^{b}$ \\ \hline
1 & 1b & 1c & 1d \\
2 & 2b & 2c & 2d \\ \hline
\end{tabular}
Table Without Bold Line
\begin{tabular}{ ? c ? c ? c ? c ?}
\hline
a
& \multicolumn{1}{|p{3cm}|}{\centering b \\ (unit) }
& c ${}^{a}$
& d ${}^{b}$ \\ \hline
1 & 1b & 1c & 1d \\
2 & 2b & 2c & 2d \\ \hline
\end{tabular}
\end{document}

Resources