How to merge cells with multirow in LaTeX? - latex

I have the following code:
\begin{table}[ht]
\begin{center}
\begin{tabular}{ | l | l | l | l | l | l | l | }
\hline
\multirow{2}{*}{Oprava} & \multirow{2}{*}{zkratka} & \multirow{2}{*}{alg.} & chybovost \% & & & \\ \hline
& & & MAE & RSE & RMSE & RRSE \\ \hline
velikosti & vel. & NBM & & & & \\ \hline
& & c4.5 & & & & \\ \hline
& & kNN & & & & \\ \hline
& & SMO & & & & \\ \hline
bilateralne & bilat. & NBM & & & & \\ \hline
& & c4.5 & & & & \\ \hline
& & kNN & & & & \\ \hline
& & SMO & & & & \\ \hline
oprava & zkratka & NBM & & & & \\ \hline
& & c4.5 & & & & \\ \hline
& & kNN & & & & \\ \hline
& & SMO & & & & \\ \hline
oprava & zkratka & NBM & & & & \\ \hline
& & c4.5 & & & & \\ \hline
& & kNN & & & & \\ \hline
& & SMO & & & & \\ \hline
\end{tabular}
\end{center}
\caption{Multi-row table}
\label{tab:multicol}
\end{table}
And what I get is this:
I need to merge the cells, so that the text is not crossed out. The same for the rows with the repeated algorithms names - NBM, kNN etc ..... they should me merged and centered. Pls help.
Thanks

The solution to your problem is very simple. You should use \cline{4-7} instead of \hline. Namely \hline makes a horizontal line over the complete width of the table, while \cline{4-7} will only make a horizontal line from column 4 until 7, and thus not crossing the first ones.
To get the text in front of the repeated words centered and merged, you can use multirow{}{}, again in combination with \cline{}. More info about these commands at this link.
An example of the code is given below:
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
\multirow{2}{*}{Oprave} & \multirow{2}{*}{Zkratka} & \multirow{2}{*}{Alg.} & \multicolumn{4}{l|}{Chybovost \%} \\ \cline{4-7}
& & & MAE & RSE & RMSE & RRSE \\ \hline
\multirow{4}{*}{velikosti} & \multirow{4}{*}{vel.} & NBM & & & & \\ \cline{3-7}
& & c4.5 & & & & \\ \cline{3-7}
& & kNN & & & & \\ \cline{3-7}
& & SMO & & & & \\ \hline
\multirow{4}{*}{bilateralne} & \multirow{4}{*}{bilat.} & NBM & & & & \\ \cline{3-7}
& & c4.5 & & & & \\ \cline{3-7}
& & kNN & & & & \\ \cline{3-7}
& & SMO & & & & \\ \hline
\multirow{4}{*}{oprava} & \multirow{4}{*}{zkratka} & NBM & & & & \\ \cline{3-7}
& & c4.5 & & & & \\ \cline{3-7}
& & kNN & & & & \\ \cline{3-7}
& & SMO & & & & \\ \hline
\multirow{4}{*}{oprava} & \multirow{4}{*}{zkratka} & NBM & & & & \\ \cline{3-7}
& & c4.5 & & & & \\ \cline{3-7}
& & kNN & & & & \\ \cline{3-7}
& & SMO & & & & \\ \hline
\end{tabular}
\end{table}
Resulting into:
Note: if you have struggles with table generation, or you want a more quick way to easily make tables as you would do in Excel, you can use an online table generator for Latex.
I often use http://www.tablesgenerator.com/

Related

Table with box inside

How to code this kind of table? The code for the table is easy for me but I don't know how to put a box in the upper right in every column. Thank you.
I found a way to add a box in the upper right corner, by adding additional columns (one left and one right for symmetry reasons) and rows to the table.
This is my solution, though they are propably more elegant ways to achive this:
\documentclass{article}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|c P{15mm} c|c P{15mm}c|cP{15mm}c|cP{15mm}c|c P{15mm}c|}
\hline
& & & & & & & & & & & & & & \\
& & & & A & & & B & & & C & & & Capacity & \\
& & & & & & & & & &
& & & & \\
\hline
& & & & & \multicolumn{1}{|c|}{5} & & & \multicolumn{1}{|c|}{4} & & & \multicolumn{1}{|c|}{3} & & & \\ \cline{6-6} \cline{9-9} \cline{12-12}
& D & & & & & & & & & & & & 100 & \\
& & & & & & & & & & & & & & \\
\hline
& & & & & \multicolumn{1}{|c|}{8} & & & \multicolumn{1}{|c|}{4} & & & \multicolumn{1}{|c|}{3} & & & \\ \cline{6-6} \cline{9-9} \cline{12-12}
& E & & & & & & & & & & & & 300 & \\
& & & & & & & & & & & & & & \\
\hline
& & & & & \multicolumn{1}{|c|}{9} & & & \multicolumn{1}{|c|}{7} & & & \multicolumn{1}{|c|}{5} & & & \\ \cline{6-6} \cline{9-9} \cline{12-12}
& F & & & & & & & & & & & & 300 & \\
& & & & & & & & & & & & & & \\
\hline
\end{tabular}
\end{table}
\end{document}
This is the output:

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}

How can I make the verticle line in the table without any gaps?

The verticle line in the third column has 2 gaps. How do I do I make it look full?
Here's the code:
\begin{table}[H]
\centering
\caption{Enzymatic cocktails and the respective tested concentrations in \%(v/v) used in Combined Hydrolysis}
\label{enzymatic cocktails}
\begin{tabular}{#{}ccc#{}}
\toprule
\textbf{Cocktail} & \textbf{Enzymes} & \textbf{Concentration \%(v/v)} \\ \midrule
\multirow{2}{*}{A} & \multicolumn{1}{c|}{Cellulase} & \multirow{8}{*}{\begin{tabular}[c]{#{}c#{}}0.25\\ 0.50\\ 1.00\end{tabular}} \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucosidase} & \\ \cmidrule(r){1-2}
\multirow{3}{*}{B} & \multicolumn{1}{c|}{Cellulase} & \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucosidase} & \\
& \multicolumn{1}{c|}{xylanase} & \\ \cmidrule(r){1-2}
\multirow{3}{*}{C} & \multicolumn{1}{c|}{Cellulase} & \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucosidase} & \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucanase and xylanase} & \\ \bottomrule
\end{tabular}
\end{table}
Vertical lines like in c| and horizontal lines such as toprule, bottomrule, midrule, cmidrule from the package booktabs do not match.
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}%[H]
\centering
\caption{Enzymatic cocktails and the respective tested concentrations in \%(v/v) used in Combined Hydrolysis}
\label{enzymatic_cocktails}
\begin{tabular}{#{}ccc#{}}
\hline
\textbf{Cocktail} & \textbf{Enzymes} & \textbf{Concentration \%(v/v)}\\
\hline
\multirow{2}{*}{A} & \multicolumn{1}{c|}{Cellulase} & %
\multirow{8}{*}{\begin{tabular}[c]{#{}c#{}}0.25\\ 0.50\\ 1.00\end{tabular}}\\
& \multicolumn{1}{c|}{$\mathbb{\beta}$-glucosidase} & \\
\cline{1-2}
\multirow{3}{*}{B} & \multicolumn{1}{c|}{Cellulase} & \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucosidase} & \\
& \multicolumn{1}{c|}{xylanase} & \\
\cline{1-2}
\multirow{3}{*}{C} & \multicolumn{1}{c|}{Cellulase} & \\
& \multicolumn{1}{c|}{$\mathbb{\beta}$-glucosidase} & \\
& \multicolumn{1}{c|}{$\mathbb{\beta}$-glucanase and xylanase} & \\
\hline
\end{tabular}
\end{table}
\end{document}
So I went back to hlines in my code. Better would be to use the above mentioned package booktabs and avoid vertical lines instead.

LaTeX orders table before text even if in the code the table is after text. Why?

This code:
\subsection*{4.1 1NF}
No, this table is not in 1NF as column Info can and on multiple rows hold multiple values. 1NF Variation would be:
\par
\begin{table}[]
\begin{tabular}{|l|l|l|l|l|l|}
\hline
{\ul \textbf{Student\_ID}} & \textbf{First Name} & \textbf{Last Name} & \textbf{Course} & \textbf{Credits} & \textbf{Grade} \\ \hline
1 & Adam & Brown & Databases & 5 & 8 \\ \hline
1 & Adam & Brown & Algebra & 3 & 7 \\ \hline
1 & Adam & Brown & Algorithms & 5 & 9 \\ \hline
2 & Felicia & Green & Algebra & 3 & 10 \\ \hline
2 & Felicia & Green & Programming & 5 & 6 \\ \hline
3 & Mary & Grey & Databases & 5 & 9 \\ \hline
3 & Mary & Grey & Algorithms & 5 & 7 \\ \hline
3 & Mary & Grey & Web & 3 & 10 \\ \hline
1 & Adam & Brown & Physics & 3 & 10 \\ \hline
\end{tabular}
\end{table}
Produces this result:
Rednder of the LaTeX code above
But I need the table to be after the text.
Can someone tell me what am I doing wrong?
You're missing a floating specifier, e.g. to allow the table [h]ere, at the [t]op, at the [b]ottom or on a separate [p]age:
\begin{table}[htbp]

How do you add vertical lines to a table?

I am making a table and I am not able to make vertical lines to appear. I followed a few examples and they are still not appearing.
\begin{table}[h!]
\centering
\begin{tabular}{||c c c c||}
\hline
\multicolumn{4}{|c|}{Telescope Data} \\
\hline
Channels & \makecell{Beam Size\\ (arcsec)} & \makecell{Noise \\ (mJy/beam)} & Position of Peak Flux \\ [0.5ex]
\hline
1-10 & \makecell{\textbf{min:} 1.42 \\ \textbf{max:} 1.95} & 4.9928 & \makecell{\textbf{peak(x):} 15 \\ \textbf{peak(y):} -13.5 \\ \textbf{peak(flux, max):} 0.002846} \\ [3ex]
\hline
52-61 & \makecell{\textbf{min:} 1.423 \\ \textbf{max:} 1.95} & 0.0018912 & \makecell{\textbf{peak(x):} -0.25 \\ \textbf{peak(y):} 0 \\ \textbf{peak(flux, max):} 0.029341} \\ [3ex]
\hline
103-112 & \makecell{\textbf{min:} 1.427 \\ \textbf{max:} 1.956} & 0.000802855 & \makecell{\textbf{peak(x):} -16 \\ \textbf{peak(y):} 0 \\ \textbf{peak(flux, max):} 0.00241892} \\ [3ex]
\hline
\end{tabular}
\end{table}

Resources