表格集成表的线箭头

表格集成表的线箭头

我最近回顾了这个问题,试图制作一个分部积分表:

分部积分表

我尝试使用其中的代码示例,但 LaTeX 给出了 tikz 箭头的渲染错误(我不知道是什么问题,所以我完全删除了 tikz 代码);但是,当我仅使用表格时,它不会出现这种情况。我的代码如下:

    \documentclass{article}
    \usepackage{gensymb}
    \usepackage{graphicx}
    \usepackage[fleqn]{amsmath}
    \usepackage{amsfonts}
    \usepackage{amssymb}
    \usepackage[usenames,dvipsnames]{color}
    \usepackage{fullpage}
    \usepackage{cancel}
    \usepackage{easylist}
    \usepackage{booktabs}
    \usepackage{xparse}
    \usepackage{graphicx}
    \usepackage{tikz}
    \usepackage{framed} 
    \usepackage{tcolorbox}
    \usepackage[fleqn]{amsmath}
    \usepackage{framed,varwidth}
    \usepackage{enumitem, color, amssymb}
    \providecommand{\e}[1]{\ensuremath{\times 10^{#1}}}
    \begin{document}
    1. $\displaystyle{\int x^6\cdot e^x dx}$ \\
    \newline
    Make a table of u and its derivatives \& dv and its integrals...
   \[\renewcommand{\arraystretch}{1.5}
\begin{array}{c @{\hspace*{1.0cm}} c}\toprule
   D & I \\\cmidrule{1-2}
 x^6\tikzmark{Left 1} & \tikzmark{Right 1}e^x \\
  6x^5\tikzmark{Left 2} & \tikzmark{Right 2}e^x \\
  30x^4 \tikzmark{Left 3} & \tikzmark{Right 3}e^x \\
 120x^3  \tikzmark{Left 4} & \tikzmark{Right 4}e^x \\
 360x^2 \tikzmark{Left 5} & \tikzmark{Right 5} e^x \\
 720x \tikzmark{Left 6} & \tikzmark{Right 6} e^x \\
 720 \tikzmark{Left 7} & \tikzmark{Right 7} e^x \\
 0 \tikzmark{Left 8} & \tikzmark{Right 8} e^x \\\bottomline
\end{array}
\]

\DrawArrow{Left 1}{Right 2}{$+$}
\DrawArrow{Left 2}{Right 3}{$-$}
\DrawArrow{Left 3}{Right 4}{$+$}
\DrawArrow{Left 4}{Right 5}{$-$}
\DrawArrow{Left 5}{Right 6}{$+$}
\DrawArrow{Left 6}{Right 7}{$-$}
\DrawArrow{Left 7}{Right 8}{$+$}
\end{document}

除了我链接的帖子之外,还有什么其他方法可以制作箭头和加号或减号吗?

答案1

这是您的代码的更正版本:

在此处输入图片描述

变化:

  1. 包含了链接问题所需的和相关的宏,并消除了不必要的包\tikzmark\DrawArrow
  2. 用来enumerate对其进行编号——假设可能还有更多。
  3. 在调用后添加尾随的% \DrawArrow
  4. 用来\dots代替...
  5. 替换\bottomrule\bottomline

参考:

代码:

\documentclass{article}
\usepackage{booktabs}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc}
    
\tikzset{Arrow Style/.style={text=black, font=\boldmath}}

\newcommand{\tikzmark}[1]{%
    \tikz[overlay, remember picture, baseline] \node (#1) {};%
}
\newcommand*{\XShift}{0.5em}
\newcommand*{\YShift}{0.5ex}
\NewDocumentCommand{\DrawArrow}{s O{} m m m}{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[->, thick, Arrow Style, #2] 
                ($(#3.west)+(\XShift,\YShift)$) -- 
                ($(#4.east)+(-\XShift,\YShift)$)
        node [midway,above] {#5};
    \end{tikzpicture}%
}

\begin{document}
\begin{enumerate}
    \item $\displaystyle{\int x^6\cdot e^x dx}$
    
    Make a table of $u$ and its derivatives \& $\mathrm{d}v$ and its integrals\dots
   \[\renewcommand{\arraystretch}{1.5}
    \begin{array}{c @{\hspace*{1.0cm}} c}\toprule
       D & I \\\cmidrule(lr){1-2}
       x^6  \tikzmark{Left 1} & \tikzmark{Right 1} e^x \\
      6x^5  \tikzmark{Left 2} & \tikzmark{Right 2} e^x \\
      30x^4 \tikzmark{Left 3} & \tikzmark{Right 3} e^x \\
     120x^3 \tikzmark{Left 4} & \tikzmark{Right 4} e^x \\
     360x^2 \tikzmark{Left 5} & \tikzmark{Right 5} e^x \\
     720x   \tikzmark{Left 6} & \tikzmark{Right 6} e^x \\
     720    \tikzmark{Left 7} & \tikzmark{Right 7} e^x \\
       0    \tikzmark{Left 8} & \tikzmark{Right 8} e^x \\\bottomrule
    \end{array}%
    \]
    % --------
    \DrawArrow{Left 1}{Right 2}{$+$}% <-- Don't forget there.
    \DrawArrow{Left 2}{Right 3}{$-$}%
    \DrawArrow{Left 3}{Right 4}{$+$}%
    \DrawArrow{Left 4}{Right 5}{$-$}%
    \DrawArrow{Left 5}{Right 6}{$+$}%
    \DrawArrow{Left 6}{Right 7}{$-$}%
    \DrawArrow{Left 7}{Right 8}{$+$}%
\end{enumerate}
\end{document}

答案2

使用{NiceArray}nicematrixTikz。

\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}
\usepackage{tikz}
    
\begin{document}
\[\renewcommand{\arraystretch}{1.5}
\begin{NiceArray}{@{\hspace{1em}}c @{\hspace*{1.0cm}}c@{\hspace{1em}}}[create-medium-nodes]
\toprule
   D     & I \\
\cmidrule(lr){1-2}
   x^6   &  e^x \\
  6x^5   &  e^x \\
  30x^4  &  e^x \\
 120x^3  &  e^x \\
 360x^2  &  e^x \\
 720x    &  e^x \\
 720     &  e^x \\
   0     &  e^x \\\bottomrule
\CodeAfter
\begin{tikzpicture} [name suffix = -medium, ->, shorten > = 2pt,every node/.style={above}]
\draw (2-1.south east) to node {$+$} (3-2.west) ; 
\draw (3-1.south east) to node {$-$} (4-2.west) ; 
\draw (4-1.south east) to node {$+$} (5-2.west) ; 
\draw (5-1.south east) to node {$-$} (6-2.west) ; 
\draw (6-1.south east) to node {$+$} (7-2.west) ; 
\draw (7-1.south east) to node {$-$} (8-2.west) ; 
\draw (8-1.south east) to node {$+$} (9-2.west) ; 
\end{tikzpicture}
\end{NiceArray}
\]
\end{document}

您需要多次编译(因为 PGF/Tikz 节点)。

上述代码的输出

相关内容