I am very new to Latex and am trying to create a table with cells that span multiple rows.
The issue I am trying to solve is removing the horizontal lines that are placed over the multirow cells. A picture of what I have so far is linked here
Latex_table_screenshot
and my code is below.
In the picture are boxed areas indicating the multirow cells that have lines going over them.
I have tried using the cline{} command to remove the horizontal lines, but it ends up removing either more than one line or none at all. I do not think I understand how to use that command completely.
I commented out the two cline commands that show what I am talking about when not commented.
\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage[margin=1in]{geometry}
\begin{document}
\renewcommand{\arraystretch}{1.5}
\centering
\begin{tabular}{c|c|c|c{3.5cm}}
\hline
\textbf{ Classification} & \textbf{Total Impulse} & \textbf{Total Impulse} & \textbf{Type/}\\
& (Newton-Seconds) & (Pounds-Seconds) & \textbf{US Requirements}\\
\hline
%___________Micro____________
1/8 A & 0—0.3125 \textbf{N·s} & 0 – 0.07 lbf·s & \multirow{1}{*}\textbf{Micro} \\%[.3cm]
%\cline{3-4}
%\cline{4-5}
\hline
%_________Low Power_________
1/4 A & 0.3126 – 0.625 N·s & 0.071 – 0.14 lbf·s & \multirow{6}{*}{Low Power}\\
\hline
1/2 A & 0.626 – 1.25 N·s & 0.141 – 0.28 lbf·s & \\
\hline
A & 0.626 – 1.25 N·s & 0.141 – 0.28 lbf·s & \\
\hline
B & 2.51 – 5.00 N·s & 0.561 – 1.12 lbf·s & \\
\hline
C & 5.01 – 10.0 N·s & 1.121 – 2.25 lbf·s & \\
\hline
D & 10.01 – 20.0 N·s & 2.251 – 4.5 lbf·s & \\
\hline
%_______Mid Power__________
E & 20.01 – 40.0 N·s & 4.51 – 8.99 lbf·s & \multirow{3}{*}{Mid Power}\\
\hline
F & 40.01 – 80.0 N·s & 8.991 – 18.0 lbf·s & \\
\hline
G & 80.01 – 160 N·s & 18.01 – 36.0 lbf·s & \\
\hline
%_____High Power | Level 1_________
H & 160.01 – 320 N·s & 36.01 – 71.9 lbf·s & \multirow{2}{150}{\textbf{ High Power | Level 1} \newline
Level 1 Certification required for purchase. Certification available through Tripoli or NAR.
Under 125g propellant is Federal Aviation Administration exempt.}\\
\hline
I & 320.01 – 640 N·s & 71.9 – 144 lbf·s & \\[2cm]
\hline
%____High Power | Level 2 _____
J & 640.01 – 1,280 N·s & 144.01–288 lbf·s & \multirow{3}{150}{\textbf{ High Power | Level 2} \newline
Level 2 Certification required for purchase. Certification available through Tripoli or NAR.}\\
\hline
K & 1,280.01 – 2,560 N·s & 288.01–576 lbf·s & \\
\hline
L & 2,560.01 – 5,120 N·s & 576.01–1,151 lbf·s & \\[.2cm]
\hline
%_______High Power | Level 3________
M & 5,120.01 – 10,240 N·s & 1,151.01–2,302 lbf·s & \multirow{3}{150}{\textbf{ High Power | Level 3}
\newline
Level 3 Certification required for purchase. Certification available through Tripoli or NAR.}\\
\hline
N & 10,240.01 – 20,480 N·s & 2,302.01–4,604 lbf·s & \\
\hline
O & 20,480.01 – 40,960 N·s & 4,604.01–9,208 lbf·s & \\[.2cm]
\hline
\end {tabular}
\end{document}
Have a look at the new tabularray package. This will give you much better results, distribute the rows neatly and will automatically deal with the horizontal lines:
\documentclass[12pt,a4paper]{article}
\usepackage[margin=1in]{geometry}
\usepackage{tabularray}
\begin{document}
\noindent
\begin{tblr}{
colspec={ c c c X},
vlines,
hlines,
vspan=even
}
H & 160.01 – 320 N·s & 36.01 – 71.9 lbf·s & \SetCell[r=2]{} \textbf{High Power | Level 1} \newline Level 1 Certification required for purchase. Certification available through Tripoli or NAR.
Under 125g propellant is Federal Aviation Administration exempt.\\
I & 320.01 – 640 N·s & 71.9 – 144 lbf·s & \\
\end{tblr}
\end{document}
(you might want to have a look at the siunitx package to get proper spacing for your numbers and units...)
You can fix just by substituting some \hline with \cline{1-3}. More precisely, where multirow spans n rows, you must make this substitution n-1 times after it.
\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage[margin=1in]{geometry}
\begin{document}
\renewcommand{\arraystretch}{1.5}
\centering
\begin{tabular}{c|c|c|c}
\hline
\textbf{ Classification} & \textbf{Total Impulse} & \textbf{Total Impulse} & \textbf{Type/}\\
& (Newton-Seconds) & (Pounds-Seconds) & \textbf{US Requirements}\\
\hline
%___________Micro____________
1/8 A & 0—0.3125 \textbf{N·s} & 0 – 0.07 lbf·s & \multirow{1}{*}\textbf{Micro} \\%[.3cm]
%\cline{3-4}
%\cline{4-5}
\hline
%_________Low Power_________
1/4 A & 0.3126 – 0.625 N·s & 0.071 – 0.14 lbf·s & \multirow{6}{*}{Low Power}\\
\cline{1-3}
1/2 A & 0.626 – 1.25 N·s & 0.141 – 0.28 lbf·s & \\
\cline{1-3}
A & 0.626 – 1.25 N·s & 0.141 – 0.28 lbf·s & \\
\cline{1-3}
B & 2.51 – 5.00 N·s & 0.561 – 1.12 lbf·s & \\
\cline{1-3}
C & 5.01 – 10.0 N·s & 1.121 – 2.25 lbf·s & \\
\cline{1-3}
D & 10.01 – 20.0 N·s & 2.251 – 4.5 lbf·s & \\
\hline
%_______Mid Power__________
E & 20.01 – 40.0 N·s & 4.51 – 8.99 lbf·s & \multirow{3}{*}{Mid Power}\\
\cline{1-3}
F & 40.01 – 80.0 N·s & 8.991 – 18.0 lbf·s & \\
\cline{1-3}
G & 80.01 – 160 N·s & 18.01 – 36.0 lbf·s & \\
\hline
%_____High Power | Level 1_________
H & 160.01 – 320 N·s & 36.01 – 71.9 lbf·s & \multirow{2}{150px}{\textbf{ High Power | Level 1} \newline
Level 1 Certification required for purchase. Certification available through Tripoli or NAR. Under 125g propellant is Federal Aviation Administration exempt.}\\
\cline{1-3}
I & 320.01 – 640 N·s & 71.9 – 144 lbf·s & \\[2cm]
\hline
%____High Power | Level 2 _____
J & 640.01 – 1,280 N·s & 144.01–288 lbf·s & \multirow{3}{150px}{\textbf{ High Power | Level 2} \newline
Level 2 Certification required for purchase. Certification available through Tripoli or NAR.}\\
\cline{1-3}
K & 1,280.01 – 2,560 N·s & 288.01–576 lbf·s & \\
\cline{1-3}
L & 2,560.01 – 5,120 N·s & 576.01–1,151 lbf·s & \\[.2cm]
\hline
%_______High Power | Level 3________
M & 5,120.01 – 10,240 N·s & 1,151.01–2,302 lbf·s & \multirow{3}{150px}{\textbf{ High Power | Level 3}
\newline
Level 3 Certification required for purchase. Certification available through Tripoli or NAR.}\\
\cline{1-3}
N & 10,240.01 – 20,480 N·s & 2,302.01–4,604 lbf·s & \\
\cline{1-3}
O & 20,480.01 – 40,960 N·s & 4,604.01–9,208 lbf·s & \\[.2cm]
\hline
\end {tabular}
\end{document}
The output:
Also, \begin{tabular}{c|c|c|c{3.5cm}} and \multirow{3}{150}{} give errors, at least with this header.
Related
I have a table that I would like to split over pages, but I can't seem to figure out how I can do it with my current lay-out or commands that I use.
At this time, I used landscape and minipage so that it would fit on one page:
\documentclass[11pt]{article}
\usepackage{pdflscape}
\usepackage{longtable}
\usepackage{lipsum}
\usepackage{bm}
\usepackage{makecell}
\begin{document}
\begin{landscape}
\centering
\begin{table}[!htb]
\caption{\label{CH2_tab:P80L} Empirical power from the simulation study with the indicators having an overall reliability of 80\% and a linear relationship with the latent variable. The highest power per setting is indicated in bold.}
\renewcommand{\arraystretch}{1.5}
\begin{minipage}{.5\linewidth}
\centering
\medskip
\scalebox{0.45}{
\begin{tabular}{rcccccc}
\hline
& \multicolumn{6}{c}{\textbf{Linear}} \\
\cline{2-7}
& \makecell{\textbf{WMW -- max rel} } & \makecell{\textbf{WMW -- mean }} & \makecell{\textbf{\textit{t} test -- max rel }} & \makecell{\textbf{\textit{t} test -- mean }} & \makecell{\textbf{SEM} } & \makecell{\textbf{SEM -- corrected}} \\
\hline
\multicolumn{7}{l}{$\mathcal{N}(0,1)$} \\
\multicolumn{7}{l}{\bm{$m=n=15$}} \\
\hline
Setting 1 & 29.7 & 31.0 & \textbf{33.2} & 32.9 & 32.4 & 32.1 \\
Setting 2 & 28.4 & 29.2 & 30.7 & \textbf{31.3} & 30.0 & 30.3 \\
Setting 3 & 29.5 & 29.3 & 31.8 & \textbf{32.3} & 32.0 & 31.9 \\
Setting 4 & 25.8 & 26.2 & 28.5 & 27.4 & \textbf{29.4} & 28.6 \\
\hline
\multicolumn{7}{l}{\bm{$m=n=50$}} \\
\hline
Setting 1 & 78.7 & 79.1 & 81.7 & 81.4 & \textbf{83.2} & 83.1 \\
Setting 2 & 79.5 & 78.8 & 81.0 & 80.4 & 82.0 & \textbf{82.1} \\
Setting 3 & 79.2 & 79.9 & 81.2 & 81.8 & \textbf{82.2} & 82.0 \\
Setting 4 & 74.8 & 72.3 & 77.6 & 74.4 & \textbf{80.0} & \textbf{80.0} \\
\hline
\multicolumn{7}{l}{\bm{$m=n=100$}} \\
\hline
Setting 1 & 98.2 & 98.1 & 98.5 & 98.6 & \textbf{98.7} & \textbf{98.7} \\
Setting 2 & 97.7 & 97.7 & 98.2 & \textbf{98.3} & \textbf{98.3} & \textbf{98.3} \\
Setting 3 & 97.6 & 97.5 & 98.1 & \textbf{98.2} & \textbf{98.2} & \textbf{98.2} \\
Setting 4 & 97.4 & 95.1 & 98.1 & 95.8 & 98.1 & \textbf{98.2} \\
\hline
\multicolumn{7}{l}{$t_5$} \\
\multicolumn{7}{l}{\bm{$m=n=15$}} \\
\hline
Setting 1 & 23.5 & 23.9 & 24.2 & 24.1 & \textbf{24.4} & 23.9 \\
Setting 2 & 24.0 & \textbf{24.1} & 23.1 & 22.6 & 22.0 & 22.2 \\
Setting 3 & 23.7 & \textbf{23.8} & 22.4 & 23.1 & 22.5 & 23.3 \\
Setting 4 & 22.1 & 22.4 & 22.2 & 22.4 & 22.4 & \textbf{23.5} \\
\hline
\multicolumn{7}{l}{\bm{$m=n=50$}} \\
\hline
Setting 1 & 65.8 & \textbf{66.1} & 60.8 & 60.9 & 61.8 & 61.4 \\
Setting 2 & \textbf{68.7} & \textbf{68.7} & 62.2 & 62.2 & 63.7 & 63.4 \\
Setting 3 & 67.3 & \textbf{67.6} & 61.1 & 61.4 & 62.7 & 62.2 \\
Setting 4 & \textbf{63.9} & 58.4 & 57.6 & 53.7 & 60.2 & 60.0 \\
\hline
\multicolumn{7}{l}{\bm{$m=n=100$}} \\
\hline
Setting 1 & 92.3 & \textbf{92.4} & 87.6 & 87.6 & 88.0 & 88.1 \\
Setting 2 & \textbf{91.7} & \textbf{91.7} & 87.0 & 87.4 & 87.9 & 87.8 \\
Setting 3 & 93.2 & \textbf{93.4} & 88.9 & 88.7 & 89.4 & 89.5 \\
Setting 4 & \textbf{90.6} & 86.8 & 85.7 & 83.4 & 87.4 & 87.4 \\
\hline
\hline
\end{tabular}
}
\end{minipage}\hfill
\begin{minipage}{.5\linewidth}
\centering
\medskip
\scalebox{0.45}{
\begin{tabular}{rcccccc}
\hline
& \multicolumn{6}{c}{\textbf{Linear}} \\
\cline{2-7}
& \makecell{\textbf{WMW -- max rel} } & \makecell{\textbf{WMW -- mean }} & \makecell{\textbf{\textit{t} test -- max rel }} & \makecell{\textbf{\textit{t} test -- mean }} & \makecell{\textbf{SEM} } & \makecell{\textbf{SEM -- corrected}} \\
\hline
\multicolumn{7}{l}{$Laplace(0,1.25)$} \\
\multicolumn{7}{l}{\bm{$m=n=15$}} \\
\hline
Setting 1 & 21.5 & \textbf{22.3} & 19.6 & 20.4 & 19.3 & 19.0 \\
Setting 2 & \textbf{21.9} & 21.4 & 21.0 & 21.1 & 19.8 & 21.0 \\
Setting 3 & 22.0 & \textbf{22.5} & 20.6 & 20.3 & 20.1 & 20.3 \\
Setting 4 & 17.3 & \textbf{19.8} & 16.5 & 18.8 & 19.4 & 19.3 \\
\hline
\multicolumn{7}{l}{\bm{$m=n=50$}} \\
\hline
Setting 1 & 61.8 & \textbf{62.0} & 53.2 & 53.2 & 55.0 & 54.6 \\
Setting 2 & 62.2 & \textbf{63.2} & 52.7 & 53.3 & 54.5 & 53.8 \\
Setting 3 & 64.6 & \textbf{66.0} & 52.9 & 52.8 & 54.7 & 54.2 \\
Setting 4 & \textbf{58.9} & 56.9 & 51.7 & 49.8 & 56.0 & 56.1 \\
\hline
\multicolumn{7}{l}{\bm{$m=n=100$}} \\
\hline
Setting 1 & \textbf{92.3} & 92.2 & 83.2 & 82.9 & 83.5 & 83.4 \\
Setting 2 & \textbf{88.1} & 87.9 & 77.7 & 77.5 & 78.2 & 78.1 \\
Setting 3 & \textbf{91.0} & 90.7 & 82.6 & 82.9 & 82.9 & 83.0 \\
Setting 4 & \textbf{85.5} & 80.4 & 77.7 & 74.2 & 79.3 & 79.3 \\
\hline
\multicolumn{7}{l}{Exp} \\
\multicolumn{7}{l}{\bm{$m=n=15$}} \\
\hline
Setting 1 & 22.2 & \textbf{23.1} & 18.1 & 18.2 & 18.7 & 18.3 \\
Setting 2 & 19.7 & \textbf{19.8} & 17.0 & 17.5 & 17.2 & 17.5 \\
Setting 3 & 19.4 & \textbf{20.2} & 16.9 & 17.6 & 16.9 & 17.0 \\
Setting 4 & 15.7 & \textbf{16.0} & 13.4 & 14.9 & 14.8 & 14.9 \\
\hline
\multicolumn{7}{l}{\bm{$m=n=50$}} \\
\hline
Setting 1 & 61.9 & \textbf{62.0} & 40.8 & 41.8 & 42.6 & 42.6 \\
Setting 2 & 56.2 & \textbf{57.6} & 38.0 & 38.2 & 39.9 & 39.3 \\
Setting 3 & 63.0 & \textbf{63.5} & 42.6 & 42.6 & 44.9 & 44.8 \\
Setting 4 & \textbf{50.1} & 45.0 & 36.9 & 36.7 & 40.6 & 40.4 \\
\hline
\multicolumn{7}{l}{\bm{$m=n=100$}} \\
\hline
Setting 1 & 86.7 & \textbf{87.2} & 67.2 & 67.5 & 67.7 & 67.8 \\
Setting 2 & 85.4 & \textbf{85.6} & 65.5 & 66.0 & 66.6 & 66.8 \\
Setting 3 & 88.2 & \textbf{88.4} & 66.4 & 66.3 & 67.3 & 67.6 \\
Setting 4 & \textbf{83.5} & 76.1 & 65.2 & 61.1 & 66.9 & 67.7 \\
\hline
\hline
\end{tabular}
}
\end{minipage}\hfill
\end{table}
\end{landscape}
\end{document}
However, I would like to split this table nicely over multiple pages (and thus by using e.g. longtable), in such way that on one page, I have the results for the N(0,1) and Laplace distribution (side by side), and then on the second page the t_5 and Exp distribution (side by side), i.e. split each table over 2 pages, but have 2 tables side by side by using minipage inside long table.
I know I could converge them and just make one large table and then use long table, however, I would really like not to rewrite the code (since I have 10 more tables like this). Does someone know how I could do this? I tried several ways, but none of them produce the result I am looking for.
Thank you for all your feedback!
Heidelinde
I want to do something like this:
It has two headings: the upper one I'm done with but now I want to add a lower heading for only some columns.
Is there a way to add such a heading in latex?
My attempt:
\begin{tabular}{lcccccccc}\hline \hline
& Whole world & Base sample & Whole world & Base sample & Whole world & Base sample & Whole world & Base sample \\
& (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\ \hline \\
& & & & & & & & & \\
\multicolumn{6}{c}{Dependent variable is log GDP per capita in 1995 } \\
& & & & & & & & \\
The following uses the eqparbox package to set the integer and decimal part of each number wrapped inside a \fmtnum
\documentclass{article}
\usepackage{booktabs,makecell,eqparbox}
\newcommand{\mc}{\multicolumn{1}{c}}
\makeatletter
\newcommand{\fmtnum}[1]{\#fmtnum#1\relax}
\def\#fmtnum#1.#2\relax{\eqmakebox[int][r]{$#1.$}\eqmakebox[dec][l]{$#2$}}
\makeatother
\begin{document}
\noindent
\begin{tabular}{ *{8}{c} }
\toprule
\makecell{Whole \\ world \\ (1)} &
\makecell{Base \\ sample \\ (2)} &
\makecell{Whole \\ world \\ (3)} &
\makecell{Base \\ sample \\ (4)} &
\makecell{Whole \\ world \\ (5)} &
\makecell{Base \\ sample \\ (6)} &
\makecell{Whole \\ world \\ (7)} &
\makecell{Base \\ sample \\ (8)} \\
\midrule
\multicolumn{6}{c}{\small Dependent variable is log GDP per capita in 1995} &
\multicolumn{2}{c}{\small \makecell[b]{Dependent variable \\ is log output per \\ worker in 1998}} \\
\cmidrule(lr){1-6}\cmidrule{7-8}
\fmtnum{ 0.54 } & \fmtnum{ 0.52 } & \fmtnum{ 0.47 } & \fmtnum{ 0.43 } & \fmtnum{ 0.47 } & \fmtnum{ 0.41 } & \fmtnum{ 0.45 } & \fmtnum{ 0.46 } \\
\fmtnum{(0.04)} & \fmtnum{(0.06)} & \fmtnum{(0.06)} & \fmtnum{(0.05)} & \fmtnum{(0.06)} & \fmtnum{(0.06)} & \fmtnum{(0.04)} & \fmtnum{(0.06)} \\
\addlinespace
& & \fmtnum{ 0.89 } & \fmtnum{ 0.37 } & \fmtnum{ 1.60 } & \fmtnum{ 0.92 } \\
& & \fmtnum{(0.49)} & \fmtnum{(0.51)} & \fmtnum{(0.70)} & \fmtnum{(0.63)} \\
& & & \fmtnum{-0.62 } & & \fmtnum{-0.60 } \\
& & & \fmtnum{(0.19)} & & \fmtnum{(0.23)} \\
& & & \fmtnum{-1.00 } & & \fmtnum{-0.90 } \\
& & & \fmtnum{(0.15)} & & \fmtnum{(0.17)} \\
& & & \fmtnum{-0.25 } & & \fmtnum{-0.04 } \\
& & & \fmtnum{(0.20)} & & \fmtnum{(0.32)} \\
\fmtnum{ 0.62 } & \fmtnum{ 0.54 } & \fmtnum{ 0.63 } & \fmtnum{ 0.73 } & \fmtnum{ 0.56 } & \fmtnum{ 0.69 } & \fmtnum{ 0.55 } & \fmtnum{ 0.49 } \\
\mc{110} & \mc{64} & \mc{110} & \mc{110} & \mc{64} & \mc{64} & \mc{108} & \mc{61} \\
\bottomrule
\end{tabular}
\end{document}
While it is a bit cumbersome, there is very little uniformity across the table, with mixtures of decimal values using parentheses and negative numbers, numbers without decimal parts and also headers that are wider than their column constituents (columns 7-8).
The above code requires at least 2 compilations with every change in the maximum width of a number's integer or decimal part.
You can streamline the input a little using collcell:
\documentclass{article}
\usepackage{booktabs,makecell,eqparbox,collcell}
\newcommand{\mc}{\multicolumn{1}{c}}
\makeatletter
\newcommand{\fmtnum}[1]{\if\relax\detokenize{#1}\relax\else\#fmtnum#1\relax\fi}
\def\#fmtnum#1.#2\relax{\eqmakebox[int][r]{$#1.$}\eqmakebox[dec][l]{$#2$}}
\makeatother
\begin{document}
\noindent
\begin{tabular}{ *{8}{>{\collectcell\fmtnum}c<{\endcollectcell}} }
\toprule
\mc{\makecell{Whole \\ world \\ (1)}} &
\mc{\makecell{Base \\ sample \\ (2)}} &
\mc{\makecell{Whole \\ world \\ (3)}} &
\mc{\makecell{Base \\ sample \\ (4)}} &
\mc{\makecell{Whole \\ world \\ (5)}} &
\mc{\makecell{Base \\ sample \\ (6)}} &
\mc{\makecell{Whole \\ world \\ (7)}} &
\mc{\makecell{Base \\ sample \\ (8)}} \\
\midrule
\multicolumn{6}{c}{\small Dependent variable is log GDP per capita in 1995} &
\multicolumn{2}{c}{\small \makecell[b]{Dependent variable \\ is log output per \\ worker in 1998}} \\
\cmidrule(lr){1-6}\cmidrule{7-8}
0.54 & 0.52 & 0.47 & 0.43 & 0.47 & 0.41 & 0.45 & 0.46 \\
(0.04) & (0.06) & (0.06) & (0.05) & (0.06) & (0.06) & (0.04) & (0.06) \\
\addlinespace
& & 0.89 & 0.37 & 1.60 & 0.92 \\
& & (0.49) & (0.51) & (0.70) & (0.63) \\
& & & -0.62 & & -0.60 \\
& & & (0.19) & & (0.23) \\
& & & -1.00 & & -0.90 \\
& & & (0.15) & & (0.17) \\
& & & -0.25 & & -0.04 \\
& & & (0.20) & & (0.32) \\
0.62 & 0.54 & 0.63 & 0.73 & 0.56 & 0.69 & 0.55 & 0.49 \\
\mc{110} & \mc{64} & \mc{110} & \mc{110} & \mc{64} & \mc{64} & \mc{108} & \mc{61} \\
\bottomrule
\end{tabular}
\end{document}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
I met this problem in LaTex. Although I know what is the error message meaning, I have no idea about how to solve this error in my task.
\newcommand*{\MinNumber}{0}%
\newcommand*{\MaxNumber}{1.2}%
\pgfmathsetmacro{\MidNumber}{(0.8}%
\def\test#1{\ifdim#1pt>\MidNumber\textcolor{gray!70}{#1}\else{#1}\fi}
\newcommand{\ApplyGradient}[2]{\centering %
\pgfmathsetmacro{\PercentColor}{100.0*(#1-\MinNumber)/(\MaxNumber-\MinNumber)}%
\edef\x{\noexpand\cellcolor{black!\PercentColor}}\x\test{#1}
}
\newcolumntype{R}{>{\collectcell\ApplyGradient}p{1.1cm}<{\endcollectcell}}
\newcolumntype{S}{>{\collectcell\ApplyGradient}p{0.6cm}<{\endcollectcell}}
%
\begin{table}[!ht]
\centering
\small
% \renewcommand{\arraystretch}{0.9}
% \begin{adjustbox}{width=0.8\textwidth}
\begin{tabular}{>{\centering}p{1.3cm}|>{\centering}p{0.9cm}|R R R R R }
\multicolumn{2}{c}{testing in$\rightarrow$}& \multicolumn{1}{c} {$\ang{40}$} & \multicolumn{1}{c} {$\ang{20}$} & \multicolumn{1}{c} {$\ang{0}$} & \multicolumn{1}{c} {$-\ang{20}$} & \multicolumn{1}{c} {$-\ang{40}$} \\ \midrule
& $\ang{40}$ & 0.52 & 0.44 & 0.27 & 0.10 & -0.01 \\
& $\ang{20}$ & 0.47 & 0.49 & 0.35 & 0.19 & 0.07 \\
spider9 & $\ang{0}$ & 0.25 & 0.47 & 0.63 & 0.46 & 0.24 \\
& $-\ang{20}$ & 0.05 & 0.17 & 0.35 & 0.55 & 0.54 \\
& $-\ang{40}$ & 0.0 & 0.05 & 0.21 & 0.47 & 0.77 \\
\midrule
& $\ang{40}$ & 0.75 & 0.69 & 0.40 & 0.17 & 0.04 \\
& $\ang{20}$ & 0.72 & 0.82 & 0.59 & 0.30 & 0.10 \\
gecko7 & $\ang{0}$ & 0.31 & 0.65 & 1.06 & 0.96 & 0.56 \\
& $-\ang{20}$ & 0.16 & 0.45 & 0.86 & 1.18 & 0.98 \\
& $-\ang{40}$ & 0.03 & 0.15 & 0.40 & 0.74 & 0.96 \\
\midrule
& $\ang{40}$ & 1.09 & 0.75 & 0.39 & 0.14 & 0.02 \\
& $\ang{20}$ & 0.54 & 0.55 & 0.33 & 0.15 & 0.04 \\
babyA & $\ang{0}$ & 0.29 & 0.58 & 0.88 & 0.74 & 0.42 \\
& $-\ang{20}$ & 0.18 & 0.47 & 0.85 & 1.09 & 0.71 \\
& $-\ang{40}$ & 0.02 & 0.11 & 0.33 & 0.65 & 0.91 \\
\bottomrule
\end{tabular}
%
\begin{tabular}{p{0.4cm} S}
& 0.0 \\
& 0.1 \\
& 0.2 \\
& 0.3 \\
& 0.4 \\
& 0.5 \\
& 0.6 \\
& 0.7 \\
& 0.8 \\
& 0.9 \\
& 1.0 \\
& 1.1 \\
& 1.2 \\
\end{tabular}
% \end{adjustbox}
\caption{Robustness of the top learned controllers for different directions in the real world.
The data shows the fitness that the top controllers of three robots in 5 directions (the second column) perform in another directions (the first row).
The fitness value in a cell is averaged over three controller and three repetitions for each controller.
The dark and light color represent the high and low fitness value respectively.}
\label{tab:robustness}
\end{table}
The table shows as the picture:
But I got a lot errors like:
Illegal unit of measure (pt inserted).
\protect
l.1545 & $\ang{40}$ & 0.52 &
0.44 & 0.27 & 0.10 & -0.01 \
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)
! Illegal unit of measure (pt inserted).
\protect
l.1545 ... & $\ang{40}$ & 0.52 & 0.44 &
0.27 & 0.10 & -0.01 \
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)
Could you give me hands to solve this problem? Thanks!
Here are some considerations:
While \MinNumber is defined to be 0, you have a number that is smaller than that in the table (-0.01).
If you're performing a test on dimensions (\ifdim <dimA><relation><dimB>) you need to make sure both <dimA> and <dimB> are dimensions. In your case you have
\ifdim#1pt>\MidNumber
and \MidNumber is clearly not a dimension. It is just a number (0.8). That's the main cause of the problem.
\ApplyGradient should only take a single argument, not two.
It's awkward to use booktabs together with vertical rules in a tabular. There's no real need for them; I've kept them in the output, but you don't need them.
\documentclass{article}
\usepackage[margin=1in]{geometry}% Just for this example
\usepackage[table]{xcolor}
\usepackage{booktabs,collcell,xfp}
\newcommand*{\ang}[2]{#1^\circ}
\newcommand*{\MinNumber}{-0.01}%
\newcommand*{\MaxNumber}{1.2}%
\newcommand*{\MidNumber}{0.8}%
\newcommand{\test}[2]{\ifdim#1pt>\MidNumber pt\textcolor{gray!70}{#1}\else #1\fi}
\newcommand{\ApplyGradient}[2]{\centering %
\edef\x{\noexpand\cellcolor{black!\fpeval{100*(#1-\MinNumber)/(\MaxNumber-\MinNumber)}}}\x\test{#1}
}
\newcolumntype{R}{>{\collectcell\ApplyGradient}p{1.1cm}<{\endcollectcell}}
\newcolumntype{S}{>{\collectcell\ApplyGradient}p{0.6cm}<{\endcollectcell}}
%
\begin{document}
\begin{table}
\centering
\begin{tabular}{
>{\centering}p{1.3cm} |
>{\centering}p{0.9cm} |
*{5}{R}
}
\multicolumn{2}{c}{testing in$\rightarrow$} &
\multicolumn{1}{c}{$\ang{40}$} &
\multicolumn{1}{c}{$\ang{20}$} &
\multicolumn{1}{c}{$\ang{0}$} &
\multicolumn{1}{c}{$-\ang{20}$} &
\multicolumn{1}{c}{$-\ang{40}$} \\
\midrule
& $\ang{40}$ & 0.52 & 0.44 & 0.27 & 0.10 & -0.01 \\
& $\ang{20}$ & 0.47 & 0.49 & 0.35 & 0.19 & 0.07 \\
spider9 & $\ang{0}$ & 0.25 & 0.47 & 0.63 & 0.46 & 0.24 \\
& $-\ang{20}$ & 0.05 & 0.17 & 0.35 & 0.55 & 0.54 \\
& $-\ang{40}$ & 0.0 & 0.05 & 0.21 & 0.47 & 0.77 \\
\midrule
& $\ang{40}$ & 0.75 & 0.69 & 0.40 & 0.17 & 0.04 \\
& $\ang{20}$ & 0.72 & 0.82 & 0.59 & 0.30 & 0.10 \\
gecko7 & $\ang{0}$ & 0.31 & 0.65 & 1.06 & 0.96 & 0.56 \\
& $-\ang{20}$ & 0.16 & 0.45 & 0.86 & 1.18 & 0.98 \\
& $-\ang{40}$ & 0.03 & 0.15 & 0.40 & 0.74 & 0.96 \\
\midrule
& $\ang{40}$ & 1.09 & 0.75 & 0.39 & 0.14 & 0.02 \\
& $\ang{20}$ & 0.54 & 0.55 & 0.33 & 0.15 & 0.04 \\
babyA & $\ang{0}$ & 0.29 & 0.58 & 0.88 & 0.74 & 0.42 \\
& $-\ang{20}$ & 0.18 & 0.47 & 0.85 & 1.09 & 0.71 \\
& $-\ang{40}$ & 0.02 & 0.11 & 0.33 & 0.65 & 0.91 \\
\bottomrule
\end{tabular}
\hspace{4mm}
\begin{tabular}{ S }
0.0 \\ 0.1 \\ 0.2 \\ 0.3 \\ 0.4 \\ 0.5 \\
0.6 \\ 0.7 \\ 0.8 \\ 0.9 \\ 1.0 \\ 1.1 \\
1.2
\end{tabular}
\caption{Robustness of the top learned controllers for different directions in the real world.
The data shows the fitness that the top controllers of three robots in~5 directions (the second column) perform in another directions (the first row).
The fitness value in a cell is averaged over three controller and three repetitions for each controller.
The dark and light color represent the high and low fitness value respectively.}
\end{table}
\end{document}
I'm attempting to align two tables in Latex document to be next to each other. Although this is working, the positions of the tables are off. The first is located lower than the second:
Does anyone know how to fix this? Below is my code:
\begin{table}[t]
\begin{minipage}{.55\linewidth}
\begin{tabular}{l|l}
\multicolumn{1}{c|}{\textbf{WordNet}} & \textbf{FreeBase} \\ \hline
domain\_region & cause\_of\_death \\
domain\_topic & ethnicity \\
has\_instance & gender \\
has\_part & institution \\
member\_holonym & nationality \\
member\_meronym & profession \\
part\_of & religion \\
similar\_to & \\
subordinate\_instance\_of & \\
synset\_domain\_topic & \\
type\_of &
\end{tabular}
\label{table1}
\caption{Relationships in WordNet \& FreeBase KBs}
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\begin{tabular}{cccc}
\multicolumn{4}{c}{\textbf{Holdout Set Construction}} \\
\multicolumn{2}{c}{\textbf{WordNet}} & \multicolumn{2}{c}{\textbf{FreeBase}} \\ \hline
Word Removed & \multicolumn{1}{c|}{\# Triples} & Name Removed & \# Triples \\
adult & \multicolumn{1}{c|}{166} & Alan Turing & 15 \\
botany & \multicolumn{1}{c|}{166} & Carl Sagan & 18 \\
building & \multicolumn{1}{c|}{185} & Frank Zappa & 16 \\
center & \multicolumn{1}{c|}{180} & Isaac Asimov & 20 \\
form & \multicolumn{1}{c|}{172} & John Denver & 16 \\
game & \multicolumn{1}{c|}{267} & Karl Marx & 13 \\
lake & \multicolumn{1}{c|}{227} & Mary Astor & 14 \\
land & \multicolumn{1}{c|}{153} & Su Song & 13 \\
mythology & \multicolumn{1}{c|}{178} & Tupac Shakur & 14 \\
room & \multicolumn{1}{c|}{189} & ... & ...
\end{tabular}
\caption{Ten words and a sample of 60 names used for constructing Holdout sets for WordNet and FreeBase, respectively. The numbers of triples that each entity occurs in are listed to the right. These triples comprise the Holdout sets}
\label{table2}
\end{minipage}
\end{table}
You can try setting the tabulars with the same content, even though some rows might be empty. This will ensure they have the same height:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[landscape]{geometry}% Just for this example
\usepackage{booktabs}
\begin{document}
\begin{table}
\mbox{}\hfill
\begin{minipage}[t]{.48\linewidth}
\centering{\ttfamily
\begin{tabular}{ l l }
\toprule
\\
\multicolumn{1}{ c }{\normalfont\bfseries WordNet} & \multicolumn{1}{ c }{\normalfont\bfseries FreeBase} \\
\midrule
domain\_region & cause\_of\_death \\
domain\_topic & ethnicity \\
has\_instance & gender \\
has\_part & institution \\
member\_holonym & nationality \\
member\_meronym & profession \\
part\_of & religion \\
similar\_to & \\
subordinate\_instance\_of & \\
synset\_domain\_topic & \\
type\_of & \\
\bottomrule
\end{tabular}}
\caption{Relationships in WordNet \& FreeBase KBs.}
\end{minipage}\hfill
\begin{minipage}[t]{.48\linewidth}
\centering
\begin{tabular}{ c c c c }
\toprule
\multicolumn{4}{c}{\bfseries Holdout Set Construction} \\
\multicolumn{2}{c}{\bfseries WordNet} & \multicolumn{2}{c}{\bfseries FreeBase} \\
\midrule
\itshape Word Removed & \itshape\# Triples & \itshape Name Removed & \itshape \# Triples \\
adult & 166 & Alan Turing & 15 \\
botany & 166 & Carl Sagan & 18 \\
building & 185 & Frank Zappa & 16 \\
center & 180 & Isaac Asimov & 20 \\
form & 172 & John Denver & 16 \\
game & 267 & Karl Marx & 13 \\
lake & 227 & Mary Astor & 14 \\
land & 153 & Su Song & 13 \\
mythology & 178 & Tupac Shakur & 14 \\
room & 189 & \ldots & \ldots \\
\bottomrule
\end{tabular}
\caption{Ten words and a sample of 60 names used for constructing Holdout sets for WordNet and FreeBase,
respectively. The numbers of triples that each entity occurs in are listed to the right.
These triples comprise the Holdout sets.}
\end{minipage}\hfill
\mbox{}
\end{table}
\end{document}
I've used
fontenc to produce a better \_ within the typewriter font (used in the left-hand table);
booktabs to provide better-looking tables.
\itshape to distinguish a sub-heading within the right-hand table from other content within the same table.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Is there a way to align tables in LaTeX?
I was writing a document with several tables in the same page, and often the edges don't match.
I would like to have tables aligned in both left and right edge.
\paragraph{Articoli}
\begin{large}
\begin{tabular}{ | l | l | l | p{3cm} |}
\hline
\textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo}
\\ \hline
& & & 1500 occorrenze \\ \hline
Codice & Char(7) & 7 & 10,7 kB \\ \hline
Nome & Varchar (100) & 100 & 150 kB \\ \hline
Marca & Varchar (100) & 100 & 150 kB \\ \hline
Prezzo & Money & 8 & 12,2 kB \\ \hline
Disponibile & Integer & 4 & 6.2 kB \\ \hline
Soglia & Integer & 4 & 6.2 kB \\ \hline
Reparto & Char (4) & 4 & 6.2 kB \\ \hline
Totale & & & 321 kB \\ \hline
Dati + Block Header & & & 322 kB \\ \hline
\end{tabular}
\paragraph{Reparti}
\begin{tabular}{ | l | l | l | p{3cm} |}
\hline
\textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo}
\\ \hline
& & & 120 occorrenze \\ \hline
Codice & Char(4) & 4 & 0,5 kB \\ \hline
Nome & Varchar (100) & 100 & 12.1 kB \\ \hline
Sezione & Char(4) & 4 & 0.5 kB \\ \hline
Totale & & & 12.2 kB \\ \hline
Dati + Block Header & & & 12.3 kB \\ \hline
\end{tabular}
\paragraph{Pagamenti}
\begin{tabular}{ | l | l | l | p{3cm} |}
\hline
\textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} \\ \hline
& & & 10 occorrenze \\ \hline
Codice & Char(4) & 4 & 0,1 kB \\ \hline
Nome & Varchar (100) & 100 & 1 kB \\ \hline
Totale & & & 1.1 kB \\ \hline
Dati + Block Header & & & 1.2 kB \\ \hline
\end{tabular}
There are a number of ways to achieve this alignment:
Use a single tabular that would contain everything. This ensures the columns all use the same width:
\documentclass{article}
\begin{document}
\begin{tabular}{ l | l | l | l | p{3cm} |}
\cline{2-5}
& \textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} \\
\cline{2-5}
& & & & 1500 occorrenze \\ \cline{2-5}
& Codice & Char(7) & 7 & 10,7 kB \\ \cline{2-5}
& Nome & Varchar (100) & 100 & 150 kB \\ \cline{2-5}
& Marca & Varchar (100) & 100 & 150 kB \\ \cline{2-5}
\textbf{Articoli} & Prezzo & Money & 8 & 12,2 kB \\ \cline{2-5}
& Disponibile & Integer & 4 & 6.2 kB \\ \cline{2-5}
& Soglia & Integer & 4 & 6.2 kB \\ \cline{2-5}
& Reparto & Char (4) & 4 & 6.2 kB \\ \cline{2-5}
& Totale & & & 321 kB \\ \cline{2-5}
& Dati + Block Header & & & 322 kB \\ \cline{2-5}
\multicolumn{1}{l}{}\\[\bigskipamount]
\cline{2-5}
& \textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} \\
\cline{2-5}
& & & & 120 occorrenze \\ \cline{2-5}
& Codice & Char(4) & 4 & 0,5 kB \\ \cline{2-5}
\textbf{Reparti} & Nome & Varchar (100) & 100 & 12.1 kB \\ \cline{2-5}
& Sezione & Char(4) & 4 & 0.5 kB \\ \cline{2-5}
& Totale & & & 12.2 kB \\ \cline{2-5}
& Dati + Block Header & & & 12.3 kB \\ \cline{2-5}
\multicolumn{1}{l}{}\\[\bigskipamount]
\cline{2-5}
& \textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} \\
\cline{2-5}
& & & & 10 occorrenze \\ \cline{2-5}
& Codice & Char(4) & 4 & 0,1 kB \\ \cline{2-5}
\raisebox{.5\normalbaselineskip}[0pt][0pt]{\textbf{Pagamenti}} &
Nome & Varchar (100) & 100 & 1 kB \\ \cline{2-5}
& Totale & & & 1.1 kB \\ \cline{2-5}
& Dati + Block Header & & & 1.2 kB \\ \cline{2-5}
\end{tabular}
\end{document}
Drawbacks here are the tables don't break across the page boundary (unless you use something like longtable or ltxtable).
Use boxes/overlapping/phantoms to adjust the appropriate entries so they align:
\documentclass{article}
\begin{document}
\leavevmode\rlap{\textbf{Articoli}}%
\phantom{\textbf{Pagamenti}}
\begin{tabular}{ | l | l | l | p{3cm} |}
\hline
\textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} \\
\hline
& & & 1500 occorrenze \\ \hline
Codice & Char(7) & 7 & 10,7 kB \\ \hline
Nome & Varchar (100) & 100 & 150 kB \\ \hline
Marca & Varchar (100) & 100 & 150 kB \\ \hline
Prezzo & Money & 8 & 12,2 kB \\ \hline
Disponibile & Integer & 4 & 6.2 kB \\ \hline
Soglia & Integer & 4 & 6.2 kB \\ \hline
Reparto & Char (4) & 4 & 6.2 kB \\ \hline
Totale & & & 321 kB \\ \hline
Dati + Block Header & & & 322 kB \\ \hline
\end{tabular}
\bigskip
\leavevmode\rlap{\textbf{Reparti}}%
\phantom{\textbf{Pagamenti}}
\begin{tabular}{ | l | l | l | p{3cm} |}
\hline
\textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} \\
\hline
& & & 120 occorrenze \\ \hline
Codice & Char(4) & 4 & 0,5 kB \\ \hline
Nome & Varchar (100) & 100 & 12.1 kB \\ \hline
Sezione & Char(4) & 4 & 0.5 kB \\ \hline
Totale & & & 12.2 kB \\ \hline
Dati + Block Header & & & 12.3 kB \\ \hline
\end{tabular}
\bigskip
\textbf{Pagamenti}
\begin{tabular}{ | l | l | l | p{3cm} |}
\hline
\textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} \\
\hline
& & & 10 occorrenze \\ \hline
Codice & Char(4) & 4 & 0,1 kB \\ \hline
Nome & Varchar (100) & 100 & 1 kB \\ \hline
Totale & & & 1.1 kB \\ \hline
Dati + Block Header & & & 1.2 kB \\ \hline
\end{tabular}
\end{document}
Note the use of % at the end of the overlapping line; this is to avoid a spurious space. See What is the use of percent signs (%) at the end of lines?
Here is another presentation using booktabs and siunitx, foregoing the excessive use of horizontal rules and no vertical rules at all:
\documentclass{article}
\usepackage{booktabs,siunitx,etoolbox}
\newcommand{\tipochar}[1]{Char~(#1)}
\newcommand{\tipovarchar}[1]{Varchar~(#1)}
\newcommand{\tipomoney}{Money}
\newcommand{\tipointeger}{Integer}
\sisetup{%
round-integer-to-decimal,
round-precision = 1,
round-mode = places
}%
\robustify\bfseries
\begin{document}
\begin{tabular}{
>{\hspace*{1em}\itshape}l
l
S[table-format = 3.1]
S[table-format = 3.2]}
\toprule
\multicolumn{1}{l}{\bfseries Attributo} &
\bfseries Tipo &
\multicolumn{1}{l}{\bfseries Byte} &
\multicolumn{1}{l}{\bfseries Complessivo [kB]} \\
\midrule
\multicolumn{1}{l}{Articoli} & & & \multicolumn{1}{c}{\num{1500} occorrenze} \\
Codice & \tipochar{7} & 7 & 10.7 \\
Nome & \tipovarchar{100} & 100 & 150 \\
Marca & \tipovarchar{100} & 100 & 150 \\
Prezzo & \tipomoney & 8 & 12.2 \\
Disponibile & \tipointeger & 4 & 6.2 \\
Soglia & \tipointeger & 4 & 6.2 \\
Reparto & \tipochar{4} & 4 & 6.2 \\
Totale & & & 321 \\
Dati + Block Header & & & 322 \\[.5\normalbaselineskip]
\multicolumn{1}{l}{Reparti} & & & \multicolumn{1}{c}{\num{120} occorrenze} \\
Codice & \tipochar{4} & 4 & 0.5 \\
Nome & \tipovarchar{100} & 100 & 12.1 \\
Sezione & \tipochar{4} & 4 & 0.5 \\
Totale & & & 12.2 \\
Dati + Block Header & & & 12.3 \\[.5\normalbaselineskip]
\multicolumn{1}{l}{Pagamenti} & & & \multicolumn{1}{c}{\num{10} occorrenze} \\
Codice & \tipochar{4} & 4 & 0.1 \\
Nome & \tipovarchar{100} & 100 & 1 \\
Totale & & & 1.1 \\
Dati + Block Header & & & 1.2 \\
\bottomrule
\end{tabular}
\end{document}