合并表格和 TikZ

合并表格和 TikZ

我正在制作一些会计数字,需要在表格环境内添加带有文本框的花括号和箭头。这是一个示例图: 例子

我想为此使用 TikZ,也许结合表格环境?这看起来太难了,我甚至不知道从哪里开始给你一个我尝试的示例代码。另外,我不确定如何使用“规则”样式命令,它只会像图中那样在某一列上加下划线,而不是整行。

答案1

这个怎么样:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,decorations.pathreplacing,calc}

\begin{document}

\begin{minipage}{.48\textwidth}
\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=6.5em, text centered, rounded corners, minimum height=3.25em]
\begin{tikzpicture}[overlay]
\def \n {3}
\coordinate (a0) at (\n,-0.5);
\coordinate (a1) at (\n,-1);
\coordinate (a2) at (\n,-1.5);
\draw[decoration={brace,amplitude=0.6em,mirror},decorate,ultra thick,gray]($(a1)!(a0.north)!($(a1)-(0,1)$)$) --  ($(a1)!(a2.south)!($(a1)-(0,1)$)$);
\node[block] at ($(a1)-(1.85,0)$) {text 1};

\coordinate (b1) at (\n,-2.5);
\draw[->,ultra thick,gray](b1) --  ($(b1)+(1,0)$);
\node[block] at ($(b1)-(1.85,0)$) {text 2};
\end{tikzpicture}
\end{minipage}
\begin{minipage}[t]{.48\textwidth}
Bla, bla\ldots\\[2mm]

\begin{tabular}{lll}
A & B & C\\
1 & 3 & 3\\
2 & 4 & 6
\end{tabular}

text \ldots
\end{minipage}
\end{document}

剩下的就是坐标的微调。

答案2

我个人建议使用臭名昭著的\tikzmark。这样你就可以:

  • 按照通常方式填写表格
  • \tikzmark{<name>}
  • 使用选项访问这些\tikzmarks并根据需要绘制。\tikzpicture[overlay,remember picture]

这使得人们能够将表格日期与需要添加的图纸分开。

在此处输入图片描述

笔记:

代码:

\documentclass{article}

\usepackage{tikz}
\usepackage{siunitx}
\usepackage{booktabs}
\usetikzlibrary{decorations.pathreplacing}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[baseline] (#1) {};}

\tikzset{My Node Style/.style={midway, right, xshift=3.0ex, align=left, font=\small, draw=blue, thin, fill=cyan!25, text=black}}

\newcommand\VerticalBrace[4][]{%
    % #1 = draw options
    % #2 = top mark
    % #2 = bottom mark
    % #4 = label
  \draw[decorate,decoration={brace, amplitude=1.5ex}, #1] 
    ([yshift=1ex]#2.north east)  -- ([yshift=-1ex]#3.south east)
        node[My Node Style] {#4};
}

\newcommand\DrawArrow[3][]{%
    % #1 = draw options
    % #2 = mark
    % #3 = label
  \draw[<-, shorten >=0.1cm, #1] 
    ([shift={(0.0cm,0.5ex)}]#2.east)  -- ([shift={(1.0cm,0.5ex)}]#2.east)
        node[My Node Style] {#3};
}


\begin{document}
\begin{tabular}{llrr}
\multicolumn{4}{c}{Big Dog Carworks Corp.}\tikzmark{Heading Top} \\
\multicolumn{4}{c}{Income Statement} \\
\multicolumn{4}{c}{For the month eded Jan. 31, 2015}\tikzmark{Heading Bottom} \\
\multicolumn{2}{l}{Revenues} \\[0.5ex]
    & Repair Revenues && \$ \num{15000} \\
\multicolumn{2}{l}{Expenses} \\
    & Rent Expense & \$ \num{1500} \\
    & Salaries Expense & \$ \num{3500} \\
    & Supplies Expense & \$ \num{3500} \\
    & Fuel Expense & \$ \num{3500} \\
    \cmidrule(lr){3-3}
    & Total Expenses && \$ \num{12000} \\
    \cmidrule(lr){4-4}
    & Net Income     && \$ \num{03000} \tikzmark{Net Income Mark}\\
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
    \VerticalBrace[ultra thick, blue]{Heading Top}{Heading Bottom}{%
        The heading shows the name \\
        of the entity, the type of \\
        financial statement, and the \\
        \textit{period-in-time} date.%
    }
    \DrawArrow[ultra thick, blue]{Net Income Mark}{%
        The net income is transferred \\
        to the statement of changes \\
        in equity.%
    }
\end{tikzpicture}

\end{document}

相关内容