인쇄된 내 명령에 대한 카운터를 어떻게 추가할 수 있나요?

인쇄된 내 명령에 대한 카운터를 어떻게 추가할 수 있나요?

다음 코드를 사용하여 경고 표시, 경고라는 단어 및 내용 텍스트가 있는 상자를 그립니다. 이제 작업은 경고를 계산하는 것입니다. 이것을 어떻게 인쇄할 수 있나요? 예를 들어 내 경고가 1장에 나타나면 경고 1.1이라고 합니다. 다음 경고는 1.2 등으로 호출됩니다.

\newcounter{myWarning}
\newcommand{\myWarning}[1]
{
  \refstepcounter{myWarning}
  \begin{longtable}[H]{|p{0.1\linewidth}m{0.9\linewidth}|}\hline
    \textbf{WARNING} & \\
    \includegraphics[width=1cm]{"CommonSubdocuments/Pictures/WarningSign"} & \textbf{#1} \\\hline
  \end{longtable}
  \addtocounter{table}{-1}
}

답변1

foo와 같은 카운터가 로 정의되면 기본값이 로 \newcounter자동 정의됩니다 . 즉, 아라비아 숫자로 카운터 값을 인쇄합니다.\thefoo\arabic{foo}

\newcounter{foo}[chapter]새 장이 시작될 때마다 카운터를 재설정합니다(더 나은 방법: 카운터가 또는 chapter으로 증가할 때) .\refstepcounter\stepcounter

번호 매기기 형식을 변경하려면 를 사용하십시오 \renewcommand{\thefoo}{\thechapter.\arabic{foo}. 즉, foo 번호 앞에 장 번호가 옵니다.

다음은 및 tcolorbox를 사용하여 자동으로 수행되는 유사한 접근 방식입니다 .number withinuse counter=...

\documentclass{book}

\usepackage[most]{tcolorbox}

\usepackage{bclogo}

\newcounter{myWarning}[chapter]

%\renewcommand{\themyWarning}{\thechapter.\arabic{myWarning}}
\newtcolorbox[use counter=myWarning,number within=chapter]{warningbox}[1][]{enhanced jigsaw, sharp corners,title={Warning \thetcbcounter},#1}

\newcommand{\myWarning}[1][]{%
  \begin{warningbox}{#1}
    \textbf{WARNING}

    \bcattention% Warning sign
  \end{warningbox}
}

\begin{document}
\chapter{Foo}
\myWarning

\myWarning

\chapter{Foobar}
\myWarning
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보