指向 tcolorbox 中方程部分的箭头在 XeLaTeX 中偏移且不整洁

指向 tcolorbox 中方程部分的箭头在 XeLaTeX 中偏移且不整洁

我试图将箭头放置在方程式的各个部分,但是我的输出非常混乱...方程式偏移了并且箭头没有进入tcolorbox

在此处输入图片描述

你能帮我把箭头放进去,tcolorbox并且让方程式不发生偏移,就像上图显示的那样吗?

这是我的代码:

\documentclass{article}

\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,,arrows,shapes,decorations.pathreplacing}
\tikzset{every picture/.style={remember picture}}

\usepackage{amsmath}
\usepackage[framemethod=default]{mdframed}
\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={
  arc=0pt,
  outer arc=0pt,
  colback=gray!30,
  colframe=black,
  boxrule=0.8pt,
  left=2pt,
  right=2pt,
  highlight math style={
    arc=0pt,
    outer arc=0pt,
    colback=gray,
    colframe=blue.
    }
  }
}

\begin{document}
\begin{enumerate}
\item The minimum settling time is given as
\begin{tcolorbox}[ams equation, myformula]
\text{Minimum Settling Time } = (%
\tikz[baseline]{\node(d1) {$q$}} +%
\tikz[baseline]{\node(d2) {$\text{max}\{\ell -1, 0 \}$}} + 1)T
\end{tcolorbox}
\begin{tikzpicture}[remember picture,overlay]{
   \draw[blue,thick,latex-,rounded corners] (d1) |- ++ (0.6cm,-1.5cm) node[anchor=west,text = black,] (label1) {input\\order};
   \draw[blue,thick,latex-,rounded corners] (d2) |- ($(label1.west)-(-0.8cm,-0.6cm)$) node[anchor=west,text = black] {G(z)};}
\end{tikzpicture}
\vspace{1cm}

\item This is another item

\end{enumerate}
\end{document}

答案1

我建议不要用手绘制公式的某些部分,而让 LaTeX 渲染它。你的公式的问题在于很难获得正确的间距。至于箭头,你可以使用 tikzmarks 标记页面上指向它们的位置。以下示例就是这样做的(我借用了tcolorboxChristian 的答案中的叠加想法):

\documentclass{article}

\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,,arrows,shapes,decorations.pathreplacing}
\tikzset{every picture/.style={remember picture}}

\usepackage{amsmath}
\usepackage[framemethod=default]{mdframed}
\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={
  arc=0pt,
  outer arc=0pt,
  colback=gray!30,
  colframe=black,
  boxrule=0.8pt,
  left=2pt,
  right=2pt,
  highlight math style={
    arc=0pt,
    outer arc=0pt,
    colback=gray,
    colframe=blue.
    }
  }
}

\begin{document}
\begin{enumerate}
\item The minimum settling time is given as
\begin{tcolorbox}[enhanced,ams equation, myformula,overlay={
  \draw[blue,thick,latex-,rounded corners] (pic cs:d1)+(3pt,-1.1ex) |- ++ (0.6cm,-1.5cm) node[anchor=west,text=black] (label1) {input\ order};
  \draw[blue,thick,latex-,rounded corners] (pic cs:d2)+(3pt,-1.1ex) |- ($(label1.east)-(-0.8cm,-0.6cm)$) node[anchor=west,text=black] {G(z)};}
  ]
  \text{Minimum Settling Time} = (\tikzmark{d1}q+\max\{\ell\tikzmark{d2}-1,0\}+1)T
\end{tcolorbox}
\vspace{1cm}

\item This is another item

\end{enumerate}
\end{document}

此示例仍然不适用于 XeLaTeX。pdfLaTeX 和 LuaLaTeX 可以正常工作。

公式

答案2

在我看来,箭头应该作为一个overlay=选项添加tcolorbox,而不是作为一个单独的环境。

\documentclass{article}

\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,,arrows,shapes,decorations.pathreplacing}
\tikzset{every picture/.style={remember picture}}

\usepackage{amsmath}
\usepackage[framemethod=default]{mdframed}
\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={
  arc=0pt,
  outer arc=0pt,
  colback=gray!30,
  colframe=black,
  boxrule=0.8pt,
  left=2pt,
  right=2pt,
  highlight math style={
    arc=0pt,
    outer arc=0pt,
    colback=gray,
    colframe=blue.
    }
  }
}

\begin{document}
\begin{enumerate}
\item The minimum settling time is given as
  \begin{tcolorbox}[enhanced,ams equation, myformula,overlay={
      \draw[blue,thick,latex-,rounded corners] (d1) |- ++ (0.6cm,-1.5cm) node[anchor=west,text = black,] (label1) {input\ order};
      \draw[blue,thick,latex-,rounded corners] (d2) |- ($(label1.east)-(-0.8cm,-0.6cm)$) node[anchor=west,text = black] {G(z)};}
    ]
\text{Minimum Settling Time } = (%
\tikz[baseline=d1.base]{\node(d1) {$q$}} +%
\tikz[baseline=d2.base]{\node(d2) {$\text{max}\{\ell -1, 0 \}$}} + 1)
\end{tcolorbox}

\item This is another item

\end{enumerate}
\end{document}

在此处输入图片描述

相关内容