# How to place right brace next to table row

How do I put a right brace next to the table row as described by the picture? Here is my MWE.

\documentclass[12pt]{article}
\usepackage{color, colortbl}

\begin{document}

\begin{tabular}{|l|l}
\hline
$$C_{i+0} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$ \\
$$C_{i+1} = \cos(k_3) A_{i+1} + \sin(k_4) B_{i+1}$$ \\
\hline
$$C_{i+0} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$ \\
$$C_{i+1} = \cos(k_3) A_{i+1} + \sin(k_4) B_{i+1}$$ \\
$$C_{i+2} = \cos(k_5) A_{i+2} + \sin(k_6) B_{i+2}$$ \\
$$C_{i+3} = \cos(k_7) A_{i+3} + \sin(k_8) B_{i+3}$$ \\
\hline
\end{tabular}

\end{document}


I appreciate the solutions. I simplified my MWE when I asked for help. However, I'm having trouble adapting both solutions to my actual problem. Here is the desired result.

And here is the corresponding MWE.

\documentclass[12pt]{article}

\usepackage{color, colortbl}

\begin{document}

\begin{tabular}{|l|l}
\hline
$$C_{i\textcolor{white}{+0}} = \textcolor{white}{\cos(k_1)} A_{i\textcolor{white}{+0}} + \textcolor{white}{\sin(k_2)} B_{i\textcolor{white}{+0}}$$\\
\hline
$$C_{i\textcolor{white}{+0}} = \textcolor{white}{\cos(}k_1 \textcolor{white}{)} A_{i\textcolor{white}{+0}} + \textcolor{white}{\sin(}k_2 \textcolor{white}{)} B_{i\textcolor{white}{+0}}$$\\
\hline
$$C_{i\textcolor{white}{+0}} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$ \\
\hline
$$C_{i+0} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$ \\
$$C_{i+1} = \cos(k_3) A_{i+1} + \sin(k_4) B_{i+1}$$ \\
\hline
$$C_{i+0} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$ \\
$$C_{i+1} = \cos(k_3) A_{i+1} + \sin(k_4) B_{i+1}$$ \\
$$C_{i+2} = \cos(k_5) A_{i+2} + \sin(k_6) B_{i+2}$$ \\
$$C_{i+3} = \cos(k_7) A_{i+3} + \sin(k_8) B_{i+3}$$ \\
\hline
$$C_{\textcolor{white}{i+0}} = \textcolor{white}{\cos(k_1)} A_{\textcolor{white}{i+0}} * \textcolor{white}{\sin(k_2)} B_{\textcolor{white}{i+0}}$$\\
\hline
\end{tabular}

\end{document}

– Werner
Commented Jan 31, 2018 at 6:10

Because of your data construction, you can stack the content inside a left-aligned array:

\documentclass{article}

\usepackage{eqparbox,xparse}

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
\IfValueTF{#1}
{\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
{\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
\mathpalette\eqmathbox@{#3}
}
\makeatother

\begin{document}

$\begin{array}{@{} l @{}} \begin{array}{ | l | } \hline \eqmathbox[C][l]{C_i} = \eqmathbox[cos]{} \eqmathbox[A][l]{A_i} + \eqmathbox[sin]{} \eqmathbox[B][l]{B_i} \end{array} \\ \begin{array}{ | l | } \hline \eqmathbox[C][l]{C_i} = \eqmathbox[cos][r]{ k_1 \phantom{)}} \eqmathbox[A][l]{A_i} + \eqmathbox[sin][r]{ k_2 \phantom{)}} \eqmathbox[B][l]{B_i} \end{array} \\ \begin{array}{ | l | } \hline \eqmathbox[C][l]{C_i} = \eqmathbox[cos][r]{\cos(k_1)} \eqmathbox[A][l]{A_i} + \eqmathbox[sin][r]{\sin(k_2)} \eqmathbox[B][l]{B_i} \end{array} \\ \left.\kern-\nulldelimiterspace \begin{array}{ | l | } \hline \eqmathbox[C][l]{C_{i + 0}} = \eqmathbox[cos][l]{\cos(k_1)} \eqmathbox[A][l]{A_i} + \eqmathbox[sin][l]{\sin(k_2)} \eqmathbox[B][l]{B_i} \\ \eqmathbox[C][l]{C_{i + 1}} = \eqmathbox[cos][l]{\cos(k_3)} \eqmathbox[A][l]{A_{i + 1}} + \eqmathbox[sin][l]{\sin(k_4)} \eqmathbox[B][l]{B_{i + 1}} \end{array} \right\} \mbox{bar} \\ \left.\kern-\nulldelimiterspace \begin{array}{ | l | } \hline \eqmathbox[C][l]{C_{i + 0}} = \eqmathbox[cos][l]{\cos(k_1)} \eqmathbox[A][l]{A_i} + \eqmathbox[sin][l]{\sin(k_2)} \eqmathbox[B][l]{B_i} \\ \eqmathbox[C][l]{C_{i + 1}} = \eqmathbox[cos][l]{\cos(k_3)} \eqmathbox[A][l]{A_{i + 1}} + \eqmathbox[sin][l]{\sin(k_4)} \eqmathbox[B][l]{B_{i + 1}} \\ \eqmathbox[C][l]{C_{i + 2}} = \eqmathbox[cos][l]{\cos(k_5)} \eqmathbox[A][l]{A_{i + 2}} + \eqmathbox[sin][l]{\sin(k_6)} \eqmathbox[B][l]{B_{i + 2}} \\ \eqmathbox[C][l]{C_{i + 3}} = \eqmathbox[cos][l]{\cos(k_7)} \eqmathbox[A][l]{A_{i + 3}} + \eqmathbox[sin][l]{\sin(k_8)} \eqmathbox[B][l]{B_{i + 3}} \end{array} \right\} \mbox{foo} \\ \begin{array}{ | l | } \hline \eqmathbox[C][l]{C} = \eqmathbox[cos]{} \eqmathbox[A][l]{A} \times \eqmathbox[sin]{} \eqmathbox[B][l]{B} \\ \hline \end{array} \end{array}$

\end{document}


The top array is separate from the bottom array, and therefore makes it easy to insert a \right brace.

We use a modified version of eqparbox's \eqmakebox set for math-specific content using \eqmathbox[<tag>][<align>]{<stuff>}. All <stuff> with the same <tag> will be placed in a box of maximum width. <align>ment can be adjusted as needed (left, right or centre).

## Original

Here is one approach using tikzmark.

\documentclass[12pt]{article}
\usepackage{color, colortbl}
\usepackage{tikz}
\usetikzlibrary{tikzmark,decorations.pathreplacing,calc}

\begin{document}

\begin{tabular}{|l|l}
\hline
$$C_{i+0} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$ \\
$$C_{i+1} = \cos(k_3) A_{i+1} + \sin(k_4) B_{i+1}$$ \\
\hline
$$C_{i+0} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$ \tikzmark{A}  \\
$$C_{i+1} = \cos(k_3) A_{i+1} + \sin(k_4) B_{i+1}$$ \\
$$C_{i+2} = \cos(k_5) A_{i+2} + \sin(k_6) B_{i+2}$$ \\
$$C_{i+3} = \cos(k_7) A_{i+3} + \sin(k_8) B_{i+3}$$ \tikzmark{B} \\
\hline
\end{tabular}
\begin{tikzpicture}[remember picture, overlay]
\draw [thick,decorate,decoration={brace,amplitude=10pt,raise=4pt}]
($(pic cs:A) + (0.3, 0.2)$)   --  ($(pic cs:B) + (0.3,-0.1)$) node [midway,xshift=0.9cm] {Foo};
\end{tikzpicture}

\end{document}


This produces:

## Update to add two brackets

Idea is still the same. We place tikzmark at the places where we want to start and end braces (search for BarA and BarB, FooA and FooB in the code below) and then draw the braces in tikz using these end points. We may have to play around with coordinates a bit to place the brackets in the right place. You can change the style of brackets by changing amplitude and raise in decoration.

\documentclass[12pt]{article}

\usepackage{color, colortbl}
\usepackage{tikz}
\usetikzlibrary{tikzmark,decorations.pathreplacing,calc}

\begin{document}

\begin{tabular}{|l|l}
\hline
$$C_{i\textcolor{white}{+0}} = \textcolor{white}{\cos(k_1)} A_{i\textcolor{white}{+0}} + \textcolor{white}{\sin(k_2)} B_{i\textcolor{white}{+0}}$$\\
\hline
$$C_{i\textcolor{white}{+0}} = \textcolor{white}{\cos(}k_1 \textcolor{white}{)} A_{i\textcolor{white}{+0}} + \textcolor{white}{\sin(}k_2 \textcolor{white}{)} B_{i\textcolor{white}{+0}}$$\\
\hline
$$C_{i\textcolor{white}{+0}} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$ \\
\hline
$$C_{i+0} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$ \tikzmark{BarA}\\
$$C_{i+1} = \cos(k_3) A_{i+1} + \sin(k_4) B_{i+1}$$ \tikzmark{BarB}\\
\hline
$$C_{i+0} = \cos(k_1) A_{i\textcolor{white}{+0}} + \sin(k_2) B_{i\textcolor{white}{+0}}$$\tikzmark{FooA} \\
$$C_{i+1} = \cos(k_3) A_{i+1} + \sin(k_4) B_{i+1}$$ \\
$$C_{i+2} = \cos(k_5) A_{i+2} + \sin(k_6) B_{i+2}$$ \\
$$C_{i+3} = \cos(k_7) A_{i+3} + \sin(k_8) B_{i+3}$$\tikzmark{FooB} \\
\hline
$$C_{\textcolor{white}{i+0}} = \textcolor{white}{\cos(k_1)} A_{\textcolor{white}{i+0}} * \textcolor{white}{\sin(k_2)} B_{\textcolor{white}{i+0}}$$\\
\hline
\end{tabular}
\begin{tikzpicture}[remember picture, overlay]
\draw [thick,decorate,decoration={brace}]
($(pic cs:FooA) + (0.5, 0.2)$)   --  ($(pic cs:FooB) + (0.5,-0.1)$) node [midway,xshift=0.9cm] {Foo};
\draw [thick,decorate,decoration={brace}]
($(pic cs:BarA) + (0.4, 0.2)$)   --  ($(pic cs:BarB) + (0.4,-0.1)$) node [midway,xshift=0.8cm] {Bar};
\end{tikzpicture}

\end{document}


This will produce: