by

Making LaTeX Figures with Custom Cell Borders

It is possible, and only slightly awkward, to make LaTex tables with borders around some of the cells and no borders or only partial borders around other cells. Below are two snippets of code showing you how. Each is followed by an image of the table it produces. This code uses two LaTex packages, multirow and rotating, so the following needs to be before your \begin{document} line. These packages are part of the MacTeX distribution.

 \usepackage{multirow} \usepackage{rotating} 

In the following code, \multicolumn{x}{y}{z} is used to merge {x} columns into one. Notice that the new column resulting from the merge has its own alignment and borders specified by {y} and the text or math equation to be displayed is specified by {z}. Creatively specifying {y} and {z} results in blank white space on the table produced.

 \begin{table} \begin{center} \begin{tabular}{|c|c|c|c|} \cline{2-4} \multicolumn{1}{c|}{} & 1 & 2 & 3 \\ \hline A & A1 & A2 & A3 \\ \hline B & B1 & B2 & B3 \\ \hline C & C1 & C2 & C3 \\ \hline \end{tabular} \end{center} \caption{Table caption.} \label{Table1} \end{table} 

Here is a more advanced example. In the code below, \multirow{x}{y}{z} is used to merge {x} rows into one. Notice that this requires leaving space for the merged rows in subsequent lines of code. This is why each subsequent line begins with an ampersand. The * makes the text in the merged row fit best and use of the sideways environment makes the text in the merged row vertical. The extra tilde after “letters” was used to force some spacing to make the text look good.

 \begin{table} \begin{center} \begin{tabular}{|c|c|c|c|c|} \cline{3-5} \multicolumn{2}{c|}{} & \multicolumn{3}{c|}{numbers} \\ \cline{3-5} \multicolumn{2}{c|}{} & 1 & 2 & 3 \\ \hline \multirow{3}{*}{\begin{sideways} letters~ \end{sideways}} & A & A1 & A2 & A3 \\ \cline{2-5} & B & B1 & B2 & B3 \\ \cline{2-5} & C & C1 & C2 & C3 \\ \hline \end{tabular} \end{center} \caption{Table caption.} \label{Table2} \end{table} 

Hopefully these examples can be adapted to accomplish your wildest LaTex table-making dreams. Enjoy!