캡션에 간단한 설명이 추가된 그림

캡션에 간단한 설명이 추가된 그림

긴 캡션이 있는 큰 수치가 있습니다. 내 캡션은 형식이 지정되어 있고(캡션 패키지 사용) 괜찮아 보이지만 짧은 설명도 파란색과 굵은 글씨로 추가되도록 좀 더 사용자 정의하고 싶습니다.

현재 그림 캡션에는 간단한 설명이 두 번 추가되어 있습니다. 이는 중복되고 오류가 발생하기 쉬운 것 같습니다. 간단한 설명은 그림 목록에도 사용되며 목록과 그림 자체 모두에 정확히 동일한 간단한 설명이 있는지 확인하고 싶습니다.

MWE:

\documentclass{book}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{xcolor}
\captionsetup[figure]{font={small, singlespacing, sf},labelfont={color=blue, bf, sf}, indention=.5cm, labelsep=quad}

\begin{document}
\listoffigures
\begin{figure}
\includegraphics[width=0.8\textwidth]{black.png}
\centering
\caption[Short description]{\textbf{\color{blue}Short description} Very long description spanning several lines.}
\label{label}
\end{figure}
\end{document}

답변1

\caption다음과 같은 방법으로 재정의할 수 있습니다 . 참고: 현재 상태에서는 이 기능이 에서 제대로 작동하지 않습니다 \caption*.

\documentclass{book}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{xcolor}
\captionsetup[figure]{font={small, singlespacing, sf},labelfont={color=blue, bf, sf}, indention=.5cm, labelsep=quad}

\begin{document}

\makeatletter
    \let\oldcaption\caption
    \def\caption{\@ifnextchar[{\caption@with}{\caption@without}}
    \def\caption@with[#1]#2{\oldcaption[#1]{\textcolor{blue}{\bfseries#1} #2}}
    \def\caption@without#1{\oldcaption{#1}}
\makeatother

\listoffigures
\begin{figure}
    \includegraphics[width=0.8\textwidth]{example-image-duck}
    \centering
    \caption[Short description]{Very long description spanning several lines.}
    \label{label}
\end{figure}
\end{document}

결과

이 정의를 서문에 직접 배치하면 작동하지 않습니다(이유는 모르겠습니다). 하지만 를 활용하는 해결 방법이 있습니다 \AtBeginDocument. 이와 같이 프리앰블에 다음을 넣으면 바로 다음에 실행됩니다 \begin{document}.

\makeatletter
\AtBeginDocument{
    \let\oldcaption\caption
    \def\caption{\@ifnextchar[{\caption@with}{\caption@without}}
    \def\caption@with[#1]#2{\oldcaption[#1]{\textcolor{blue}{\bfseries#1} #2}}
    \def\caption@without#1{\oldcaption{#1}}
}
\makeatother

관련 정보