使用超链接和 tbox 的答案存在问题

使用超链接和 tbox 的答案存在问题

我对以下解决方案有小疑问 带有答案包的超链接

我想制作一个宏,它以解决方案和练习作为参数,使用类似相互引用的按钮,并在视觉上与环境分离。以下是我的 MWE:

\documentclass[12pt,a4paper]{book}
\usepackage{answers}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{tcolorbox}
\usepackage{ifthen}
\usepackage{tikz}
\usetikzlibrary{shadows}

\tikzstyle{buttonstyle} = [rectangle, fill = black!30, draw = black!80, drop shadow, font={\sffamily\bfseries}, text=white]

\newcommand*{\button}[1]{\tikz{\node[buttonstyle] {#1};}}

\theoremstyle{definition}
\newtheorem{ex}{%
  \hypertarget{sol:\theex}{ } \hfill
  \hyperlink{ex:\theex}{\button{Solution}}\\
  \phantomsection
  }[chapter]
\Newassociation{sol}{Soln}{corr}
\renewenvironment{Soln}[1]
  {\par\bigskip\noindent\phantomsection{\bfseries \hypertarget{ex:#1}{}
{\bfseries Solution  of exercise #1}\hfill
  \hyperlink{sol:#1}{\button{Back to exercise #1}}\\}\quad}
  {\par\bigskip}

% Usage \MEExercise[keys]{exercise}{solution}
\newcommand\MEExercise[3][]{
\ifthenelse{\equal{#3}{}}
{ % The no solution case
}
{ %Have a solution
\begin{tcolorbox}
\begin{ex}
#2
\begin{sol}
#3
\end{sol}
\end{ex}
\end{tcolorbox}
}
}

\begin{document}
\chapter{This}
\Opensolutionfile{corr}[ans1]
\section{Problems}
\begin{tcolorbox}
\begin{ex}
First exercise.
\begin{sol}
First solution.
\end{sol}
\end{ex}
\end{tcolorbox}

%\MEExercise{this is exercise 1}{this is solution of exercise 1}
\chapter{That}
%\newpage
\begin{ex}
Second exercise.
\begin{sol}
Second solution.
\end{sol}
\end{ex}
%\MEExercise{this is exercise 2}{this is solution of exercise 2}
%\newpage
\Closesolutionfile{corr}
%\newpage
\section{Solutions}
\input{ans1}
\end{document}

我的问题:1./ 超链接按钮的位置似乎与练习和解决方案毫不相关。如果我将按钮和练习放在一个框中,这或多或少是可以接受的,但最好将按钮放在练习文本的末尾

2./ 我想将内容放入宏中,请参阅 \MEExercise。但是,在这种情况下,ans1 文件的内容是

\begin{Soln}{1.1}
First solution.
\end{Soln}
\begin{Soln}{1.2}
this is solution of exercise 1 \end {sol} \end {ex} \end {tcolorbox}  
\chapter{That}
%\newpage
\begin{ex}
Second exercise.
\begin{sol}
Second solution.
\end{Soln}

并导致错误 \begin{Soln}{1.2}被关闭 \end {sol}

相关内容