Graphics, Figures & TablesTable formatting

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jsamuco
Posts: 3
Joined: Thu Oct 19, 2023 11:59 pm

Table formatting

Post by jsamuco »

Hello!
I have the code below for my table. Everything is okay, but I can not see the horizontal line between the 2nd and 6th columns below the text "Runtime (seconds)", and "Objective  Function Value". See the desire table in attachment. Please, help me. Thank you.

Code: Select all

\documentclass[journal]{IEEEtran}
%\documentclass[12pt]{exam}
%\documentclass[twoside, 11pt]{article}
\RequirePackage{amssymb, amsfonts, amsmath, latexsym, verbatim, xspace, setspace}
\usepackage{booktabs}
\usepackage{blkarray}%matrizes com rótulos em linhas e colunas
%\RequirePackage{tikz, pgflibraryplotmarks}
\usepackage[margin=0.7in]{geometry}
\usepackage[english]{babel}
%\usepackage[DM,final,newLogo]{uaThesis}
%\usepackage{fancyhdr}
%\usepackage[table]{xcolor}
%\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{algpseudocode}
%\usepackage{algcompatible}
\usepackage{colortbl}
\usepackage[long]{optidef}%Problemas de optimização
\usepackage{color}
\usepackage[latin1]{inputenc}
\usepackage{enumerate}
\usepackage{mdframed}%para fazer molduras
\usepackage{lipsum}
\usepackage{array}
\usepackage{multirow}
%\usepackage[table,xcdraw]{xcolor}
\usepackage{xcolor}
\usepackage{enumitem}%melhora o begin description, enumerate e itemize
%\usepackage{bigints}
\usepackage[]{graphicx}%gerir imagens
%\usepackage[export]{adjustbox}
\graphicspath{ {./images/} }%Permite procura as images em pastas de imagens na pasta de trabalho
\usepackage{multicol}%para texto em colunas
\usepackage{lmodern}
\usepackage{float} %gestaoo de posicaoo de figuras
%\floatstyle{boxed} %coloca uma borda fina nas figura
%\restylefloat{figure}%parte da instrução para colocação de borda nas figuras
\usepackage{float} %gestaoo de posicaoo de figuras
%\usepackage{caption}%legenda de figura
\usepackage[justification=justified]{caption}
\usepackage{subcaption}%legendas de subfiguras
\usepackage{indentfirst}
%\usepackage{subfigure}
\usepackage{xcolor}
\usepackage[long]{optidef}
\usepackage{wrapfig}%Permite esccrever texto à volta de figuras
\usepackage{chngcntr}
\counterwithout{figure}{section}%numeração de figuras independente das secções


%\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage{amsmath}
%\usepackage{amsfonts}
%\usepackage{amssymb}
\usepackage{stmaryrd}
%\usepackage{graphicx}
\usepackage[export]{adjustbox}
%\graphicspath{ {./Figuras/} }
%%%%
\usepackage{natbib} %package para a bibliografia

\usepackage{setspace}%espaçamento entre linhas
\usepackage{indentfirst} %permite identar o 1.º paragráfo das secções
\usepackage{url}%mantém os links nos ficheiros PDF
\usepackage{hyperref}%usado para lidar com comandos de referência cruzada em LaTeX para produzir links de hipertexto no documento PDF.
\RequirePackage{pgfcore}
\usepackage{chngcntr}
\usepackage{graphics}

\newcounter{enumr} \renewcommand{\theenumr}{\roman{enumr}}
\providecommand{\sin}{}
\providecommand{\sin}{}
\newenvironment{enumerater}{\begin{list}{(\theenumr)}{\usecounter{enumr}}}{
\end{list}}
\newcommand{\qua}{\hrulefill \hspace{3mm}\fbox{\rule[-0.2cm]{0cm}{0.4 cm} $\;$ } }
\newcommand{\qu}{\fbox{\rule[-0.05cm]{0cm}{0.3 cm} $\;$ } }

\newcommand{\MTL}{{\sc\scriptsize
		MATLAB$\textsuperscript{\textregistered}$}}

\DeclareMathOperator{\arctg}{arctg}
\DeclareMathOperator{\arcsec}{arcsec}
\DeclareMathOperator{\arcsen}{arcsen}
\DeclareMathOperator{\arccot}{arccot}
\DeclareMathOperator{\arccsc}{arccosec}
\DeclareMathOperator{\sen}{sen}
\DeclareMathOperator{\tg}{tg}
\DeclareMathOperator{\cotg}{cotg}
\DeclareMathOperator{\cosec}{cosec}
\DeclareMathOperator{\argmin}{argmin}
% EDITAR CABEÇALHO DA PROVA

\algrenewcommand\algorithmicrequire{\textbf{Input:}}%Nos algoritmos, altera Require para Input
\algrenewcommand\algorithmicensure{\textbf{Output:}}%Nos algoritmos, altera Ensure para Input

\setlist{labelindent=\parindent, leftmargin=*}%alinhar itens enumerate e itemize com o paragrafo
\parskip=3.0mm %inser um espaço de x mm entre parágrafos em todo documento

\newtheorem{teo}{Theorem}%[section]
\newtheorem{defin}{Definition}%[section]
\newtheorem{lema}{Lemma}%[section]
\newtheorem{cor}{Corolary}%[section]
\newtheorem{prop}[teo]{Proposition}
%\newtheorem{defin}[teo]{Definition}
\newtheorem{algor}{Algorithm} %[section]
\newtheorem{prob}{Problem}%[section]
\newtheorem{example}{Example}%[section]
\newtheorem{obser}{Observation}%[section]
\newenvironment{prove}{\endsloppypar\noindent\bgroup%\small
	{\bf Proof. }}{\samepage\null\hfill $\Box$\endsloppypar\egroup}

\numberwithin{equation}{section}%numerar as equações 
\bibliographystyle{plain}

\hyphenation{op-tical net-works semi-conduc-tor}
\begin{document}

\begin{table}[]
	\resizebox{\columnwidth}{!}{
		\begin{tabular}{|c|ccc|ccc|}
			\hline
			\rowcolor[HTML]{A6A6A6}
			\cellcolor[HTML]{A6A6A6} &
			\multicolumn{3}{c|}{\cellcolor[HTML]{A6A6A6}\textbf{Runtime   (seconds)}}  &
			\multicolumn{3}{c|}{\cellcolor[HTML]{A6A6A6}\textbf{Objective Function Value}}\\ \cline{2-7} %\cmidrule{2-7}
			\rowcolor[HTML]{A6A6A6}
			\multirow{-2}{*}{\cellcolor[HTML]{A6A6A6}\textbf{m}} &
			\multicolumn{1}{c|}{\cellcolor[HTML]{A6A6A6}MCL} &
			\multicolumn{1}{c|}{\cellcolor[HTML]{A6A6A6}MC-Greedy} &
			ClusterGreedy &
			\multicolumn{1}{c|}{\cellcolor[HTML]{A6A6A6}Linking   set} &
			\multicolumn{1}{c|}{\cellcolor[HTML]{A6A6A6}MC-Greedy} &
			ClusterGreedy \\ \hline
			46 & \multicolumn{1}{c|}{9.63}  & \multicolumn{1}{c|}{5686.06}  & 1262.49 & \multicolumn{1}{c|}{52} & \multicolumn{1}{c|}{63} & 66 \\ \hline
			74 & \multicolumn{1}{c|}{8.49}  & \multicolumn{1}{c|}{6102.56}  & 1196.61 & \multicolumn{1}{c|}{52} & \multicolumn{1}{c|}{63} & 64 \\ \hline
			35 & \multicolumn{1}{c|}{10.47} & \multicolumn{1}{c|}{1842.13}  & 2980.89 & \multicolumn{1}{c|}{55} & \multicolumn{1}{c|}{63} & 66 \\ \hline
			54 & \multicolumn{1}{c|}{7.18}  & \multicolumn{1}{c|}{6448.28}  & 639.67  & \multicolumn{1}{c|}{54} & \multicolumn{1}{c|}{64} & 55 \\ \hline
			36 & \multicolumn{1}{c|}{9.54}  & \multicolumn{1}{c|}{2507.60}  & 1066.20 & \multicolumn{1}{c|}{57} & \multicolumn{1}{c|}{63} & 67 \\ \hline
			36 & \multicolumn{1}{c|}{19.01} & \multicolumn{1}{c|}{6646.61}  & 2257.27 & \multicolumn{1}{c|}{55} & \multicolumn{1}{c|}{64} & 66 \\ \hline
			57 & \multicolumn{1}{c|}{11.23} & \multicolumn{1}{c|}{3806.67}  & 1519.56 & \multicolumn{1}{c|}{51} & \multicolumn{1}{c|}{62} & 55 \\ \hline
			35 & \multicolumn{1}{c|}{18.50} & \multicolumn{1}{c|}{5989.16}  & 2059.86 & \multicolumn{1}{c|}{54} & \multicolumn{1}{c|}{64} & 67 \\ \hline
			45 & \multicolumn{1}{c|}{11.30} & \multicolumn{1}{c|}{4338.80}  & 2404.25 & \multicolumn{1}{c|}{51} & \multicolumn{1}{c|}{63} & 65 \\ \hline
			35 & \multicolumn{1}{c|}{11.01} & \multicolumn{1}{c|}{4388.51}  & 1660.90 & \multicolumn{1}{c|}{53} & \multicolumn{1}{c|}{63} & 53 \\ \hline
			72 & \multicolumn{1}{c|}{10.74} & \multicolumn{1}{c|}{17638.40} & 2538.96 & \multicolumn{1}{c|}{54} & \multicolumn{1}{c|}{64} & 63 \\ \hline
			36 & \multicolumn{1}{c|}{10.32} & \multicolumn{1}{c|}{13198.84} & 7031.46 & \multicolumn{1}{c|}{52} & \multicolumn{1}{c|}{64} & 66 \\ \hline
			70 & \multicolumn{1}{c|}{9.66}  & \multicolumn{1}{c|}{23175.31} & 2869.66 & \multicolumn{1}{c|}{56} & \multicolumn{1}{c|}{64} & 68 \\ \hline
			35 & \multicolumn{1}{c|}{42.80} & \multicolumn{1}{c|}{18236.07} & 5720.39 & \multicolumn{1}{c|}{56} & \multicolumn{1}{c|}{64} & 67 \\ \hline
			35 & \multicolumn{1}{c|}{10.60} & \multicolumn{1}{c|}{22917.41} & 9670.09 & \multicolumn{1}{c|}{55} & \multicolumn{1}{c|}{65} & 64 \\ \hline
			71 & \multicolumn{1}{c|}{17.54} & \multicolumn{1}{c|}{6037.13}  & 3432.35 & \multicolumn{1}{c|}{55} & \multicolumn{1}{c|}{64} & 65 \\ \hline
			72 & \multicolumn{1}{c|}{11.30} & \multicolumn{1}{c|}{5725.89}  & 2709.56 & \multicolumn{1}{c|}{54} & \multicolumn{1}{c|}{63} & 66 \\ \hline
			35 & \multicolumn{1}{c|}{10.68} & \multicolumn{1}{c|}{5859.43}  & 6857.45 & \multicolumn{1}{c|}{55} & \multicolumn{1}{c|}{64} & 66 \\ \hline
			63 & \multicolumn{1}{c|}{12.22} & \multicolumn{1}{c|}{6199.05}  & 1544.76 & \multicolumn{1}{c|}{56} & \multicolumn{1}{c|}{64} & 68 \\ \hline
			71 & \multicolumn{1}{c|}{11.39} & \multicolumn{1}{c|}{5965.02}  & 1079.90 & \multicolumn{1}{c|}{54} & \multicolumn{1}{c|}{64} & 68 \\ \hline
		\end{tabular}
	}
	%\caption{Computational results for $n=3000$, $k=30$, $r=50$ (from $ 1^{st} $ to $ 10^{th} $ experiments), and $r=100$  (from $ 11^{th} $ to $ 20^{th} $ experiments).}
%	\label{tab3000}
\end{table}
\end{document}
Attachments
tablecommunity.pdf
(93.36 KiB) Downloaded 423 times
Last edited by jsamuco on Sun Oct 22, 2023 6:30 pm, edited 4 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Table formating

Post by Stefan Kottwitz »

Hi,

welcome to the forum!

When we write a post here, there's a "Code" button to format code. Mark text withe the mouse, click the "Code" button. Then the code is nicely formatted with Syntax Highlighting, and then there's a button "Run LaTeX here", so any reader can test the code with a single click. No worries, I did it for you in your post.

The code is incomplete though, an \end{table} missing, but the document including the preamble is missing. Your code cannot be tested, we don't know what packages you use (colortbl? xcolor? booktabs? array?) etc. Not sure if a reader sees in the code why lines are missing, or starts typing \documentclass... etc. by themselves to build an entire document for testing. Your chance to get a solution is much, much higher, when you post a small compilable example, where forum readers can simply click the button "Run LaTeX here", test and fix it and respond with the solution code. Have a look here: Infominimal working example

Best regards,

Stefan
LaTeX.org admin
jsamuco
Posts: 3
Joined: Thu Oct 19, 2023 11:59 pm

Table formatting

Post by jsamuco »

Hi Stefan.

Thank you for help me.

Now I thing the code is ready to be tested for anyone.

Best regards,
José Maria
FPantigny
Posts: 5
Joined: Wed Jul 26, 2023 10:37 pm

Table formatting

Post by FPantigny »

That's a classic problem: \cline is overwritten by the colored panels of \rowcolor.

Here is a easy to construct your table with {NiceTabular} of nicematrix. You need several compilations (because nicematrix uses PGF/TikZ under the hood).

Code: Select all

\documentclass[journal]{IEEEtran}
\usepackage{nicematrix}

\begin{document}
\begin{table}[]
\renewcommand{\arraystretch}{1.3}
\small
\begin{NiceTabular}{ccccccc}[hvlines,color-inside]
\RowStyle[nb-rows=2,rowcolor=[HTML]{A6A6A6}]{}
\Block{2-1}{mu} &
\Block{1-3}{Runtime (seconds)} & & &
\Block{1-3}{Objective Function Value} \\ 
& MCL &
MC-Greedy &
ClusterGreedy &
Linking set &
MC-Greedy &
ClusterGreedy \\ 
46 & {9.63}  & {5686.06}  & 1262.49 & {52} & {63} & 66 \\ 
74 & 8.49  & 6102.56  & 1196.61 & 52 & 63 & 64 \\ 
35 & 10.47 & 1842.13  & 2980.89 & 55 & 63 & 66 \\ 
54 & 7.18  & 6448.28  & 639.67  & 54 & 64 & 55 \\ 
36 & 9.54  & 2507.60  & 1066.20 & 57 & 63 & 67 \\ 
36 & 19.01 & 6646.61  & 2257.27 & 55 & 64 & 66 \\ 
57 & 11.23 & 3806.67  & 1519.56 & 51 & 62 & 55 \\ 
35 & 18.50 & 5989.16  & 2059.86 & 54 & 64 & 67 \\ 
45 & 11.30 & 4338.80  & 2404.25 & 51 & 63 & 65 \\ 
35 & 11.01 & 4388.51  & 1660.90 & 53 & 63 & 53 \\ 
72 & 10.74 & 17638.40 & 2538.96 & 54 & 64 & 63 \\ 
36 & 10.32 & 13198.84 & 7031.46 & 52 & 64 & 66 \\ 
70 & 9.66  & 23175.31 & 2869.66 & 56 & 64 & 68 \\ 
35 & 42.80 & 18236.07 & 5720.39 & 56 & 64 & 67 \\ 
35 & 10.60 & 22917.41 & 9670.09 & 55 & 65 & 64 \\ 
71 & 17.54 & 6037.13  & 3432.35 & 55 & 64 & 65 \\ 
72 & 11.30 & 5725.89  & 2709.56 & 54 & 63 & 66 \\ 
35 & 10.68 & 5859.43  & 6857.45 & 55 & 64 & 66 \\ 
63 & 12.22 & 6199.05  & 1544.76 & 56 & 64 & 68 \\ 
71 & 11.39 & 5965.02  & 1079.90 & 54 & 64 & 68 \\ 
\end{NiceTabular}
\end{table}
\end{document}
jsamuco
Posts: 3
Joined: Thu Oct 19, 2023 11:59 pm

Table formatting

Post by jsamuco »

Hi FPantigny!

Thank you for help me.

Best regards
José Maria
Post Reply