2

I would like to set the counter of the colorbox dtn from the value 3 so that it will compile like Type 3, type 4, etc. However, when I use the command setcounter{dtn}{2} then there appears some error. Can someone help me to fix this problem? Thank you guys so much

Here is my code

\documentclass[a4paper,12pt, twoside]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage[utf8]{vietnam}
\usepackage{wrapfig} 
\usepackage[top=2cm, bottom=2cm, left=1.5cm, right=1.5cm]{geometry}
\usepackage{color,graphicx,multicol,multirow,hyperref,geometry,graphicx,amsmath,tikz,amssymb,pgf,tkz-tab,amsfonts,amsthm,array,fancyhdr}
\usepackage{lipsum}
\usepackage{amsxtra, latexsym, amscd, enumerate, ifthen, amstext}
\usepackage{array, tabularx, longtable}
\usepackage{mathrsfs}
\usepackage[all]{xy}
\usepackage{subcaption}
\usepackage{csquotes}
\usetikzlibrary{arrows,calc}
\usetikzlibrary{decorations.pathmorphing,patterns}
\DeclareRobustCommand{\divby}{\mathrel{\vbox{\baselineskip.65ex\lineskiplimit0pt\hbox{.}\hbox{.}\hbox{.}}}}
\DeclareGraphicsExtensions{.pdf,.jpg,.png,.bmp}
\let\mod=\undefined
\let\top=\undefined
 \DeclareMathOperator{\im}{Im}
 \DeclareMathOperator{\Ker}{Ker}
\DeclareMathOperator{\rk}{rank} 
%Tiếng Anh
\newtheorem{theo}{Theorem}[section]
\newtheorem{defi}{Definition}[section]
\newtheorem{cor}{Corollary}[section]
\newtheorem{lem}{Lemma}[section]
\newtheorem{prop}{Proposition}[section]
\newtheorem{exam}{Example}[section]
\newtheorem{rema}{Remark}[section]
\newtheorem{construction}{Construction}[section]
\newtheorem{prob}{Problem}[section]
\newtheorem{ques}{Question}
\newtheorem{exe}{Exercise}

%Tiếng Việt
\newtheorem{theorem}{Định lý}[section]
\newtheorem{theorem1}{Định lý}
\newtheorem{lemma}{Bổ đề}[section]
\newtheorem{exercise}{Bài tập}[section]
\newtheorem{corollary}{Hệ quả}[section]
\newtheorem{proposition}{Mệnh đề}[section]
\newtheorem{remark}{Chú ý}[section]
\newtheorem{comment}{Nhận xét}[section]
\newtheorem{property}{Tính chất}[section]
\newtheorem{definition}{Định nghĩa}[section]
\newtheorem{example}{Ví dụ}[section]
\newtheorem{ex}{Ví dụ}
\newtheorem{bt}{Bài tập}
\newtheoremstyle{mystyle}% Name of the style
  {\topsep}% Space above
  {\topsep}% Space below
  {}% Body font
  {0pt}% Indent amount
  {\bfseries}% Theorem head font
  {}% Punctuation after theorem head (in this case empty because defined in the head spec)
  {.5em}% Space after theorem head
  {\ifstrequal{#3}{done}{\color{Blue}}{}\thmname{#1}\thmnumber{ #2.}}% Theorem head spec
\theoremstyle{mystyle}
\newtheorem{bto}{Bài}
\newtheorem{baitoan}{Bài toán}[section]
\newtheorem{md}{Mệnh đề}
\newtheorem{dl}{Định lý}
\newtheorem*{dn}{Định nghĩa.}
\newtheorem*{vd}{Ví dụ.}
\newtheorem{hq}{Hệ quả}
\newtheorem*{nx}{Nhận xét.}
\newtheorem*{bd}{Bổ đề.}
\newtheorem{cy}{Chú ý}
\newtheorem{ch}{Câu}
\newtheorem{dang}{Dạng}
\newtheorem{GT}[dl]{Assumption}

\newcommand{\Np}{\mathbb{N^*}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\bsq}{\textnormal{\scalebox{2.5}{$\square$}}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Q}{\mathbb{Q}} 
\newcommand{\R}{\mathbb{R}} 
\newcommand{\pr}{\textnormal{P}}
\newcommand{\E}{\textnormal{E}}
\newcommand{\ans}{\textcolor{black!20}{\rule{\textwidth}{.5pt}}}
\renewcommand{\baselinestretch}{1.3}
\newcommand{\parallelsum}{\mathbin{\!/\mkern-5mu/\!}}
\usepackage{centernot} %viết dấu gạch chéo ở mũi tên
\usepackage{indentfirst}
\usepackage{setspace}
\usepackage[shortlabels]{enumitem}
%\setlist{leftmargin=5mm}
%Tạo frame
\usepackage[most]{tcolorbox}
\renewcommand*{\thesection}{\Roman{section}}
\renewcommand*{\thesubsection}{\arabic{subsection}}
\renewcommand\familydefault{\sfdefault}
%san - mathversion
%\DeclareMathVersion{sans}
%\SetSymbolFont{operators}{sans}{OT1}{cmbr}{m}{n}
%\SetSymbolFont{letters}{sans}{OML}{cmbrm}{m}{it}
%\SetSymbolFont{symbols}{sans}{OMS}{cmbrs}{m}{n}
%\SetMathAlphabet{\mathit}{sans}{OT1}{cmbr}{m}{sl}
%\SetMathAlphabet{\mathbf}{sans}{OT1}{cmbr}{bx}{n}
%\SetMathAlphabet{\mathtt}{sans}{OT1}{cmtl}{m}{n}
%\SetSymbolFont{largesymbols}{sans}{OMX}{iwona}{m}{n}
%\sffamily\mathversion{sans}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}

\newtcolorbox[auto counter]{dtn}[2][]{%
colback=white,colframe=Blue!75!black,fonttitle=\bfseries,
title=Type~\thetcbcounter. #2,#1}
\usepackage{fancyhdr,lipsum}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}

%choice in multiple choice answer
\usepackage{tasks,calc}
\settasks{label = \protect\circled{\textbf{\sffamily\Alph*}},
  label-width = 2em,
  label-offset = 0pt,
  item-indent = 2em+4pt}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=1pt] (char) {#1};}}
%dotted line
\begin{document}
\begin{dtn}
something
\end{dtn}
\end{document}

2
  • Welcome! Thanks for providing code, but 'some error' isn't helpful. What error message do you get?
    – cfr
    Sep 30, 2023 at 18:47
  • You can always create your own counter and tell tcolorbox to use that. The auto-assigned counter may well not be just the name of the environment. But that's just a guess without seeing the error.
    – cfr
    Sep 30, 2023 at 18:49

1 Answer 1

3

The counter created by the tcolorbox auto counter option is of the form:

tcb@cnt@<boxname>

So we can easily create a macro to set the counter for any particular box. Its syntax will be

\setboxcounter{boxname}{value}

And its definition is:

\newcommand\setboxcounter[2]{\setcounter{tcb@cnt@#1}{#2}}

Here's your example (massively trimmed to be minimal):

\documentclass[a4paper,12pt, twoside]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tcolorbox}
\makeatletter
\newcommand\setboxcounter[2]{\setcounter{tcb@cnt@#1}{#2}}
\makeatother

\newtcolorbox[auto counter]{dtn}[2][]{%
colback=white,colframe=Blue!75!black,fonttitle=\bfseries,
title=Type~\thetcbcounter. #2,#1}

\begin{document}
\setboxcounter{dtn}{4}
\begin{dtn}{Title}
something
\end{dtn}
\end{document}

output of code

1
  • Thanks. This works for me Oct 1, 2023 at 1:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .