How to Frame Cells in a LaTeX Table
At a glance
- 1. Choose the frame
Use table rules for cell edges, or \fbox for a box around the content.
- 2. Add the borders
Use vertical bars in the column specification and \hline or \cline for horizontal rules.
- 3. Target one cell
Override that cell's column format with \multicolumn when only one cell needs vertical edges.
- 4. Check the result
Compile and adjust spacing or rule thickness if the frame looks too tight or heavy.
In LaTeX, framing a table cell can mean drawing borders along the cell edges or putting a small box around its contents. The first approach uses rules in the tabular environment; the second uses \fbox. Choose based on whether you want a table-style border or a content-sized box.
The examples below use only standard LaTeX commands, so no extra package is required.
Draw borders along cell edges
In a tabular column specification, | adds a vertical rule at a column boundary. The command \hline draws a horizontal rule across the table. Put rules between every column and row to give every cell a complete rectangular frame:
\documentclass{article}
\begin{document}
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
Item & Value & Status \\ \hline
Alpha & 12 & Review \\ \hline
Beta & 8 & Ready \\ \hline
\end{tabular}
\end{center}
\end{document}
Here, |c|c|c| puts vertical rules at the outside edges and between the three centered columns. Each \hline supplies a horizontal rule, including the top and bottom borders. Use l or r instead of c if you want a column left- or right-aligned.
Frame just one cell with table rules
If only one cell needs a table-edge frame, use \multicolumn{1}{|c|}{...} for that cell. The first argument says the cell spans one column; the second replaces that cell’s usual column format with one that has vertical rules. Add \cline{2-2} above and below it to draw horizontal rules across just column 2:
\documentclass{article}
\begin{document}
\begin{center}
\begin{tabular}{lcr}
Left & Center & Right \\
\cline{2-2}
Ordinary & \multicolumn{1}{|c|}{Target} & Ordinary \\
\cline{2-2}
Left & Center & Right
\end{tabular}
\end{center}
\end{document}
The vertical bars in the \multicolumn format form the target cell’s sides, and the two \cline{2-2} commands form its top and bottom. Change the column number in each \cline range if the target is in another column. For instance, \cline{1-1} draws a rule only across the first column.
This technique is useful when you want the frame to follow the table’s alignment and rule layout. If the table uses \hline across the whole row, that full-width rule will also cross the other cells; use \cline when you need a partial rule.
Put a box around the contents
Use \fbox{...} when the goal is to outline the text or object inside a cell, rather than draw a border that fills the cell’s entire width. For example, replace Review with \fbox{Review} in the first example. The box grows to fit its contents, so it may be narrower than the column.
You can control the padding and line thickness by setting \fboxsep and \fboxrule. For example:
{\setlength{\fboxsep}{3pt}%
\setlength{\fboxrule}{0.5pt}%
\fbox{Review}}
The braces keep these settings local, so they do not affect boxes elsewhere in the document. \fboxsep sets the gap between the contents and the border; \fboxrule sets the border thickness.
Common mistakes
- Using only
|and expecting a complete frame. Vertical bars make vertical rules only. Add\hlineor\clinefor horizontal rules. - Expecting
\fboxto fill the cell. It frames its contents and padding, not the full column width. Use table rules when the border must align with cell edges. - Forgetting that
\multicolumnreplaces the cell format. Its second argument specifies the formatting for that cell. Include the vertical bars you need there, even if the column specification elsewhere has different rules. - Making boxed content too wide. A boxed object takes extra room for its padding and border. If the table becomes too wide, reduce
\fboxsepor use a cell-edge rule instead. - Adding many heavy rules without checking readability. A full grid is valid, but in some publication styles simpler rules are preferred. Follow the required style when preparing a paper or report.
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.