Draw a table in vertical display instead of horizontal display - latex

Can Someone tell me by which command I can draw a table in vertical display in LaTex.
Thanks..

I think you want the lscape package, can be usefully used for this purpose as follows:
\begin{landscape}
\begin{table}
\centering
\begin{tabular}{....}
.......
\end{tabular}
\end{table}
\end{landscape}
EDIT 2nd solution:
Another possibility is to use the sideways environment from the rotating package:
\begin{sideways}
\begin{tabular}
...
\end{tabular}
\end{sideways}
And for floating tables sidewaystable.

The following code works for me to display the table at the center of vertical position.
\begin{landscape}
\begin{table}
\begin{center}
\caption{Table name}
\begin{tabular}{lll}
A & B & C \\
20 &23 &56 \\
25 &25 &65 \\
\end{tabular}
\end{center}
\end{table}
\end{landscape}

Related

An alternative to write multirow in latex's tabular?

In latex, I know we can use the multirow command like the following,
\begin{table}[!h]
\centering
\begin{tabular}{|c|l|}
\hline
\multirow{2}{*}{A}
& I want to place this sentence in multiple lines, \\
& but don't want to control the linebreak myself \\
\hline
\end{tabular}
\end{table}
I think it is so stupid to control the linebreak myself.
Any other alternative that fits the text width to line width?
\documentclass{article}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabularx}{\linewidth}{|c|X|}
\hline
A
& I want to place this sentence in multiple lines, but don't want to control the linebreak myself \\
\hline
\end{tabularx}
\end{table}
\end{document}

How to center my text vertically in a table environment?

I have a table with 3 columns where the first 2 columns are pictures and the 3rd is my comment on those pictures, but the comment "drowns", it is down at the bottom of the cell.
I have tried with m{2cm} instead of c:
\begin{tabularx}{\textwidth}{c c m{2cm}}
but no change.
\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
\begin{tabularx}{\textwidth}{c c c}
\textbf{O-Na} & \textbf{Na-Y} & \textbf{Comments} \\
\includegraphics[width=0.3\linewidth]{pic1.png} &
\includegraphics[width=0.3\linewidth]{pic2.png} &
My comments. \\
\end{tabularx}
\end{table}
My text is at the bottom of the cell.
The graphbox provides the handy align=c option to vertically centre images:
\documentclass{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage{graphicx}
\usepackage{graphbox}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\begin{document}
\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
\begin{tabularx}{\textwidth}{XXX}
\thead{O-Na} & \thead{Na-Y} & \thead{Comments} \\
\includegraphics[width=\linewidth,align=c]{example-image-duck} &
\includegraphics[width=\linewidth,align=c]{example-image-duck} &
My comments. \\
\end{tabularx}
\end{table}
\end{document}

centre a table in latex with headings above cells

I have a table I wish to fit in the margins. I also wish to add both EPS and PPS above the middle of the cells with these two in. I am not sure why adding a caption is not working either. Here is the code:
\begin{tabular}{ |p{3cm}||p{3cm}|p{3cm}|p{3cm}|p{3cm}| }
\multicolumn{5}{c}{} \\
\hline
&EPS:Pre &EPS:Post &PPS:Pre & PPS:Post \\
\hline
Species tested:&13 &15& 43& 43\\
Compounds tested:& 745 & 745& 310& 361 \\
Unique tests:& 193& 193& 406& 407\\
Total experiments:&17,811 &17,929& 107,470& 130,926\\
\hline
\end{tabular}
\label{tab}
Thank you.
There where several problems.
Your table was too large, with the margins and intercolumn spacing. I made a macro to fine adjust column width.
To redefine a column (for instance to center a header), you can use `\multicolumn{1}{c}{header}
\label assigns a number that is used in a numbered environment. It is associated with the table environmenent, not with tabular. The label appears within a caption. Also, the table is centered within the table environment.
\documentclass{article}
\begin{document}
\newcommand{\colwidth}{0.17\textwidth}
\newcommand{\centercolumn}[1]{\multicolumn{1}{c|}{#1}}
\begin{table}
\centering
\begin{tabular}{ |p{3cm}||p{\colwidth}|p{\colwidth}|p{\colwidth}|p{\colwidth}| }
% \multicolumn{5}{c}{} \\ useless, I think
\hline
&\centercolumn{EPS:Pre} &\centercolumn{EPS:Post} &\centercolumn{PPS:Pre} & \centercolumn{PPS:Post} \\
\hline
Species tested:&13 &15& 43& 43\\
Compounds tested:& 745 & 745& 310& 361 \\
Unique tests:& 193& 193& 406& 407\\
Total experiments:&17,811 &17,929& 107,470& 130,926\\
\hline
\end{tabular}
\caption{My table}
\label{tab:1}
\end{table}
\end{document}

rowcolors fill whole row and not just the table row

Ok so i wrote this simple code (shown below) to create an alternate colour table using \rowcolors, yet instead of just colouring the rows of the table it colours the whole row (even more than textwidth). Any help how to fix this?
begin{table}[ht]
\scriptsize
\begin{center}
\rowcolors{1}{lightgray}{white}
\caption{...}
\begin{tabular}{p{0.45\textwidth} | p{0.55\textwidth}}
Filename & Contents \\
\hline
\hline
A & B \\
C & F \\
\end{tabular}
\end{center}
\end{table}
While 0.45\textwidth + 0.55\textwidth would seem to fit within \textwidth, each of your p-columns have an extra column separation... on both sides. To that end, you should remove them in order to make it fit within the text block boundary:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{lipsum}
\begin{document}
\begin{table}[ht]
\scriptsize\centering
\rowcolors{1}{lightgray}{white}
\caption{This is a table.}
\begin{tabular}{
p{\dimexpr0.45\textwidth-2\tabcolsep} |
p{\dimexpr0.55\textwidth-2\tabcolsep}}
Filename & Contents \\
\hline
\hline
A & B \\
C & F
\end{tabular}
\end{table}
\lipsum[1]
\end{document}
Also, don't use the center environment; use \centering instead.

How to create a new line in the table cell

I am new to latex, and I am trying to create a table, but the content in the table cell is quite long, so I decided to create a new line for the cells.
But I am not sure how to do that, could someone help me on that? Here is my code:
\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
Observation(Species name) & Likelihood (Limnodynastes peronii Distribution Model) &Likelihood (Rhinella marina Distribution Model)\\
\hline
Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
\hline
Observation 2 (Rhinella marina) &0.30 &0.013 \\
\hline
\end{tabular}
\end{center}
\end{table}
Here is a fix I made up. The command wraps information in a parbox with a little extra spacing above and below the text to make it look nice. This allows you to limit the width of a cell as well as enter manual line breaks.
\begin{table}[h!]
\caption{Multirow table}
\newcommand{\wrap}[1]{\parbox{.33\linewidth}{\vspace{1.5mm}#1\vspace{1mm}}}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
\wrap{Observation\\ (Species name)} &\wrap{Likelihood\\ (Limnodynastes peronii Distribution Model)} &\wrap{Likelihood\\ (Rhinella marina\\ Distribution Model)}\\
\hline
\wrap{Observation 1\\ (Limnodynastes peronii)} &0.0712 &0.2699\\
\hline
\wrap{Observation 2\\ (Rhinella marina)}&0.30 &0.013 \\
\hline
\end{tabular}
\end{center}
\end{table}
Hope this helps- this is my first answer on stackoverflow!

Resources