tcbtheoremのカウンターを得たい

tcbtheoremのカウンターを得たい

- t t の投稿
返信数: 8
お世話になっております。
・環境
windows11、lualatex

・質問
数式番号をtcbtheoremで作った定理環境
(Part番号-章番号.節番号.その中での個数 という形のカウンタにしています。※1)
などと共通にしたいです。つまり、

定理 I-1.1.1
命題 I-1.1.2
(数式) (I-1.1.3)
定義 I-1.1.4

のようにしたいです。
そこで、\numberwithin{equation}{theorem}のようにしてみましたが、エラーでした。
カウンタの設定で、tcbtheoremの「use counter from」に相当するものはありませんか?
もしなければ、他に上記の出力を実現する方法はありませんか?

tcbtheoremのマニュアルなどを読んでみましたが、まるでわかりません。よろしければご教示お願いします。

※1 具体的には
\newcounter{teiribangou}
\renewcommand{\theteiribangou}{\Roman{part}.\arabic{section}.\arabic{subsection}}

\newtcbtheorem[number within=teiribangou]{theorem}{定理}{いろんな設定}{th}
\newtcbtheorem[use counter from=theorem]{prop}{命題}{いろんな設定}{pr}
(いろんな設定のところは、環境の設定諸々。カウンタと無関係。他の系などの環境も同一)
のようにしています
t t への返信

Re: tcbtheoremのカウンターを得たい

- 髙橋 政晴 の投稿

見た目だけであれば、tcolorboxを利用して再現できると思います。


\documentclass{jlreq} \usepackage{amsmath} \newcounter{teiribangou} \renewcommand{\theteiribangou}{\Roman{part}.\arabic{section}.\arabic{subsection}} \newcounter{mycounter} \newcommand{\mycount}{\stepcounter{mycounter}\arabic{mycounter}} \usepackage{tikz,tcolorbox,varwidth,multicol} \usetikzlibrary{calc} \tcbuselibrary{xparse,hooks,skins,breakable} \DeclareTColorBox{囲み枠}{o o}{enhanced,title={#1\, \theteiribangou .\mycount:\, #2}} \makeatletter \def\tagform@#1{% \maketag@@@{(\theteiribangou .\mycount)}% } \makeatother \begin{document} \part{あいうえお} \section{\TeX} \subsection{\LaTeX} \begin{囲み枠}[定理][定理名] a \end{囲み枠} \begin{囲み枠}[命題][タイトル] b \end{囲み枠} \begin{equation} S=\sum_{n=1}^\infty a_n \end{equation} \setcounter{mycounter}{0} \subsection{\LaTeX} \begin{囲み枠}[命題][タイトル] c \end{囲み枠} \begin{equation} S=\sum_{n=1}^\infty a_n \end{equation} \begin{囲み枠}[定義][定義名] d \end{囲み枠} \end{document}
髙橋 政晴 への返信

Re: tcbtheoremのカウンターを得たい

- t t の投稿
ありがとうございます。
参照などに使っている自作コマンドもあるため、theorem環境(tcbtheoremで作った)のカウンタを変更して、equationと同一のカウンタにするか、equationのカウンタをtheorem環境(tcbtheoremで作った)に合わせたいと思っています。
しかし、頂いた返信も、ヒントになるかもしれないです。
それを参考にしながらも所望の結果を得られるよう、色々試してみます。
取り急ぎお礼だけ送信します。
t t への返信

Re: tcbtheoremのカウンターを得たい

- 髙橋 政晴 の投稿

少し強引な手法かもしれませんが、枠線と背景色を消したtcbtheoremを数式を書くためにもう1つ新定義し、そこでカウンタを引き継ぐというのはいかがでしょうか?

具体的なコードを以下に示します。


\documentclass{jlreq} \usepackage{amsmath} \newcounter{teiribangou} \usepackage{tikz,tcolorbox,varwidth,multicol} \usetikzlibrary{calc} \tcbuselibrary{xparse,hooks,skins,breakable,theorems} \renewcommand{\theteiribangou}{\Roman{part}.\arabic{section}.\arabic{subsection}} \makeatletter \def\tagform@#1{% \maketag@@@{(\csname thetcb@cnt@theorem\endcsname)}% } \makeatother \newtcbtheorem[number within=teiribangou]{theorem}{定理}{}{th} \newtcbtheorem[use counter from=theorem]{prop}{命題}{}{pr} \newtcbtheorem[use counter from=theorem]{mydef}{定義}{}{de} \newtcbtheorem[use counter from=theorem]{mymath}{}{colframe=white,colback=white,breakable,top=0mm,bottom=0mm,left=0mm,right=0mm}{ma} \newenvironment{myequation}{\begin{mymath}{}{}\begin{equation}}{\end{equation}\end{mymath}} \begin{document} \part{見出し} \section{\TeX} \subsection{\LaTeX} \begin{theorem}{タイトル1}{} 内容1 \end{theorem} \begin{prop}{タイトル2}{} 内容2 \end{prop} \begin{myequation} S=\sum_{n=1}^\infty a_n \end{myequation} \begin{mydef}{タイトル3}{} 内容3 \end{mydef} \end{document}
髙橋 政晴 への返信

Re: tcbtheoremのカウンターを得たい

- t t の投稿
高橋様

第二案も拝見させていただきました。
しかし、alignなど、他の数式環境を使いたいことや、いろいろな数式環境独自の機能をつかっている、そして過去に作っている書類にも適用させたいことから、カウンターの方を変えたいです。(特にmathtoolsパッケージの\mathtoolsset{showonlyrefs=true} は使いたい)

そして、高橋様の第一案によりすこし進歩しましたことをご報告します。

具体的には、「\thetcb@cnt@theorem」でカウンタを入手し、それを使います。

【しかし、\eqrefが正しく機能しなくなってしまいました。】
1.式を参照するたびにカウンタが進んでしまいます。
2.\eqrefコマンドにhyperリンクがつかなくなってしまいます

これがかなり大きな問題点です。
実際の出力を添付いたします。

コードは以下のとおりです。



\documentclass{ltjsarticle}



\usepackage{amsmath,mathtools}
\usepackage[many]{tcolorbox}
\newcounter{teiribangou}
\renewcommand{\theteiribangou}{\Roman{part}.\arabic{section}.\arabic{subsection}}

%*定理環境
\newtcbtheorem[number within=teiribangou]{theorem}{定理}{}{th}
\newtcbtheorem[use counter from=theorem]{prop}{命題}{}{pr}

\makeatletter
\def\thmcounter{\thetcb@cnt@theorem}
\makeatother

\newcommand{\mycountforeq}{\stepcounter{tcb@cnt@theorem}\thmcounter}

\makeatletter
\let\@org@tagform@\tagform@
\def\tagform@#1{%
\maketag@@@{(\mycountforeq)}%
}

\makeatother

\mathtoolsset{showonlyrefs=true} %参照している数式のみ番号をつける

\usepackage[unicode=true,pdfusetitle]{hyperref}



\begin{document}

\part{part1}
\section{section1}
\subsection{subsection1}


\begin{theorem}{定理環境1}{thmlabel1}
定理1
\end{theorem}

\begin{equation}
equation \label{eq1}
\end{equation}

式を参照\eqref{eq1}

\begin{theorem}{定理環境2}{thmlabel2}
定理2
\end{theorem}


\section{section2}
\subsection{subsection2}

\begin{theorem}{定理環境3}{thmlabel3}
定理3 である。\ref{th:thmlabel1}により、主張である。また、\ref{th:thmlabel2}により、主張である。
\end{theorem}

\begin{equation}
equation2 \label{eq2}
\end{equation}

\begin{align}
align \label{al1}
\end{align}

式を参照\eqref{eq2}、alignも参照\eqref{al1}

\begin{theorem}{定理環境4}{thmlabel4}
定理4
\end{theorem}

\begin{equation}
no+label+equation
\end{equation}

\subsection{subsection3}

\begin{prop}{命題1}{proplabel1}
命題1
\end{prop}


\end{document}
t t への返信

Re: tcbtheoremのカウンターを得たい

- 髙橋 政晴 の投稿
こちら(https://tex.stackexchange.com/questions/411046/how-to-make-specific-equations-follow-theorem-counter)に少し役に立ちそうな情報がありますが、解決は私の技量では厳しいです。
髙橋 政晴 への返信

Re: tcbtheoremのカウンターを得たい

- t t の投稿
高橋さん

色々教えてくださったことを感謝します。
またいろいろ試し、解決策が判明し次第、追記いたします。
t t への返信

Re: tcbtheoremのカウンターを得たい

- 本田 知亮 の投稿
\theteiribangouの定義がまずおかしいです.
teiribangouをどんなにカウントアップしても
そのカウントアップは表に出てこないです

equationカウンタは内部でいろいろ使われるので
このカウンタをtcolorで使うのがいいと思います.

use counterというそのもののオプションがあります.
また,tcolorでそのカウンタの表示形式を変えるオプションnumber formatがあるので
number formatでtcolorでの表示を指定して,
その指定で逆にequationの表示を指定するといいんじゃないかなと思います.

\documentclass{ltjarticle}

\usepackage{amsmath,mathtools}
\usepackage[many]{tcolorbox}


\newtcbtheorem[use counter=equation,number format=\theeq]{theorem}{定理}{}{th}
\newtcbtheorem[use counter=equation,number format=\theeq]{prop}{命題}{}{pr}

\mathtoolsset{showonlyrefs=true} %参照している数式のみ番号をつける

\def\theeq#1{\Roman{part}-\arabic{section}.\arabic{subsection}.\the\value{#1}}
\def\theequation{\theeq{equation}}

\usepackage[unicode=true,pdfusetitle]{hyperref}

以下略
本田 知亮 への返信

Re: tcbtheoremのカウンターを得たい

- t t の投稿
ありがとうございます。
完全な解決を得られました。

また、仕様を理解はしていませんが、
\numberwithin{equation}{subsection}
を付け加えることで、subsectionが変わるごとに
\numberwithin{equation}{section}
を付け加えることで、sectionが変わるごとに
カウンタの一番最後の部分(I.1.1.2 の2の部分)を変えることができました。