如何将右括号放在表格行旁边

如何将右括号放在表格行旁边

如何在表格行旁边放置右括号,如图所示?这是我的 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}

我很欣赏这些解决方案。当我寻求帮助时,我简化了我的 MWE。但是,我无法将这两种解决方案应用于我的实际问题。这是所需的结果。

这是相应的 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}

答案1

由于您的数据构造,您可以将内容堆叠在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}

顶部array与底部分开array,因此可以轻松插入\right支架。

我们使用修改后的版本eqparbox\eqmakebox为数学专用内容设置使用。\eqmathbox[<tag>][<align>]{<stuff>}所有<stuff>具有相同内容的内容<tag>将放置在最大宽度的框中。<align>可以根据需要调整 (left、right 或centre)。

答案2

原来的

这是使用 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}

得出的结果为:

桌子支架

更新以添加两个括号

想法还是一样。我们将 tikzmark 放在我们想要开始和结束括号的地方(在下面的代码中搜索 BarA 和 BarB、FooA 和 FooB),然后使用这些端点在 tikz 中绘制括号。我们可能需要稍微调整一下坐标,以便将括号放在正确的位置。您可以通过更改amplituderaise装饰来更改括号的样式。

\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}

这将产生:

第二张图片

相关内容