编辑

编辑

我尝试用 LaTeX 格式化表格,但无法将内容放在表格的左侧和右侧。它看起来像这样:

当前表

我期望它看起来是这样的:

预期表

我想在表格左侧添加表格名称。我尝试通过在第一列之前向表格添加另一列并在那里添加表格名称来实现这一点,但不幸的是图片中的三条线也被画出来了。我希望表格名称看起来不像是实际表格的一部分。

我的第二个问题是关系右侧的文本应仅适用于三行,而不是整个表格。我只找到了导致括号像他们那样放在表格内的解决方案这里或者使用的解决方案\left\right命令,我无法毫无错误地进行编译。

这应该是 MWE:

\documentclass[a4paper, twoside=false, DIV=12, BCOR=5mm, bibliography=totocnumbered, headheight=1cm, footheight=1cm, numbers=autoendperiod]{scrartcl}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{amsmath}

\newenvironment{rcases}
  {\left.\begin{aligned}}
  {\end{aligned}\right\rbrace}

\begin{document}
\begin{figure}[hbp]
\center
\[
\begin{rcases}
\begin{tabular}{lllr}
\toprule
\multicolumn{1}{c}{\textbf{A}} & \multicolumn{1}{c}{\textbf{B}} & \multicolumn{1}{c}{\textbf{C}} & \multicolumn{1}{c}{\textbf{D}}\\
\midrule
    1   & 4 & 7 & 16 \\
    2   & 5 & 8 & 15 \\
    3   & 6 & 9 & 14 \\
    \rowcolor{gray!30}10 & 11 & 12 & 13 \\
    & & & \multicolumn{1}{c}{$\underbrace{\hspace{15em}}$} \\
    & & & \multicolumn{1}{c}{Column} \\
\bottomrule
\end{tabular}   
~\hspace{0.5cm}\end{rcases} Relation
\]
\caption{Example of a DB}
\end{figure}

\end{document}

答案1

像这样吗?

表格和注释

我使用过tikzmark需要 TikZ 的。除非你需要 TikZ,否则这可能不是最有效的策略,但我倾向于使用它,因为我熟悉它并且它有效。

\documentclass[a4paper, twoside=false, DIV=12, BCOR=5mm, bibliography=totocnumbered, headheight=1cm, footheight=1cm, numbers=autoendperiod]{scrartcl}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark,decorations.pathreplacing,calc}
\newlength\mywidth
\begin{document}
  \begin{figure}[hbp]
    \centering
    \settowidth\mywidth{\textbf{\MakeUppercase{Table Name}}}
    \begin{minipage}[t]{\mywidth}
      \mbox{}\par
      \textbf{\MakeUppercase{Table Name}}
    \end{minipage}
    \begin{tabular}[t]{lllr}
      \toprule
      \multicolumn{1}{c}{\textbf{A}} & \multicolumn{1}{c}{\textbf{B}} & \multicolumn{1}{c}{\textbf{C}} & \multicolumn{1}{c}{\textbf{D}}\tikzmark{a}\\
      \midrule
      1   & 4 & 7 & 16\tikzmark{b}\\
      2   & 5 & 8 & 15 \\
      3   & 6 & 9 & 14 \\
      \rowcolor{gray!30}10 & 11 & 12 & 13\tikzmark{c}\\
      & & & \multicolumn{1}{c}{$\underbrace{\hspace{15em}}$}\tikzmark{d}\\
      & & & \multicolumn{1}{c}{Column} \\
      \bottomrule
    \end{tabular}
    \tikz[remember picture, overlay]{%
      \draw [decorate, decoration={brace, amplitude=5pt}] ($({pic cs:a})!1/2!({pic cs:b})$) +(1.5em,0) coordinate (e) -- ({$({pic cs:c})!1/2!({pic cs:d})$} -| e) node [midway, right, xshift=5mm] {Relation};}
    \caption{Example of a DB}
  \end{figure}
\end{document}

编辑

一定有更好的方法来做到这一点,但是......

\documentclass[a4paper, twoside=false, DIV=12, BCOR=5mm, bibliography=totocnumbered, headheight=1cm, footheight=1cm, numbers=autoendperiod]{scrartcl}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{tikz,showframe,calc}
\usetikzlibrary{tikzmark,decorations.pathreplacing,calc}
\newlength\mywidth
\begin{document}
  \begin{figure}[hbp]
    \centering
    \settowidth\mywidth{\textbf{\MakeUppercase{Table Name}}}
    \begin{minipage}[t]{\mywidth}
      \mbox{}\par
      \textbf{\MakeUppercase{Table Name}}
    \end{minipage}
    \begin{tabular}[t]{lllr}
      \toprule
      \multicolumn{1}{c}{\textbf{A}} & \multicolumn{1}{c}{\textbf{B}} & \multicolumn{1}{c}{\textbf{C}} & \multicolumn{1}{c}{\textbf{D}}\tikzmark{a}\\
      \midrule
      1   & 4 & 7 & 16\tikzmark{b}\\
      2   & 5 & 8 & 15 \\
      3   & 6 & 9 & 14 \\
      \rowcolor{gray!30}10 & 11 & 12 & 13\tikzmark{c}\\
      & & & \multicolumn{1}{c}{$\underbrace{\hspace{15em}}$}\tikzmark{d}\\
      & & & \multicolumn{1}{c}{Column} \\
      \bottomrule
    \end{tabular}
    \settowidth\mywidth{Relation}%
    \addtolength\mywidth{1.5em+5mm+5pt}%
    \hspace*{\mywidth}%
    \tikz[remember picture, overlay]{%
      \draw [decorate, decoration={brace, amplitude=5pt}] ($({pic cs:a})!1/2!({pic cs:b})$) +(1.5em,0) coordinate (e) -- ({$({pic cs:c})!1/2!({pic cs:d})$} -| e) node [midway, right, xshift=5mm] {Relation};}
    \caption{Example of a DB}
  \end{figure}
\end{document}

showframe只是为了查看相对于页面的图形。实际使用时请将其移除。结果(显示框架):

已调整

这可能不是完全居中但可能足够接近......

答案2

另一种方法是使用bigdelim:来自文档(在源代码中)

% Usage in a tabular or array:
% \usepackage{multirow}
% \usepackage{bigdelim}
% \ldelim({n}{w}[text]
% \rdelim){n}{w}[text]
% Use these commands in a column of a tabular or array. They generate a big
% parenthesis/brace extending over the next n rows (including this one).
% The corresponding entries in the next rows must explicitely be given as
% empty cells. The first parameter must be the delimiter to be used, e.g.
% \{ \} [ ] ( ), in fact any parameter that can be used with \left and
% \right. The text is optional and is set centered to the left of
% \ldelim and to the right of \rdelim.  w must be the width reserved for
% the brace and text.  If you have a recent version of multirow.sty {w} may
% be given as {*}, but this may cause the braces to be too small. Also with
% a recent version of multirow.sty the commands may be used in the last row
% of the extension with a negative n parameter. This is useful in
% combination with the colortbl package (see multirow.sty)
% If there are unusually large rows you may have to enlarge n (you can use
% non-integral values).
% If you have horizontal lines that interact with the braces you are
% advised to use the hhline package to make the lines.

代码:

\documentclass[a4paper, twoside=false, DIV=12, BCOR=5mm, bibliography=totocnumbered, headheight=1cm, footheight=1cm, numbers=autoendperiod]{scrartcl}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{amsmath}

\usepackage{multirow}
\usepackage{bigdelim}

\newenvironment{rcases}
  {\left.\begin{aligned}}
  {\end{aligned}\right\rbrace}

\begin{document}
\begin{figure}[hbp]
\centering

\begin{tabular}{lllrl@{}}
\toprule
\multicolumn{1}{c}{\textbf{A}} & \multicolumn{1}{c}{\textbf{B}} & \multicolumn{1}{c}{\textbf{C}} & \multicolumn{1}{c}{\textbf{D}}\\
\midrule
    1   & 4 & 7 & 16 & \\
    2   & 5 & 8 & 15 & \\
    3   & 6 & 9 & 14 & \\
    \rowcolor{gray!30}10 & 11 & 12 & 13 & \cellcolor{white}\rdelim\}{-4}{-\tabcolsep}[Relation] \\
    & & & \multicolumn{1}{c}{$\underbrace{\hspace{15em}}$} & \\
    & & & \multicolumn{1}{c}{Column} & \\
\bottomrule
\end{tabular}
\caption{Example of a DB}
\end{figure}

\end{document}

在此处输入图片描述

相关内容