10 希望在下面的双向跳转【题目-答案】的基础上将题干和答案套上使用tcolorbox显示,不清楚如何进一步修改?

发布于 2024-08-03 18:26:33

尝试模仿群友@u76459 手搓的一个双向索引【题目-答案】计数器环境,仅在thesection层级下计数,可以实现如下的双向跳转效果。

参考链接: 双向跳转问题链接

以下是MWE,可以编译出具备双向跳转功能的PDF文件。

\documentclass[12pt]{ctexart}
\usepackage{tcolorbox}
\usepackage{lipsum}
\usepackage[hidelinks]{hyperref}
\newcounter{question}[section]
\renewcommand\theHquestion{\thesection-\thequestion}
\newcommand{\labelquestion}{
    \refstepcounter{question}%
    \label{Question\arabic{section}-\arabic{question}}
}
\newcommand{\question}[1]{
    \indent\labelquestion
    \hyperref[{Answer\arabic{section}-\arabic{question}}]{\textbf{\thesection-\thequestion}\hskip .2cm}
}
\newcounter{answer}[section]
\renewcommand\theHanswer{\thesection-\theanswer}
\newcommand{\labelanswer}{
    \refstepcounter{answer}%
    \label{Answer\arabic{section}-\arabic{answer}}
}
\newcommand{\answer}{
    \indent\labelanswer
    \hyperref[{Question\arabic{section}-\arabic{answer}}]{\textbf{\thesection-\theanswer}\hskip .2cm}
}
\begin{document}
\section{这是第一章节}
\question 这是第一题
\lipsum[1]

\question 这是第二题

\answer 这是第一题的答案

\answer 这是第二题的答案

\section{这是第二章节}
\lipsum[2]
\section{这是第三章节}
\question 这是第一题\lipsum[9-12]

\answer 这是第一题的答案\

\question 这是第二题\lipsum[8]

\answer 这是第二题的答案

\end{document}

现在希望将\question\answer命令使用\tcolorbox[title={Question\thesection-\thequestion}]以及\tcolorbox[title={Answer\thesection-\theanswer}]的样式呈现效果,其中希望盒子的title位置的编号同样能实现双向跳转功能,但tbc提供的\thetcbcounter计数器令我迷惑.不知道此处应该如何设置修改?

查看更多

关注者
0
被浏览
331
鱼香肉丝没有鱼先生
鱼香肉丝没有鱼先生.

这是你想要的效果吗?

\documentclass[12pt]{ctexart}
\usepackage[most]{tcolorbox}

\usepackage{lipsum}
\usepackage{hyperref}

\usepackage{pifont}


\newcounter{question}[section]
\newcounter{answer}[section]

\NewTColorBox{question}{}
{enhanced, fonttitle=\bfseries, title={\refstepcounter{question}\label{que:\thesection-\thequestion}Question~\thesection-\thequestion\hfill \ding{43}~\pageref{ans:\thesection-\thequestion}}}

\NewTColorBox{answer}{}
{enhanced, fonttitle=\bfseries, title={\refstepcounter{answer}\label{ans:\thesection-\theanswer}Answer~\thesection-\theanswer\hfill \ding{49}~\pageref{que:\thesection-\theanswer}}}

\begin{document}
\section{这是第一章节}
\begin{question}
    \[
        a^2 + b^2 = c^2
    \]
\end{question}
\lipsum[1-10]


\begin{answer}
    \[
        a^2 + b^2 = c^2
    \]
\end{answer}

\end{document}

image.png
image.png

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览