环境中的箭头异常拉伸

环境中的箭头异常拉伸

我正在尝试使用提供的解决方案克皮姆话题。

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{tikz}
\usepackage{environ}
\usepackage{fancyhdr}
\usepackage{tasks} 

\pagestyle{empty}


\tikzstyle{fancytitle3}=[draw=black, fill=white, text=black, rounded corners = 3pt, inner sep = 3]
\NewEnviron{sol}{%
 \begin{center}
 \begin{tikzpicture}
  \node[rectangle, rounded corners = 7pt, inner sep = 10 ,minimum width=0.9\textwidth,
     text opacity=1,
    draw=orange, ultra thick, draw opacity=1,
    fill=white, fill opacity=1] (box)
    {%
        \begin{minipage}{.95\textwidth}
         \begin{small}\textsl{\BODY}\end{small}
        \end{minipage}
    };
     \node[fancytitle3, right=5pt] at (box.north west) {\textsl{\textbf{\begin{small}Solution \end{small}} }};
\end{tikzpicture}
\end{center}
}
\tikzset{
main node/.style={inner sep=0,outer sep=0},
label node/.style={inner sep=0,outer ysep=.2em,outer xsep=.4em,font=\scriptsize,overlay},
strike out/.style={shorten <=-.2em,shorten >=-.5em,overlay}
}
\newcommand{\cancelto}[3][]{\tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \node[label node,#1, anchor=south west] at (N.north east){$#3$};
  \draw[strike out,-latex,#1]  (N.south west) -- (N.north east);
}}
\newcommand{\bcancelto}[3][]{\tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \node[label node,#1, anchor=north west] at (N.south east){$#3$};
  \draw[strike out,-latex,#1]  (N.north west) -- (N.south east);
}}
\begin{document}
\begin{align*}
    \text{This is good:}\qquad \cancelto[red]{2x-1}{1}
\end{align*}
\begin{sol}
\begin{align*}
    \text{We don't want this:}\qquad \cancelto[red]{2x-1}{1}
\end{align*}
\end{sol}
\end{document}

在此处输入图片描述

正如您所看到的,当我在\cancelto解决方案环境中使用时,某些东西告诉 tex 拉伸箭头,但我不确定是什么原因造成的。

我知道这个cancel包没有出现这个问题。在这个阶段,我更感兴趣的是目前的情况是否可以得到解决。

答案1

解决此问题的一种方法是使用一个框并将内容排版到其中:

在此处输入图片描述

参考:

代码:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{tikz}
\usepackage{environ}
\usepackage{fancyhdr}
\usepackage{tasks} 

\pagestyle{empty}


\tikzset{fancytitle3/.style={draw=black, fill=white, text=black, rounded corners = 3pt, inner sep = 3}}

\newsavebox{\MyBox}
\NewEnviron{sol}{%
  \savebox{\MyBox}{%
      \begin{minipage}{.95\textwidth}
        \begin{small}\textsl{\BODY}\end{small}
       \end{minipage}%
  }%
 \centering
 \begin{tikzpicture}
  \node[rectangle, rounded corners = 7pt, inner sep = 10 ,minimum width=0.9\textwidth,
     text opacity=1,
    draw=orange, ultra thick, draw opacity=1,
    fill=white, fill opacity=1] (box)
    {%
        \usebox{\MyBox}%
    };
     \node[fancytitle3, right=5pt] at (box.north west) {\textsl{\textbf{\begin{small}Solution \end{small}} }};
\end{tikzpicture}%
}
\tikzset{
main node/.style={inner sep=0,outer sep=0},
label node/.style={inner sep=0,outer ysep=.2em,outer xsep=.4em,font=\scriptsize,overlay},
strike out/.style={shorten <=-.2em,shorten >=-.5em,overlay}
}
\newcommand{\cancelto}[3][]{%
\begingroup
    \tikz[baseline=(N.base)]{
        \node[main node](N){$#2$};
        \node[label node,#1, anchor=south west] at (N.north east){$#3$};
        \draw[strike out,-latex,#1]  (N.south west) -- (N.north east);
    }%
\endgroup
}
\newcommand{\bcancelto}[3][]{%
  \tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \node[label node,#1, anchor=north west] at (N.south east){$#3$};
  \draw[strike out,-latex,#1]  (N.north west) -- (N.south east);
}}
\begin{document}
\begin{align*}
    \text{This is good:}\qquad \cancelto[red]{2x-1}{1}
\end{align*}
\begin{sol}
\begin{align*}
    \text{This is now also good:}\qquad \cancelto[red]{2x-1}{1}
\end{align*}
\end{sol}
\end{document}

答案2

不需要重新发明轮子,这个tcolorbox包允许你创建一个可以完成你需要做的事情的盒子。

输出:

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{tikz}
\usepackage{environ}
\usepackage{fancyhdr}
\usepackage{tasks} 

\pagestyle{empty}

\usepackage[most]{tcolorbox}

% title style "solution" 
\tcbset{titleresume/.style={boxed title style={colframe=black,colbacktitle=white,arc=3pt,boxrule=.6pt}}}

% box creating the box "solution"
\newtcolorbox{solution}{
titleresume,arc=7pt,width=0.95\textwidth,
colframe=orange,colbacktitle=white,coltitle=black,colback=white,fonttitle=\sl\bfseries\large,
center,boxrule=1.6pt,%boxsep=10pt,
enhanced,nobeforeafter,
attach boxed title to top left={yshift=-3mm,xshift=5pt},
title={Solution}}


\tikzset{
main node/.style={inner sep=0,outer sep=0},
label node/.style={inner sep=0,outer ysep=.2em,outer xsep=.4em,font=\scriptsize,overlay},
strike out/.style={shorten <=-.2em,shorten >=-.5em,overlay}
}
\newcommand{\cancelto}[3][]{\tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \node[label node,#1, anchor=south west] at (N.north east){$#3$};
  \draw[strike out,-latex,#1]  (N.south west) -- (N.north east);
}}
\newcommand{\bcancelto}[3][]{\tikz[baseline=(N.base)]{
  \node[main node](N){$#2$};
  \node[label node,#1, anchor=north west] at (N.south east){$#3$};
  \draw[strike out,-latex,#1]  (N.north west) -- (N.south east);
}}
\begin{document}
\begin{align*}
    \text{This is good:}\qquad \cancelto[red]{2x-1}{1}
\end{align*}

\begin{solution}
\begin{align*}
    \text{This is good too:}\qquad \cancelto[red]{2x-1}{1}
\end{align*}
\end{solution}
\end{document}

相关内容