2

I'm trying to make a custom caption format and want to put an overlay in the tcolorbox environment, but it does not seem to like having the overlay option in the definition of the tcolorbox. It compiles fine without the overlay but gives the error:

Argument of \@tempa has an extra }

\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}
  • Please make your code compilable, at the moment, there's \fontspec settings to fonts not everybody has installed and there is no \pagewidth length – user31729 Sep 27 '17 at 16:15
1

The overlay option needs the enhanced option in order to allow for other than standard skins.

Also load hyperref at the end of the preamble here, not somewhere at the beginning.

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.