# How to set a default border for each cell in table?

I have a document which has some tables in it and I want to set some default border for each cell in the table. Right now I have defined a new command and I have to call that command for each cell but I don't want to do this. I want to set it as default so that every cell will have the same border. Is there a command which can solve my problem. My current code is like this

\documentclass[11pt]{article}
\usepackage{blindtext}
\usepackage{xcolor}
\begin{document}
\newcommand{\comm}[1]{
\setlength{\fboxrule}{2pt}
\fcolorbox{red}{white}{#1}
}
\begin{center}
\begin{tabular}{ c c c }
\comm{cell1} & \comm{cell2} & \comm{cell3} \\
\end{tabular}
\end{center}
\end{document}


Here I don't want to call commad "comm" for each cell.

• Welcome to TeX-SE! Are you looking for \setlength\arrayrulewidth{2pt}? See e.g. this answer for examples. – user121799 Jun 14 at 5:53
• It's not totally clear what you want the output to look like. With what you're doing now, if the cells have different widths, the frames around them will also be different widths. This will not look much like a table any more. Are you trying to get thick red vertical and horizontal lines in your table? Then @marmot 's linked answer will solve your problem and we can close this as a duplicate. – Alan Munn Jun 14 at 5:56
• @marmot This would only work when we are using \hline to separate each of the rows and we are inserting "|" in the definition of the tabular tag. But in my example, I am not using any such lines in the tables nut still I want a border around each of the cells of the table. Hope you got it – MRIDUL SHARMA Jun 14 at 6:00
• @AlanMunn All I want is that all the cells(of all the tables) should have a border around them. The border should come even in the case of above example also where I do not have any lines in the table(neither horizontal nor verticle) right now I have to call some command for each cell in order to do that. I want to set some default value for this. Hope this helps. – MRIDUL SHARMA Jun 14 at 6:03

If you want to wrap a macro around each cell, you may be interested in collcell.

\documentclass[11pt]{article}
\usepackage{xcolor}
\usepackage{array}
\usepackage{collcell}
\usepackage{colortbl} % < for alternative
\begin{document}
\newcommand{\comm}[1]{
\setlength{\fboxrule}{2pt}
\fcolorbox{red}{white}{#1}
}
\newcolumntype{E}{>{\collectcell\comm}c<{\endcollectcell}}
This wraps the content of each cell in your macro:
\begin{center}
\begin{tabular}{*3{E}}
cell1 & cell2 & cell3 \\
\end{tabular}
\end{center}
Are you sure you do not want:
\begin{center}
\setlength\arrayrulewidth{2pt}%
\arrayrulecolor{red}%
\begin{tabular}{|*3{c|}}
\hline
cell1 & cell2 & cell3 \\
\hline
\end{tabular}
\end{center}
\end{document}


• I was just about to post this as an answer. You're not citing me. :) But this approach will look awful as soon as you add more rows or if the cells are of unequal width and height. You might want to add an example of this to show the effect. – Alan Munn Jun 14 at 6:09
• @AlanMunn Yes, I agree that it won't look good but this is my interpretation of the OP's question and comments. (And yes, I should have started my answer with "As Alan Munn was going to point out, ...". ;-) – user121799 Jun 14 at 6:13
• @marmot I prefer to use the first format rather than second(cells connected). – MRIDUL SHARMA Jun 14 at 6:20
• @MRIDULSHARMA You are free to use either of them, of course. – user121799 Jun 14 at 6:21
• @MRIDULSHARMA To be clear what we're talking about, try adding a row that contains the following: longCellone & cccc & cell3. Your cell heights and widths will all be different. – Alan Munn Jun 14 at 6:22