5

I'd like to remove the horizontal spacing between the text and table lines. I am using @{}, but it removes the vertical line of the table for the first row. Does anyone know why?

\documentclass[11pt,onecolumn]{article}
\usepackage{array}
\usepackage{color, colortbl}
\definecolor{mColor1}{rgb}{0.9,0.9,0.9}
\begin{document}
\newcolumntype{N}{@{}>{\columncolor{red}[0pt][0pt]}m{0pt}@{}}
\begin{table}[h!]
\scriptsize
\caption{Summary}
\centering
\begin{tabular}{| c | @{}c | c | N }
\hline
\rowcolor{mColor1}
\textbf{Author(s)} & \textbf{App.} & \textbf{Algorithm} & \\ [0.5cm]
\hline
\textbf{Author(s)} & \textbf{App.} & \textbf{Algorithm} & \\ [0.5cm]
\hline
\end{tabular}
\label{tabSummary}
\end{table}
\end{document} 

enter image description here

I believe \rowcolor{mColor1} is causing the issue, but I don't know how to fix it! Any help is appreciated. Thanks

2
  • 2
    It removed even \documentclass ... \begin{document}...\end{document} apparently ;-)
    – user31729
    Jan 25 '15 at 17:21
  • \rowcolor has some overhang
    – user31729
    Jan 25 '15 at 17:25
4

It's easier to set \tabcolsep to zero then add space where you need it, this has some space in the outer columns, and tight space in the middle

enter image description here

\documentclass[11pt,onecolumn]{article}
\usepackage{array}
\usepackage{color, colortbl}
\definecolor{mColor1}{rgb}{0.9,0.9,0.9}
\begin{document}
\newcolumntype{N}{@{}>{\columncolor{red}[0pt][0pt]}m{0pt}@{}}
\begin{table}[h!]
\setlength\tabcolsep{0pt}
\scriptsize
\caption{Summary}
\centering
\begin{tabular}{| c | c | c | N }
\hline
\rowcolor{mColor1}
\textbf{\ Author(s)\ } & \textbf{App.} & \textbf{\ Algorithm\ } & \\ [0.5cm]
\hline
\textbf{Author(s)} & \textbf{App.} & \textbf{Algorithm} & \\ [0.5cm]
\hline
\end{tabular}
\label{tabSummary}
\end{table}
\end{document} 
2
  • Thank you for your answer. If a column is left aligned, then I believe, I must set the spacing for all of the rows manually, Am I right? If you change \begin{tabular}{| c | c | c | N } to \begin{tabular}{| l | c | c | N } then the second row is not alight with the first row of the first column.
    – NESHOM
    Jan 25 '15 at 18:44
  • @NESHOM you could use >{\hspace{1em}l} probably. Jan 25 '15 at 18:51
4

I think it's easier to define a new column type C

\newcolumntype{C}{>{\hspace{-\tabcolsep}}c}

and use it instead of c to obtain what you want, so you don't have to manually specify the spacing.

MWE

\documentclass[11pt,onecolumn]{article}
\usepackage{array}
\usepackage{color, colortbl}
\definecolor{mColor1}{rgb}{0.9,0.9,0.9}
\begin{document}
\newcolumntype{N}{@{}>{\columncolor{red}[0pt][0pt]}m{0pt}@{}}
\newcolumntype{C}{>{\hspace{-\tabcolsep}}c}
\begin{table}[h!]
\scriptsize
\caption{Summary}
\centering
\begin{tabular}{| c | C | c | N }
\hline
\rowcolor{mColor1}
\textbf{Author(s)} & \textbf{App.} & \textbf{Algorithm} & \\ [0.5cm]
\hline
\textbf{Author(s)} & \textbf{App.} & \textbf{Algorithm} & \\ [0.5cm]
\hline
\end{tabular}
\label{tabSummary}
\end{table}
\end{document} 

Output

enter image description here

If you want to remove the spacing on the other side, as well, define it as

\newcolumntype{C}{>{\hspace{-\tabcolsep}}c@{}}

and you will get

enter image description here

2
  • 1
    @NESHOM You're welcome. Isn't it simpler this way? Jan 26 '15 at 5:57
  • sorry for the delay. Yes, generally it is easier, however, since I have already defined specific column types it makes it more complicated in my case to include this as well. thanks again.
    – NESHOM
    Jan 27 '15 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.