我想在对齐环境中使用它。有人知道我该怎么做吗?

我想在对齐环境中使用它。有人知道我该怎么做吗?
\documentclass{article}

\usepackage{tikz, amsmath}

\newcommand{\highlight}[2][black]{\tikz[baseline, anchor=base]{\node[inner sep=2mm](A){$#2$};
    \draw[#1] (A.north east)--(A.south east)--(A.south west);
    \draw[#1] ([shift={(.1,.5)}]A.south east)--([shift={(-.5,-.1)}]A.south east);
    \draw[#1] ([shift={(.1,.3)}]A.south east)--([shift={(-.3,-.1)}]A.south east);
}}

\begin{document}
\begin{center}
   \highlight{a_{\rho}=\dfrac{V^2}{\rho}} 
\end{center}


\end{document}

我用它来强调结果。 在此处输入图片描述

答案1

这使用tikzmark并要求tikzmarknode在开头命名 a 并在结尾命名 another。在align环境之后,\highlight使用您命名的节点调用宏。

您必须编译两次。

在此处输入图片描述

\documentclass{article}

\usepackage{tikz, amsmath}
\usetikzlibrary{tikzmark}

\newcommand{\highlight}[3][orange!70]{\tikz[remember picture, overlay]{
    \draw[very thick, shorten >=-3mm, #1] ([shift={(.2,.1)}]#3.north east)--([shift={(.2,-.2)}]#3.south east)--([shift={(.2,-.2)}]#3.south east-|#2.west);
    \draw[thick, #1] ([shift={(.3,.3)}]#3.south east)--([shift={(-.3,-.3)}]#3.south east);
    \draw[#1] ([shift={(.3,.1)}]#3.south east)--([shift={(-.1,-.3)}]#3.south east);
}}

\begin{document}

\begin{align*}
x&=1\\
y&=2\\
\tikzmarknode{A}{a_{\rho}}&=\tikzmarknode{B}{\dfrac{V^2}{\rho}}
\end{align*}
\highlight{A}{B}

\end{document

答案2

代码

\documentclass{article}
\usepackage{tikz, mathtools}
\pgfqkeys{/tikzHighlight}{
  .code=\pgfqkeys{/tikzHighlight}{#1},
  .unknown/.code=\pgfkeyssetevalue{/tikzHighlight/color}{\pgfkeyscurrentname},
  color/.initial=black, text/.initial=black,
  node/.style={
    text=\pgfkeysvalueof{/tikzHighlight/text},
    anchor=base,overlay=false,inner sep=\fboxsep+.5\fboxrule, outer sep=+0pt,
    append after command={(\tikzlastnode.north east)|-(\tikzlastnode.south west)
      {[shift=(\tikzlastnode.south east),rotate=45]
        (-2mm,1mm) edge[thin] (2mm,1mm) (-3mm,2mm) edge (3mm,2mm)}}
  },
  path/.style={
    overlay,thick,line cap=round,draw=\pgfkeysvalueof{/tikzHighlight/color}},
}
\newcommand*\highlight[1][]{%
  \gdef\tikzHighlightOptions{#1}%
  \tikzHighlightBoxedInt}
\newcommand*\tikzHighlightBoxed[1]{%
  \tikz[baseline,/tikzHighlight/.expand once=\tikzHighlightOptions]
    \draw[/tikzHighlight/path]node[/tikzHighlight/node]{#1};}
\MakeAboxedCommand\tikzHighlightBoxedInt\tikzHighlightBoxed

\begin{document}
\begin{align}
  \highlight                                   {a_{\rho} &= \frac{V^2}{\rho}} \\
  \highlight[orange!70]                {\frac{V^2}{\rho} &= a_{\rho}} \\
  \highlight[path/.append style={rounded corners=2pt}]{E &= mc^2}
\end{align}
\end{document}

输出

在此处输入图片描述

相关内容