2

I'm using tcolorbox to document some commands, and I would like to have a slight background color on the body text of the command explanations. I have the below MWE to show this by wrapping the body in its own tcolorbox with a colback value.

However, I would like to remove the white space between the head and the body, such that they are directly connected. I have tried adjusting the boxes via nobeforeafter and before/after skips without luck.

I suspect that the body (and thus the tcolorbox that I create with the before/after doc body keys in the preamble) is wrapped in something, but I don't know how to access and change it.

example

\documentclass{article}

\usepackage{tcolorbox}
\tcbuselibrary{documentation}

\tcbset{
    doc head={
        interior style={fill,color=blue!10},
        boxsep=2pt,
        after skip=0pt,
        nobeforeafter,
        %show bounding box,
    },
    before doc body={
        \begin{tcolorbox}[
            colback=blue!5,
            colframe=blue!5,
            arc=0pt,
            outer arc=0pt,
            before skip=0pt,
            nobeforeafter,
        ]
    },
    after doc body={\end{tcolorbox}},
}


\begin{document}

\begin{docCommand}
    {myCommand}
    {\marg{argument}}
    Some description of the command. Blah blah blah.
\end{docCommand}

\end{document}

1 Answer 1

2

The doc head tcolorbox is placed within a tcbraster, which has a default after skip of 4.1pt. This needs to be set to 0pt using doc raster={raster after skip=0pt} and then the gap is removed:

\documentclass{article}

\usepackage{tcolorbox}
\tcbuselibrary{documentation}

\tcbset{
    doc head={
        interior style={fill,color=blue!10},
        boxsep=2pt,
    },
    doc raster={raster after skip=0pt},
    before doc body={
        \begin{tcolorbox}[
            colback=blue!5,
            colframe=blue!5,
            arc=0pt,
            outer arc=0pt,
            before skip=0pt,
        ]
    },
    after doc body={\end{tcolorbox}},
}


\begin{document}

\begin{docCommand}
    {myCommand}
    {\marg{argument}}
    Some description of the command. Blah blah blah.
\end{docCommand}

\end{document}

output

5
  • Excellent, many thanks!
    – meide
    Commented Sep 23, 2020 at 14:51
  • Is it also possible to prevent page breaks between head & body? I tried adding before={\needspace{10\baselineskip}} to doc raster but that had no effect (with \usepackage{needspace} in preamble)
    – meide
    Commented Sep 25, 2020 at 4:40
  • 1
    @meide, it might be best to ask a new question with example code that reproduces your problem, then more people will see your question. Commented Sep 25, 2020 at 9:01
  • Alright, thanks :)
    – meide
    Commented Sep 25, 2020 at 9:01
  • 1
    For future reference, I did it by patching an internal tcolorbox environment in my preamble: \AtBeginEnvironment{tcb@manual@entry}{\needspace{10\baselineskip}}
    – meide
    Commented Sep 27, 2020 at 9:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .