tcolorbox 以字幕格式覆盖

tcolorbox 以字幕格式覆盖

我正在尝试制作自定义字幕格式,并希望在环境中放置一个覆盖层tcolorbox,但它似乎不喜欢在 的定义中使用覆盖选项tcolorbox。它编译时没有覆盖层,但会出现错误:

\@tempa 的参数有一个额外的 }

\documentclass[8pt,openany]{book}
\usepackage[english]{babel}         % for typography, proper hyphenation, etc
\usepackage{hyperref}               % creating hyperlinks
\urlstyle{same}
\hypersetup{
    colorlinks=true,                % replace boxed coloring with text coloring
    urlcolor=blue,                  % color of external links
}
\usepackage{graphicx}               % importing images
\usepackage{float}                  % necessary for creating floating env
\usepackage{fontspec}
\setmainfont{LiberationSerif}
\usepackage{calc}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}  % remove header underline
\usepackage{tikz}
\usepackage{mdframed}
\usepackage{caption}
\usepackage[many]{tcolorbox}
\usepackage{color}
\usepackage{titlesec}
\usepackage{wrapfig}


\definecolor{dc-text}{RGB}{60,60,60}
\definecolor{dc-base}{RGB}{150,150,150}
\definecolor{dc-box}{RGB}{200,200,200}
\DeclareCaptionFormat{tcbcaption}{%
\begin{tcolorbox}[
colback=dc-box,
arc=0pt,
outer arc=0pt,
colframe=dc-box,
boxrule=0pt,
colupper=dc-text,
fontupper=\fontspec{LiberationSans-Regular.ttf}\fontsize{8}{10}\selectfont,
boxsep=0pt,
overlay={\path[draw=\chbasecolor] (frame.north west) -- (frame.south east);}
]
{\fontspec{LiberationSans-Bold.ttf}\fontsize{8}{10}#1#2}#3
\end{tcolorbox}%
}
\captionsetup{format=tcbcaption}

\begin{document}
\begin{figure}[t]%default t
    \centering
    \includegraphics[width=\pagewidth]{example-image-a}
    \caption{Foo}
\end{figure}%

\end{document}

答案1

overlay选项需要enhanced选项才能允许使用非标准皮肤。

另外,请hyperref在此处的序言末尾加载,而不是在开头的某个地方。

\documentclass[8pt,openany]{book}
\usepackage[english]{babel}         % for typography, proper hyphenation, etc
\usepackage{graphicx}               % importing images
\usepackage{float}                  % necessary for creating floating env
%\usepackage{fontspec}
%\setmainfont{LiberationSerif}
\usepackage{calc}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}  % remove header underline
\usepackage{tikz}

\usepackage{mdframed}
\usepackage{caption}
\usepackage[many]{tcolorbox}
\usepackage{titlesec}
\usepackage{wrapfig}



\usepackage{hyperref}               % creating hyperlinks

\urlstyle{same}
\hypersetup{
    colorlinks=true,                % replace boxed coloring with text coloring
    urlcolor=blue,                  % color of external links
}



\definecolor{dc-text}{RGB}{60,60,60}
\definecolor{dc-base}{RGB}{150,150,150}
\definecolor{dc-box}{RGB}{200,200,200}
\DeclareCaptionFormat{tcbcaption}{%
  \begin{tcolorbox}[
    enhanced,
    colback=dc-box,
    arc=0pt,
    outer arc=0pt,
    colframe=dc-box,
    boxrule=0pt,
    colupper=dc-text,
    after={\par},
    % fontupper=\fontspec{LiberationSans-Regular.ttf}\fontsize{8}{10}\selectfont,
    boxsep=0pt,
    overlay={\draw[red] (frame.north west) -- (frame.south east);}
    ]
    {%\fontspec{LiberationSans-Bold.ttf}\fontsize{8}{10}
      #1#2}#3%
    \end{tcolorbox}%
}


\captionsetup{format=tcbcaption}

\begin{document}
\begin{figure}[t]%default t
    \centering
    \includegraphics[width=\paperwidth]{example-image-a}
    \caption{Foo}%
\end{figure}%


\end{document}

相关内容