Given the following LaTeX table, how can I make all cells have a bold style?
MWE:
\documentclass{article}
\begin{document}
\begin{table}[ht]%
\centering
\caption[Data description]{Dataset description}
\begin{tabular}{|l|l|c|c|c|c|}
\hline
&Dataset &Samples&Numerical&Categorical&Class\\ \hline
1&Horse & 300 & 7 & 16 & 2 \\ \hline
2&Ionosphere & 351 & 32 & 1 & 2 \\ \hline
3&Band & 540 & 13 & 6 & 2 \\ \hline
4&Australian+MV& 621 & 3 & 11 & 2 \\ \hline
5&Hepatitis & 155 & 2 & 17 & 2 \\ \hline
6&Credit & 690 & 3 & 12 & 2 \\ \hline
\end{tabular}
\label{tab:data}
\end{table}
\end{document}
You can set the formatting of each column in the tabular argument with >{...}, see Tabular, make a column or a row emphasized:
\begin{tabular}{|>{\bfseries}l|>{\bfseries}l|>{\bfseries}c|>{\bfseries}c|>{\bfseries}c|>{\bfseries}c|}
Use the *{num}{str} syntax to make it shorter and more readable:
\begin{tabular}{*{2}{|>{\bfseries}l} *{4}{|>{\bfseries}c} |}\hline
I.e. 'two times flush left and bold', then 'four times centred and bold'. (Note that \bf is deprecated.)
Your MWE:
\documentclass{article}
\usepackage{array} % otherwise you get "Error: Illegal character in array arg."
\begin{document}
\begin{table}[ht]%
\centering
\caption[Data description]{Dataset description}
\begin{tabular}{*{2}{|>{\bfseries}l} *{4}{|>{\bfseries}c} |}\hline
&Dataset &Samples&Numerical&Categorical&Class\\ \hline
1&Horse & 300 & 7 & 16 & 2 \\ \hline
2&Ionosphere & 351 & 32 & 1 & 2 \\ \hline
3&Band & 540 & 13 & 6 & 2 \\ \hline
4&Australian+MV& 621 & 3 & 11 & 2 \\ \hline
5&Hepatitis & 155 & 2 & 17 & 2 \\ \hline
6&Credit & 690 & 3 & 12 & 2 \\ \hline
\end{tabular}
\label{tab:data}
\end{table}
\end{document}
You can also set the formatting of a whole row (less interesting in this case) - see for instance How to change a whole row of a table.
Note: you can make a single cell normal again by using \normalfont{}.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{table}[ht]%
% If you want all in bold face then enclose it between {\ bf }
\centering {\bf
\caption[Data description]{Dataset description}
\begin{tabular}{|l|l|c|c|c|c|}\hline
& Dataset & Samples & Numerical & Categorical & Class\\\hline
1 & Horse & 300 & 7 & 16 & 2 \\\hline
2 & Ionosphere & 351 & 32 & 1 & 2 \\\hline
3 & Band & 540 & 13 & 6 & 2 \\\hline
4 & Australian+MV& 621 & 3 & 11 & 2 \\\hline
5 & Hepatitis & 155 & 2 & 17 & 2 \\\hline
6 & Credit & 690 & 3 & 12 & 2 \\\hline
\end{tabular}
\label{tab:data}
Related
I am trying to make a table where the first column is multiple columns (2 columns) and also multiple rows (2 rows). The error is on the first column (Aspects). How to make it work?
\begin{table}[htb]
\centering
\begin{tabular}{l|c|c|c|c|c}
\hline
\multirow{2}{c}{}\multicolumn{2}{c|}{Aspects} & \multicolumn{4}{c}{Methods} \\
\cline{3-6}
& & Binomial Test & Tangram & Stereoscope & BayesPrism\\
\hline
\multirow{10}{*}{\begin{turn}{270}Total Number\end{turn}} & Cell Type 0 & 3381 & 25 & 1200 & 331 \\
& Cell Type 1 & 1903 & 40 & 3360 & 3468 \\
& Cell Type 2 & 3466 & 0 & 1357 & 2729 \\
& Cell Type 3 & 3468 & 40 & 1711 & 412 \\
& Cell Type 4 & 3406 & 64 & 1996 & 3458 \\
& Cell Type 5 & 2934 & 31 & 1512 & 1772 \\
& Cell Type 6 & 494 & 55 & 3463 & 3468 \\
& Cell Type 7 & 3159 & 30 & 2367 & 3467 \\
& Cell Type 8 & 3454 & 53 & 3275 & 3456 \\
& Cell Type 9 & 3281 & 18 & 1320 & 1451 \\
\hline
\multicolumn{2}{c|}{Total Variables} & 28,946 & 356 & 21,443 & 23,962\\
\multicolumn{2}{c|}{Residual Error Mean} & 3.04 & 3.50 & 2.92 & 2.93 \\
\hline
\end{tabular}
\caption{Total Number of Each Cell Types for The Model \ref{regression}}
\label{total_cell}
\end{table}
This line is completely messed up:
\multirow{2}{c}{}\multicolumn{2}{c|}{Aspects}
The \multirow has the wrong syntax, and moreover, \multirow must be inside \multicolumn if you want to combine them (see the multirow manual).
Also I added a \multicolumn{1}{l}{} to get rid of the vertical bar in the 2x2 cell.
\documentclass{article}
\usepackage{multirow}
\usepackage{rotating}
\begin{document}
\begin{table}[htb]
\centering
\begin{tabular}{l|c|c|c|c|c}
\hline
\multicolumn{2}{c|}{\multirow{2}{*}{Aspects}} & \multicolumn{4}{c}{Methods} \\
\cline{3-6}
\multicolumn{1}{l}{} & & Binomial Test & Tangram & Stereoscope & BayesPrism\\
\hline
\multirow{10}{*}{\begin{turn}{270}Total Number\end{turn}} & Cell Type 0 & 3381 & 25 & 1200 & 331 \\
& Cell Type 1 & 1903 & 40 & 3360 & 3468 \\
& Cell Type 2 & 3466 & 0 & 1357 & 2729 \\
& Cell Type 3 & 3468 & 40 & 1711 & 412 \\
& Cell Type 4 & 3406 & 64 & 1996 & 3458 \\
& Cell Type 5 & 2934 & 31 & 1512 & 1772 \\
& Cell Type 6 & 494 & 55 & 3463 & 3468 \\
& Cell Type 7 & 3159 & 30 & 2367 & 3467 \\
& Cell Type 8 & 3454 & 53 & 3275 & 3456 \\
& Cell Type 9 & 3281 & 18 & 1320 & 1451 \\
\hline
\multicolumn{2}{c|}{Total Variables} & 28,946 & 356 & 21,443 & 23,962\\
\multicolumn{2}{c|}{Residual Error Mean} & 3.04 & 3.50 & 2.92 & 2.93 \\
\hline
\end{tabular}
\caption{Total Number of Each Cell Types for The Model \ref{regression}}
\label{total_cell}
\end{table}
\end{document}
I need to add some left spacing in a table's cell. Can anyone help me?
It follows a code sample; I need to add left spacing in the cells of the first colum where the label is not bold.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{graphics}
\begin{document}
{
\begin{table}[ht]
\centering
\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering\arraybackslash}p{0.15\textwidth}|}
\hline
& \textbf{VRE} & \textbf{FPE} & \textbf{MPE} & \multicolumn{2}{c|}{\textbf{Full sample}} \\
& \textit{n} & \textit{n} & \textit{n} & \textit{n} & \textit{\%} \\
\hline
\textbf{Gender} &&&&& \\
Female & 12 & 10 & 18 & 40 & 52.6 \\
Male & 10 & 13 & 13 & 36 & 47.4 \\
\hline
\textbf{Educational level} &&&&& \\
High School & 8 & 5 & 6 & 19 & 25.0 \\
Bachelor's Degree & 13 & 9 & 19 & 41 & 53.9 \\
Master's Degree & 1 & 8 & 6 & 15 & 19.7 \\
PhD & 0 & 1 & 0 & 1 & 1.3 \\
\hline \hline
\textbf{Age} &&&&& \\
Mean & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
Median & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
\hline
\end{tabular}
\caption{Participants demographic information}
\label{tab:demographic}
\end{table}
}
Thanks in advance.
One possibility: you can place \quad (or similar spacing macros) at the start of these cells:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{graphics}
\begin{document}
{
\begin{table}[ht]
\centering
\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|p{0.26\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering\arraybackslash}p{0.15\textwidth}|}
\hline
& \textbf{VRE} & \textbf{FPE} & \textbf{MPE} & \multicolumn{2}{c|}{\textbf{Full sample}} \\
& \textit{n} & \textit{n} & \textit{n} & \textit{n} & \textit{\%} \\
\hline
\textbf{Gender} &&&&& \\
\quad Female & 12 & 10 & 18 & 40 & 52.6 \\
\quad Male & 10 & 13 & 13 & 36 & 47.4 \\
\hline
\textbf{Educational level} &&&&& \\
\quad High School & 8 & 5 & 6 & 19 & 25.0 \\
\quad Bachelor's Degree & 13 & 9 & 19 & 41 & 53.9 \\
\quad Master's Degree & 1 & 8 & 6 & 15 & 19.7 \\
\quad PhD & 0 & 1 & 0 & 1 & 1.3 \\
\hline \hline
\textbf{Age} &&&&& \\
\quad Mean & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
\quad Median & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
\hline
\end{tabular}
\caption{Participants demographic information}
\label{tab:demographic}
\end{table}
}
\end{document}
Unrelated to the problem, but your fixed width columns "waste" a lot of space. I would instead use a tabularx like this:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{graphics}
\begin{document}
{
\begin{table}[ht]
\centering
\setlength{\tabcolsep}{10pt}
\renewcommand{\arraystretch}{1.5}
\begin{tabularx}{\textwidth}{ | X ccccc | }
\hline
& \textbf{VRE} & \textbf{FPE} & \textbf{MPE} & \multicolumn{2}{c|}{\textbf{Full sample}} \\
& \textit{n} & \textit{n} & \textit{n} & \textit{n} & \textit{\%} \\
\hline
\textbf{Gender} &&&&& \\
\quad Female & 12 & 10 & 18 & 40 & 52.6 \\
\quad Male & 10 & 13 & 13 & 36 & 47.4 \\
\hline
\textbf{Educational level} &&&&& \\
\quad High School & 8 & 5 & 6 & 19 & 25.0 \\
\quad Bachelor's Degree & 13 & 9 & 19 & 41 & 53.9 \\
\quad Master's Degree & 1 & 8 & 6 & 15 & 19.7 \\
\quad PhD & 0 & 1 & 0 & 1 & 1.3 \\
\hline \hline
\textbf{Age} &&&&& \\
\quad Mean & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
\quad Median & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
\hline
\end{tabularx}
\caption{Participants demographic information}
\label{tab:demographic}
\end{table}
}
\end{document}
Taking this to tex.stackexhange.
The problem
Let's say I want to have more than rules in two different colors in the same row ... how can I make it work?
Here is a minimal example:
\documentclass{article}
\usepackage{colortbl}
\usepackage{booktabs}
\begin{document}
\begin{table}[ht]
\begin{tabular}{llll}
\toprule
A & B & alpha & beta\\
\arrayrulecolor{black} \cmidrule[1pt](l){1-1} \arrayrulecolor{red} \cmidrule[1pt](r){2-2} \arrayrulecolor{black} \cmidrule[1pt](l){3-3} \arrayrulecolor{black} \cmidrule[1pt](r){4-4}
1 & 5 & 10 & 100\\
2 & 6 & 11 & 101\\
2 & 7 & 12 & 102\\
3 & 8 & 13 & 103\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
What happens is that with each call of \arrayrulecolor{}, the corresponding cmidrule is moved down. Is there a solution to this?
The problem with the earlier solution
The solution mentioned in the comments has some trouble when you have different widths in one row. Consider this example:
\documentclass{article}
\usepackage{colortbl}
\usepackage{booktabs}
\newcommand{\corcmidrule}[1][2pt]{% \corcmidrule[<len>]
\\[\dimexpr-\normalbaselineskip-\belowrulesep-\aboverulesep-#1\relax]%
}
\begin{document}
\begin{table}[ht]
\begin{tabular}{llll}
\toprule
A & B & alpha & beta\\
\arrayrulecolor{black}\cmidrule[1pt](l){1-1}
\corcmidrule[2pt]\arrayrulecolor{black}\cmidrule[2pt](r){2-2}
\corcmidrule[5pt]\arrayrulecolor{black}\cmidrule[5pt](l){3-3}
\corcmidrule[1pt]\arrayrulecolor{black}\cmidrule[1pt](r){4-4}
1 & 5 & 10 & 100\\
2 & 6 & 11 & 101\\
2 & 7 & 12 & 102\\
3 & 8 & 13 & 103\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
What's wrong with this?
Consider what it looks like without the macro:
\documentclass{article}
\usepackage{colortbl}
\usepackage{booktabs}
\newcommand{\corcmidrule}[1][2pt]{% \corcmidrule[<len>]
\\[\dimexpr-\normalbaselineskip-\belowrulesep-\aboverulesep-#1\relax]%
}
\begin{document}
\begin{table}[ht]
\begin{tabular}{llll}
\toprule
A & B & alpha & beta\\
\arrayrulecolor{black}\cmidrule[1pt](l){1-1}
\cmidrule[2pt](r){2-2}
\cmidrule[5pt](l){3-3}
\cmidrule[1pt](r){4-4}
1 & 5 & 10 & 100\\
2 & 6 & 11 & 101\\
2 & 7 & 12 & 102\\
3 & 8 & 13 & 103\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
The macro might need a modification.
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]
I a trying to put a table in my report. I want to place it in the middle of the page.
but it is shifted to the right side. How can I fix it? (I am using overleaf)
I really appreciate it if anyone could help me to fix the problem.
This is the code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{floatrow}
\floatsetup[table]{capposition=top}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{tabularx}
\usepackage{caption}
\begin{table}[p]
\centering
\small
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
\hline
\textbf{Sub fault} & \textbf{Lat} & \textbf{Lon} & \textbf{\begin{tabular}[c]{#{}c#{}}Depth\\ (Km)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Strike\\ (Deg.)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Dip \\ (Deg.)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Length\\ (Km)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Width\\ (Km)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Rake \\ (Deg.)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Slip (m)\\ Mw=9.0\end{tabular}} \\ \hline
\textbf{1} & 18.9848 & -65.6921 & 22.1 & 89.59 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{2} & 19.4069 & -65.6953 & 5 & 89.59 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{3} & 18.9484 & -66.5742 & 22.1 & 84.98 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{4} & 19.3688 & -66.6133 & 5 & 84.98 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{5} & 18.8738 & -67.5412 & 22.1 & 85.87 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{6} & 19.2948 & -67.5734 & 5 & 85.87 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{7} & 18.7853 & -68.4547 & 22.1 & 83.64 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{8} & 19.2048 & -68.5042 & 5 & 83.64 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{9} & 18.8870 & -63.8800 & 22.1 & 95.37 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{10} & 19.3072 & -63.8382 & 5 & 95.37 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{11} & 18.9650 & -64.8153 & 22.1 & 94.34 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{12} & 19.3859 & -64.7814 & 5 & 94.34 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{13} & 18.0566 & -61.5491 & 17.94 & 112.84 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{14} & 18.4564 & -61.3716 & 5 & 112.34 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{15} & 18.4149 & -62.4217 & 17.94 & 117.86 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{16} & 18.7985 & -62.2075 & 5 & 117.86 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{17} & 18.7844 & -63.1649 & 17.94 & 110.46 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{18} & 19.1798 & -63.0087 & 5 & 110.46 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{19} & 16.4535 & -59.9029 & 17.94 & 136.99 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{20} & 16.7494 & -59.5716 & 5 & 136.99 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{21} & 17.0903 & -60.5996 & 17.94 & 138.71 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{22} & 17.3766 & -60.2580 & 5 & 138.71 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{23} & 17.8560 & -61.1559 & 17.94 & 141.07 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{24} & 18.1286 & -60.8008 & 5 & 141.07 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\end{tabular}
\captionsetup{justification=centering}
\caption{\label{tab:table-name}source parameters for a Mw 9.0 PRT co-seismic source based on 24 sub-faults (Gica eal,2008). Corresponding surface elevation computed with Okadas (1985) method is shown in fig 3}
\end{table}
\clearpage
Your issue here is that the table is too wide to fit within the text block. As such, LaTeX pushes is against the left margin and let it overflow into the right margin. If you don't want to change anything and just centre it, you can wrap the entire tabular inside a \makebox[\linewidth]:
\begin{table}
\centering
\small
\makebox[\linewidth]{%
\begin{tabular}{| *{10}{c|} }
<your table here>
\end{tabular}%
}
\caption{<caption>}
\end{table}
For more details and options, see My table doesn't fit; what are my options?
You can try the following:
\begin{center}
\begin{tabular}{ | c | c | c | }
\hline
symbol & value & unit \\ \hline
$z Na$ & 11 & - \\ \hline
$z F$ & 9 & - \\ \hline
$Emax Na$ & 0.545 & $[MeV]$ \\ \hline
\end{tabular}
\end{center}
Refer: How to center table in latex