Скрипт KOMA: изменение шрифта заголовка только для одного типа плавающего объекта

Скрипт KOMA: изменение шрифта заголовка только для одного типа плавающего объекта

Я настроил новый тип поплавка. Используя fontspecпакет в scrreprt, как мне изменить шрифт заголовка только для этого одного типа поплавка? Прямо сейчас я использую \addtokomafont{caption}{\gillfont}и \addtokomafont{captionlabel}{\gillfont}\gillfontуказанием ранее). Это, конечно, меняет шрифт заголовка для всех поплавков. Как мне сделать это только для новой textboxсреды?

введите описание изображения здесь

МВЭ:

    \documentclass{scrreprt}
    \usepackage{lmodern}
    \usepackage[T1]{fontenc}
    \usepackage[english]{babel}

    %%%---being able to use all installed fonts (must compile with LuaLaTeX!)
    \usepackage{fontspec}
    \newfontfamily\gillfont{Gill Sans MT}

    %%%---setting up Box environment as float

    \usepackage{newfloat}
    \usepackage{caption}
    \DeclareFloatingEnvironment[fileext=frm,placement={H},name=Box]{myfloat}

    \captionsetup[myfloat]{labelfont=bf}

    \usepackage[framemethod=TikZ]{mdframed}

    \newenvironment{textbox}[1]
    {\begin{myfloat}[tb]
            \begin{mdframed}[backgroundcolor=gray!10]
                \caption{#1}
                            }
                {\end{mdframed}\end{myfloat}
    }

    %%%---formatting float captions

    \usepackage{chngcntr}
    \counterwithout{myfloat}{chapter}
    \counterwithout{figure}{chapter}
    \counterwithout{table}{chapter}%%--no chapter numbers in floats ("1" instead of "1.1")


    \usepackage[singlelinecheck=false, format=plain]{caption}

    \addtokomafont{caption}{\gillfont}
    \addtokomafont{captionlabel}{\gillfont}

    \usepackage{lipsum}


    \begin{document}

    \begin{textbox}{More details}\label{box1}
    \lipsum[1]
\end{textbox}

\begin{figure}[h]
    \includegraphics[width=0.4\linewidth]{example-image-a}
    \caption{\lipsum[2]}
\end{figure}

\end{document}

решение1

Вот еще одно предложение без пакетов newfloatи caption. Дополнительно я бы заменил пакет mdframedна пакет tcolorbox.

\documentclass{scrreprt}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

%%%---being able to use all installed fonts (must compile with LuaLaTeX!)
\usepackage{fontspec}
\newfontfamily\gillfont{Gill Sans MT}

\DeclareNewTOC[
  type=myfloat,
  float,% defines floating environment myfloat
  %nonfloat,% defines nonfloating environment myfloat-
  tocentryindent=1.5em,
  tocentrynumwidth=2.3em,
  name=Box,
  listname={Boxes},
  atbegin={\addtokomafont{caption}{\gillfont}\addtokomafont{captionlabel}{\gillfont}}
]{frm}

\usepackage{tcolorbox}
\newenvironment{textbox}[1]
  {\begin{myfloat}[tb]
    \begin{tcolorbox}[colback=gray!10,arc=0mm,boxrule=.4pt]
      \caption{#1}%
  }
  {\end{tcolorbox}\end{myfloat}}


%\usepackage{chngcntr}% needed for older TeX distributions
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
\KOMAoptions{captions=nooneline}% can also be set as class option
\setcapindent{0pt}

\usepackage{lipsum}% only for dummy text
\begin{document}
\listofmyfloats
\listoffigures
\clearpage
\begin{textbox}{More details}\label{box1}
  \lipsum[1]
\end{textbox}

\begin{figure}[hb]
  \includegraphics[width=0.4\linewidth]{example-image-a}
  \caption{\lipsum[2]}
\end{figure}
\end{document}

Результат:

введите описание изображения здесь


Если вы тоже хотите использовать \captionof{myfloat}{...}, то замените \DeclareNewTOCкоманду в примере выше на

\DeclareNewTOC[
  type=myfloat,
  float,% defines floating environment myfloat
  %nonfloat,% defines nonfloating environment myfloat-
  tocentryindent=1.5em,
  tocentrynumwidth=2.3em,
  name=Box,
  listname={Boxes}
]{frm}
\makeatletter
\addtokomafont{caption}{\ifstr{\@captype}{myfloat}{\gillfont}{}}
\addtokomafont{captionlabel}{\ifstr{\@captype}{myfloat}{\gillfont}{}}
\makeatother

Пример:

\documentclass{scrreprt}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

%%%---being able to use all installed fonts (must compile with LuaLaTeX!)
\usepackage{fontspec}
\newfontfamily\gillfont{Gill Sans MT}

\DeclareNewTOC[
  type=myfloat,
  float,% defines floating environment myfloat
  %nonfloat,% defines nonfloating environment myfloat-
  tocentryindent=1.5em,
  tocentrynumwidth=2.3em,
  name=Box,
  listname={Boxes}
]{frm}

\makeatletter
\addtokomafont{caption}{\ifstr{\@captype}{myfloat}{\gillfont}{}}
\addtokomafont{captionlabel}{\ifstr{\@captype}{myfloat}{\gillfont}{}}
\makeatother

\usepackage{tcolorbox}
\newenvironment{textbox}[1]
  {\begin{myfloat}[tb]
    \begin{tcolorbox}[colback=gray!10,arc=0mm,boxrule=.4pt]
      \caption{#1}%
  }
  {\end{tcolorbox}\end{myfloat}}


%\usepackage{chngcntr}% needed for older TeX distributions
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
\KOMAoptions{captions=nooneline}% can also be set as class option
\setcapindent{0pt}

\usepackage{lipsum}% only for dummy text
\begin{document}
\listofmyfloats
\listoffigures
\clearpage
\begin{textbox}{More details}\label{box1}
  \lipsum[1]
\end{textbox}

\begin{figure}[hb]
  \includegraphics[width=0.4\linewidth]{example-image-a}
  \caption{\lipsum[2]}
\end{figure}
\captionof{myfloat}{Test myfloat}
\captionof{figure}{Test figure}
\end{document}

Связанный контент