Changing latex table text direction? - latex

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}

Related

Changing dimensions (height and width ) of latex table generated tabularray

I need to make the LaTeX table generated here smaller in height either by changing the total height or each row height, whichever looks better. How can I do that?
Here is the code:
\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}
The extra height comes from the \parbox. If you reduce the width of the \parbox a bit, the rows become less tall.
If you need the rows to be even narrower, you can change the rowsep (but you'll have to ditch the idea of rotated text then).
\documentclass[11pt]{article}
\usepackage{tabularray}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{graphicx}
\begin{document}
\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},
% rowsep = 0mm
}
& \SetCell[c=5]{} Type of Distribution & & & &\\
\SetCell[r=5]{} \rotatebox{90}{\parbox{2.6cm}{\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}
\end{document}

How to remove middle horizontal line in a table in Overleaf

I have a table in Overleaf. I want to remove the horizontal line (crossing the number 0.3). I know I can use \cline{} command to remove some horizontal lines, but I do not know how to use the combination of them.
\begin{tabular}{l|c|c|c|c|c}
\hline
\multirow{2}{*}{Aspects} & Probability & \multicolumn{4}{c}{Methods} \\
\cline{3-6}
& for DE Genes & Binomial Test & Tangram & stereoscope & BayesPrism\\
\cline{3-6}
AUC & \multirow{2}{*}{0.3} & 0.519 & -0.261 & -0.020 & 0.996 \\
\cline{1-2}
\cline{3-6}
Best thresholds & &$0.398$ & $0.019$ & 0.204 & ${\rm e}^{-50}$\\
\hline
\end{tabular}
\caption{The ROC Curve Summary for Data with 5 Clusters with Probability 0.05 for DE
Genes}
\label{5 cluster 0.05}
\end{table}
The table looks like this.
If you want the line only in the first column, use \cline{1-1} instead of \cline{1-2} which will draw it over the first two columns.
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{l|c|c|c|c|c}
\hline
\multirow{2}{*}{Aspects} & Probability & \multicolumn{4}{c}{Methods} \\
\cline{3-6}
& for DE Genes & Binomial Test & Tangram & stereoscope & BayesPrism\\
\cline{3-6}
AUC & \multirow{2}{*}{0.3} & 0.519 & -0.261 & -0.020 & 0.996 \\
\cline{1-1}
\cline{3-6}
Best thresholds & &$0.398$ & $0.019$ & 0.204 & ${\rm e}^{-50}$\\
\hline
\end{tabular}
\end{document}

LaTeX - tabular start at new line

I want to start the tabular at start of line, but when I put it directly after e.g. \paragraph{Foo}, than It will be displayed at right side of 'Foo'.
\documentclass[twocolumn,a4,titlepage]{article}
\begin{document}
\section{foo}
\paragraph{A}
\begin{tabular}{ccc}
X & Y & Z \\
X & Y & Z \\
X & Y & Z \\
\end{tabular}
\paragraph{B}
\begin{tabular}{ccc}
X & Y & Z \\
X & Y & Z \\
X & Y & Z \\
\end{tabular}
\end{document}
I know, I could put it between \begin{center} and \end{center}, but than it would float around (i.e. will sometimes be displayed after the following text) and will be centered, which looks strange for small tables.
I strongly believe that this question is already answered elsewhere, but I couldn't find it.
Thanks!!
You can force the table to start in a new line like this:
\documentclass[twocolumn,a4,titlepage]{article}
\begin{document}
\section{foo}
\paragraph{A}
\begin{tabular}{ccc}
X & Y & Z \\
X & Y & Z \\
X & Y & Z \\
\end{tabular}
\paragraph{B}\mbox{}\par
\noindent\begin{tabular}{#{}ccc}
X & Y & Z \\
X & Y & Z \\
X & Y & Z \\
\end{tabular}
\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}

How to rotate table-headline in Latex table

is there a way to rotate the "Demo 1", "Demo2" and "Demo 3" headlines 90° in the following LaText table?
\documentclass[a4paper,twoside,10pt]{report}
\begin{document}
\begin{tabular}{|l|l|l|l|}
\hline
& Demo1 & Demo2 & Demo3 \\
\hline
Person 1 & x & & \\
\hline
Person 2 & x & & x \\
\hline
Person 3 & x & x & \\
\hline
Person 4 & & x & x \\
\hline
\end{tabular}
\end{document}
Thanks
Yes. As Dr. Andrew J. Page wrote on his blog,
Put this at the top of your code:
\usepackage{rotating}
Simply to create a table with rotated column text use this code:
\begin{tabular}{|r|r|}\hline
\begin{sideways}Paper\end{sideways} &\begin{sideways}Static\end{sideways} \\
\hline
HAR1994j & Journal \\
SWRT1996c & Conference \\
\hline
\end{tabular}

Resources